[Embeddables] Fix passing the embeddable title down to the data table visualizations (#137844)

This commit is contained in:
Michael Dokolin 2022-08-08 10:04:17 +02:00 committed by GitHub
parent a6483d14a3
commit 4905d60951
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 12 deletions

View file

@ -10,6 +10,7 @@ import { createTableVisFn } from './table_vis_fn';
import { tableVisResponseHandler } from './utils';
import { TableVisConfig } from './types';
import { ExecutionContext } from '@kbn/expressions-plugin/common';
import { functionWrapper } from '@kbn/expressions-plugin/common/expression_functions/specs/tests/utils';
import { Datatable } from '@kbn/expressions-plugin/common/expression_types/specs';
@ -55,25 +56,29 @@ describe('interpreter/functions#table', () => {
],
buckets: [],
} as unknown as TableVisConfig;
const handlers = {
variables: {},
} as ExecutionContext;
beforeEach(() => {
jest.clearAllMocks();
});
it('returns an object with the correct structure', async () => {
const actual = await fn(context, visConfig, undefined);
const actual = await fn(context, visConfig, handlers);
expect(actual).toMatchSnapshot();
});
it('calls response handler with correct values', async () => {
await fn(context, visConfig, undefined);
await fn(context, visConfig, handlers);
expect(tableVisResponseHandler).toHaveBeenCalledTimes(1);
expect(tableVisResponseHandler).toHaveBeenCalledWith(context, visConfig);
});
it('logs correct datatable to inspector', async () => {
let loggedTable: Datatable;
const handlers = {
await fn(context, visConfig, {
...handlers,
inspectorAdapters: {
tables: {
logDatatable: (name: string, datatable: Datatable) => {
@ -82,8 +87,7 @@ describe('interpreter/functions#table', () => {
reset: () => {},
},
},
};
await fn(context, visConfig, handlers as any);
});
expect(loggedTable!).toMatchSnapshot();
});

View file

@ -166,13 +166,17 @@ export const createTableVisFn = (): TableExpressionFunctionDefinition => ({
const logTable = prepareLogTable(inspectorData, argsTable);
handlers.inspectorAdapters.tables.logDatatable('default', logTable);
}
return {
type: 'render',
as: 'table_vis',
value: {
visData: convertedData,
visType: VIS_TYPE_TABLE,
visConfig: args,
visConfig: {
...args,
title: (handlers.variables.embeddableTitle as string) ?? args.title,
},
},
};
},

View file

@ -115,7 +115,10 @@ export const datatableFn =
value: {
data: table,
untransposedData,
args,
args: {
...args,
title: (context.variables.embeddableTitle as string) ?? args.title,
},
},
};
};

View file

@ -582,11 +582,10 @@ export class Embeddable
errors={this.errors}
lensInspector={this.lensInspector}
searchContext={this.getMergedSearchContext()}
variables={
input.palette
? { theme: { palette: input.palette }, embeddableTitle: this.getTitle() }
: { embeddableTitle: this.getTitle() }
}
variables={{
embeddableTitle: this.getTitle(),
...(input.palette ? { theme: { palette: input.palette } } : {}),
}}
searchSessionId={this.externalSearchContext.searchSessionId}
handleEvent={this.handleEvent}
onData$={this.updateActiveData}