mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[Graph] Fix drilldown url templates for sample data (#141079)
* [Graph] Fix drilldown url templates for sample data * [Graph] Add tests * Revert "[Graph] Add tests" This reverts commit08d5c7d864
. * Revert "[Graph] Fix drilldown url templates for sample data" This reverts commit0fc575ef09
. * [Graph] Fix issue with opening sample graph ws in any Kibana spaces * [Graph] Add tests Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
aae100f709
commit
797b351b1a
3 changed files with 39 additions and 4 deletions
|
@ -40,7 +40,9 @@ export const DrillDowns = ({ urlTemplates, openUrlTemplate }: DrillDownsProps) =
|
|||
return (
|
||||
<li className="list-group-item">
|
||||
{urlTemplate.icon && (
|
||||
<span className="kuiIcon gphNoUserSelect">{urlTemplate.icon?.code}</span>
|
||||
<>
|
||||
<span className="kuiIcon gphNoUserSelect">{urlTemplate.icon?.code}</span>{' '}
|
||||
</>
|
||||
)}
|
||||
<a aria-hidden="true" onClick={onOpenUrlTemplate}>
|
||||
{urlTemplate.description}
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { urlTemplatesReducer, saveTemplate } from './url_templates';
|
||||
import { urlTemplatesReducer, saveTemplate, loadTemplates } from './url_templates';
|
||||
import { requestDatasource } from './datasource';
|
||||
import { outlinkEncoders } from '../helpers/outlink_encoders';
|
||||
import { UrlTemplate } from '../types';
|
||||
|
||||
describe('url_templates', () => {
|
||||
const addBasePath = (url: string) => url;
|
||||
const addBasePath = (url: string) => `/test/s/custom/${url}`;
|
||||
|
||||
describe('reducer', () => {
|
||||
it('should create a default template as soon as datasource is known', () => {
|
||||
|
@ -74,5 +74,26 @@ describe('url_templates', () => {
|
|||
expect(templates[0].description).toBe('def');
|
||||
expect(templates[0].isDefault).toBe(false);
|
||||
});
|
||||
|
||||
it('should patch default urls with a space-aware prefix', () => {
|
||||
const templates = urlTemplatesReducer(addBasePath)(
|
||||
[],
|
||||
loadTemplates([
|
||||
{
|
||||
url: '/app/discover?and-the-rest',
|
||||
isDefault: true,
|
||||
} as UrlTemplate,
|
||||
{
|
||||
url: 'https://example.com?and-the-rest',
|
||||
isDefault: true,
|
||||
} as UrlTemplate,
|
||||
])
|
||||
);
|
||||
expect(templates.length).toBe(2);
|
||||
expect(templates[0].url).toBe('/test/s/custom//app/discover?and-the-rest');
|
||||
expect(templates[0].isDefault).toBe(true);
|
||||
expect(templates[1].url).toBe('https://example.com?and-the-rest');
|
||||
expect(templates[1].isDefault).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -82,7 +82,19 @@ export const urlTemplatesReducer = (addBasePath: (url: string) => string) =>
|
|||
const customTemplates = templates.filter((template) => !template.isDefault);
|
||||
return [...customTemplates, generateDefaultTemplate(datasource, addBasePath)];
|
||||
})
|
||||
.case(loadTemplates, (_currentTemplates, newTemplates) => newTemplates)
|
||||
.case(loadTemplates, (_currentTemplates, newTemplates) => {
|
||||
return newTemplates.map((template) =>
|
||||
template.isDefault && template.url?.startsWith('/app/discover') // as in saved objects of sample data sets
|
||||
? {
|
||||
...template,
|
||||
url: addBasePath(template.url).replace(
|
||||
encodeURIComponent(urlTemplatePlaceholder),
|
||||
urlTemplatePlaceholder
|
||||
),
|
||||
}
|
||||
: template
|
||||
);
|
||||
})
|
||||
.case(saveTemplate, (templates, { index: indexToUpdate, template: updatedTemplate }) => {
|
||||
// set default flag to false as soon as template is overwritten.
|
||||
const newTemplate = { ...updatedTemplate, isDefault: false };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue