updating markdownvis interpreter func arguments (#34534)
This commit is contained in:
parent
bd5e81bafc
commit
7693f18f50
|
@ -21,7 +21,7 @@ import { functionsRegistry } from 'plugins/interpreter/registries';
|
|||
import { i18n } from '@kbn/i18n';
|
||||
|
||||
export const kibanaMarkdown = () => ({
|
||||
name: 'kibana_markdown',
|
||||
name: 'markdownVis',
|
||||
type: 'render',
|
||||
context: {
|
||||
types: [],
|
||||
|
@ -30,20 +30,28 @@ export const kibanaMarkdown = () => ({
|
|||
defaultMessage: 'Markdown visualization'
|
||||
}),
|
||||
args: {
|
||||
visConfig: {
|
||||
types: ['string'],
|
||||
default: '"{}"',
|
||||
markdown: {
|
||||
type: ['string'],
|
||||
aliases: ['_'],
|
||||
required: true,
|
||||
},
|
||||
fontSize: {
|
||||
types: ['number'],
|
||||
default: 12,
|
||||
},
|
||||
openLinksInNewTab: {
|
||||
types: ['boolean'],
|
||||
default: false,
|
||||
}
|
||||
},
|
||||
fn(context, args) {
|
||||
const params = JSON.parse(args.visConfig);
|
||||
return {
|
||||
type: 'render',
|
||||
as: 'visualization',
|
||||
value: {
|
||||
visType: 'markdown',
|
||||
visConfig: {
|
||||
...params,
|
||||
...args,
|
||||
},
|
||||
}
|
||||
};
|
||||
|
|
|
@ -22,14 +22,14 @@ import { kibanaMarkdown } from './markdown_fn';
|
|||
|
||||
describe('interpreter/functions#markdown', () => {
|
||||
const fn = functionWrapper(kibanaMarkdown);
|
||||
const visConfig = {
|
||||
const args = {
|
||||
fontSize: 12,
|
||||
openLinksInNewTab: true,
|
||||
markdown: '## hello _markdown_',
|
||||
};
|
||||
|
||||
it('returns an object with the correct structure', () => {
|
||||
const actual = fn(undefined, { visConfig: JSON.stringify(visConfig) });
|
||||
const actual = fn(undefined, args);
|
||||
expect(actual).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
exports[`visualize loader pipeline helpers: build pipeline buildPipelineVisFunction handles input_control_vis function 1`] = `"input_control_vis visConfig='{\\"some\\":\\"nested\\",\\"data\\":{\\"here\\":true}}' "`;
|
||||
|
||||
exports[`visualize loader pipeline helpers: build pipeline buildPipelineVisFunction handles markdown function 1`] = `"kibana_markdown visConfig='{\\"markdown\\":\\"## hello _markdown_\\",\\"foo\\":\\"bar\\"}' "`;
|
||||
exports[`visualize loader pipeline helpers: build pipeline buildPipelineVisFunction handles markdown function 1`] = `"markdownvis '## hello _markdown_' fontSize=12 openLinksInNewTab=true "`;
|
||||
|
||||
exports[`visualize loader pipeline helpers: build pipeline buildPipelineVisFunction handles metric function with buckets 1`] = `"kibana_metric visConfig='{\\"metric\\":{},\\"dimensions\\":{\\"metrics\\":[0,1],\\"bucket\\":2}}' "`;
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ describe('visualize loader pipeline helpers: build pipeline', () => {
|
|||
});
|
||||
|
||||
it('handles markdown function', () => {
|
||||
const params = { markdown: '## hello _markdown_', foo: 'bar' };
|
||||
const params = { markdown: '## hello _markdown_', fontSize: 12, openLinksInNewTab: true, foo: 'bar' };
|
||||
const actual = buildPipelineVisFunction.markdown({ params });
|
||||
expect(actual).toMatchSnapshot();
|
||||
});
|
||||
|
|
|
@ -198,7 +198,11 @@ export const prepareJson = (variable: string, data: object): string => {
|
|||
};
|
||||
|
||||
export const prepareString = (variable: string, data: string): string => {
|
||||
return `${variable}='${data.replace(/\\/g, `\\\\`).replace(/'/g, `\\'`)}' `;
|
||||
return `${variable}='${escapeString(data)}' `;
|
||||
};
|
||||
|
||||
export const escapeString = (data: string): string => {
|
||||
return data.replace(/\\/g, `\\\\`).replace(/'/g, `\\'`);
|
||||
};
|
||||
|
||||
export const buildPipelineVisFunction: BuildPipelineVisFunction = {
|
||||
|
@ -220,8 +224,16 @@ export const buildPipelineVisFunction: BuildPipelineVisFunction = {
|
|||
return `timelion_vis ${expression}${interval}`;
|
||||
},
|
||||
markdown: visState => {
|
||||
const visConfig = prepareJson('visConfig', visState.params);
|
||||
return `kibana_markdown ${visConfig}`;
|
||||
const { markdown, fontSize, openLinksInNewTab } = visState.params;
|
||||
const escapedMarkdown = escapeString(markdown);
|
||||
let expr = `markdownvis '${escapedMarkdown}' `;
|
||||
if (fontSize) {
|
||||
expr += ` fontSize=${fontSize} `;
|
||||
}
|
||||
if (openLinksInNewTab) {
|
||||
expr += `openLinksInNewTab=${openLinksInNewTab} `;
|
||||
}
|
||||
return expr;
|
||||
},
|
||||
table: (visState, schemas) => {
|
||||
const visConfig = {
|
||||
|
|
Loading…
Reference in a new issue