Skip to content

Commit

Permalink
Update plugins using expressions according to the updated public API
Browse files Browse the repository at this point in the history
  • Loading branch information
dokmic committed Oct 1, 2021
1 parent b70d5fc commit a54736d
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ export function ActionsExpressionsExample({ expressions, actions }: Props) {
};

const handleEvents = (event: any) => {
if (event.id !== 'NAVIGATE') return;
if (event.name !== 'NAVIGATE') return;
// enrich event context with some extra data
event.baseUrl = 'http://www.google.com';

actions.executeTriggerActions(NAVIGATE_TRIGGER_ID, event.value);
actions.executeTriggerActions(NAVIGATE_TRIGGER_ID, event.data);
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function ActionsExpressionsExample2({ expressions, actions }: Props) {
};

const handleEvents = (event: any) => {
updateVariables({ color: event.value.href === 'http://www.google.com' ? 'red' : 'blue' });
updateVariables({ color: event.data.href === 'http://www.google.com' ? 'red' : 'blue' });
};

return (
Expand Down
4 changes: 2 additions & 2 deletions examples/expressions_explorer/public/renderers/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export const buttonRenderer: ExpressionRenderDefinition<any> = {
render(domNode, config, handlers) {
const buttonClick = () => {
handlers.event({
id: 'NAVIGATE',
value: {
name: 'NAVIGATE',
data: {
href: config.href,
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { functionWrapper } from '../../../../expressions/common/expression_funct
import { ExpressionValueVisDimension } from '../../../../visualizations/public';
import { Datatable } from '../../../../expressions/common/expression_types/specs';

type Arguments = Parameters<ReturnType<typeof tagcloudFunction>['fn']>[1];

describe('interpreter/functions#tagcloud', () => {
const fn = functionWrapper(tagcloudFunction());
const column1 = 'Count';
Expand All @@ -26,7 +28,7 @@ describe('interpreter/functions#tagcloud', () => {
{ [column1]: 0, [column2]: 'US' },
{ [column1]: 10, [column2]: 'UK' },
],
};
} as unknown as Datatable;
const visConfig = {
scale: 'linear',
orientation: 'single',
Expand Down Expand Up @@ -73,12 +75,12 @@ describe('interpreter/functions#tagcloud', () => {
};

it('returns an object with the correct structure for number accessors', () => {
const actual = fn(context, { ...visConfig, ...numberAccessors }, undefined);
const actual = fn(context, { ...visConfig, ...numberAccessors } as Arguments, undefined);
expect(actual).toMatchSnapshot();
});

it('returns an object with the correct structure for string accessors', () => {
const actual = fn(context, { ...visConfig, ...stringAccessors }, undefined);
const actual = fn(context, { ...visConfig, ...stringAccessors } as Arguments, undefined);
expect(actual).toMatchSnapshot();
});

Expand All @@ -93,7 +95,7 @@ describe('interpreter/functions#tagcloud', () => {
},
},
};
await fn(context, { ...visConfig, ...numberAccessors }, handlers as any);
await fn(context, { ...visConfig, ...numberAccessors } as Arguments, handlers as any);

expect(loggedTable!).toMatchSnapshot();
});
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/vis_type_markdown/public/markdown_fn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@

import { functionWrapper } from '../../expressions/common/expression_functions/specs/tests/utils';
import { createMarkdownVisFn } from './markdown_fn';
import { Arguments } from './types';

describe('interpreter/functions#markdown', () => {
const fn = functionWrapper(createMarkdownVisFn());
const args = {
font: { spec: { fontSize: 12 } },
openLinksInNewTab: true,
markdown: '## hello _markdown_',
};
} as unknown as Arguments;

it('returns an object with the correct structure', async () => {
const actual = await fn(null, args, undefined);
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/vis_types/metric/public/metric_vis_fn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import { createMetricVisFn } from './metric_vis_fn';
import { functionWrapper } from '../../../expressions/common/expression_functions/specs/tests/utils';
import { Datatable } from '../../../expressions/common/expression_types/specs';

type Arguments = Parameters<ReturnType<typeof createMetricVisFn>['fn']>[1];

describe('interpreter/functions#metric', () => {
const fn = functionWrapper(createMetricVisFn());
const context = {
type: 'datatable',
rows: [{ 'col-0-1': 0 }],
columns: [{ id: 'col-0-1', name: 'Count' }],
};
} as unknown as Datatable;
const args = {
percentageMode: false,
useRanges: false,
Expand Down Expand Up @@ -50,7 +52,7 @@ describe('interpreter/functions#metric', () => {
aggType: 'count',
},
],
};
} as unknown as Arguments;

it('returns an object with the correct structure', () => {
const actual = fn(context, args, undefined);
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/vis_types/pie/public/pie_fn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { functionWrapper } from '../../../expressions/common/expression_functions/specs/tests/utils';
import { createPieVisFn } from './pie_fn';
import { PieVisConfig } from './types';
import { Datatable } from '../../../expressions/common/expression_types/specs';

describe('interpreter/functions#pie', () => {
Expand All @@ -16,7 +17,7 @@ describe('interpreter/functions#pie', () => {
type: 'datatable',
rows: [{ 'col-0-1': 0 }],
columns: [{ id: 'col-0-1', name: 'Count' }],
};
} as unknown as Datatable;
const visConfig = {
addTooltip: true,
addLegend: true,
Expand All @@ -43,7 +44,7 @@ describe('interpreter/functions#pie', () => {
params: {},
aggType: 'count',
},
};
} as unknown as PieVisConfig;

beforeEach(() => {
jest.clearAllMocks();
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/vis_types/table/public/table_vis_fn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { createTableVisFn } from './table_vis_fn';
import { tableVisResponseHandler } from './utils';
import { TableVisConfig } from './types';

import { functionWrapper } from '../../../expressions/common/expression_functions/specs/tests/utils';
import { Datatable } from '../../../expressions/common/expression_types/specs';
Expand All @@ -24,7 +25,7 @@ describe('interpreter/functions#table', () => {
type: 'datatable',
rows: [{ 'col-0-1': 0 }],
columns: [{ id: 'col-0-1', name: 'Count' }],
};
} as unknown as Datatable;
const visConfig = {
title: 'My Chart title',
perPage: 10,
Expand Down Expand Up @@ -52,7 +53,7 @@ describe('interpreter/functions#table', () => {
},
],
buckets: [],
};
} as unknown as TableVisConfig;

beforeEach(() => {
jest.clearAllMocks();
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/vis_types/vislib/public/pie_fn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/

import type { Datatable } from 'src/plugins/expressions';
import { functionWrapper } from '../../../expressions/common/expression_functions/specs/tests/utils';
import { createPieVisFn } from './pie_fn';
// @ts-ignore
Expand Down Expand Up @@ -34,7 +35,7 @@ describe('interpreter/functions#pie', () => {
type: 'datatable',
rows: [{ 'col-0-1': 0 }],
columns: [{ id: 'col-0-1', name: 'Count' }],
};
} as unknown as Datatable;
const visConfig = {
type: 'pie',
addTooltip: true,
Expand Down
11 changes: 8 additions & 3 deletions x-pack/plugins/canvas/canvas_plugin_src/functions/common/as.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
* 2.0.
*/

import { Datatable, ExpressionFunctionDefinition, getType } from '../../../types';
import {
Datatable,
DatatableColumnType,
ExpressionFunctionDefinition,
getType,
} from '../../../types';
import { getFunctionHelp } from '../../../i18n';

interface Arguments {
Expand All @@ -30,14 +35,14 @@ export function asFn(): ExpressionFunctionDefinition<'as', Input, Arguments, Dat
default: 'value',
},
},
fn: (input, args) => {
fn: (input, args): Datatable => {
return {
type: 'datatable',
columns: [
{
id: args.name,
name: args.name,
meta: { type: getType(input) },
meta: { type: getType(input) as DatatableColumnType },
},
],
rows: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ ${examplesBlock}
*Returns:* ${output ? wrapInBackTicks(output) : 'Depends on your input and arguments'}\n\n`;
};

const getArgsTable = (args: { [key: string]: ExpressionFunctionParameter }) => {
const getArgsTable = (args: { [key: string]: ExpressionFunctionParameter<any> }) => {
if (!args || Object.keys(args).length === 0) {
return 'None';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@

import { Datatable, DatatableColumn } from 'src/plugins/expressions/public';
import { functionWrapper } from 'src/plugins/expressions/common/expression_functions/specs/tests/utils';
import { FormatColumnArgs, formatColumn } from './index';
import { formatColumn } from './index';

describe('format_column', () => {
const fn: (input: Datatable, args: FormatColumnArgs) => Promise<Datatable> =
functionWrapper(formatColumn);
const fn = functionWrapper(formatColumn);

let datatable: Datatable;

Expand Down

0 comments on commit a54736d

Please sign in to comment.