diff --git a/src/legacy/core_plugins/interpreter/public/functions/visualization.js b/src/legacy/core_plugins/interpreter/public/functions/visualization.js index 14831f7ff6e9b..649abd70de5f6 100644 --- a/src/legacy/core_plugins/interpreter/public/functions/visualization.js +++ b/src/legacy/core_plugins/interpreter/public/functions/visualization.js @@ -116,17 +116,21 @@ export const visualization = () => ({ if (context.columns) { // assign schemas to aggConfigs context.columns.forEach(column => { - column.aggConfig.aggConfigs.schemas = visType.schemas.all; + if (column.aggConfig) { + column.aggConfig.aggConfigs.schemas = visType.schemas.all; + } }); Object.keys(schemas).forEach(key => { schemas[key].forEach(i => { - context.columns[i].aggConfig.schema = key; + if (context.columns[i] && context.columns[i].aggConfig) { + context.columns[i].aggConfig.schema = key; + } }); }); } - context = await responseHandler(context); + context = await responseHandler(context, visConfigParams.dimensions); } return { diff --git a/src/legacy/ui/public/visualize/loader/pipeline_helpers/__snapshots__/build_pipeline.test.js.snap b/src/legacy/ui/public/visualize/loader/pipeline_helpers/__snapshots__/build_pipeline.test.js.snap index ee4f3354cc9ed..f06a7959347f3 100644 --- a/src/legacy/ui/public/visualize/loader/pipeline_helpers/__snapshots__/build_pipeline.test.js.snap +++ b/src/legacy/ui/public/visualize/loader/pipeline_helpers/__snapshots__/build_pipeline.test.js.snap @@ -1,5 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`visualize loader pipeline helpers: build pipeline buildPipeline calls toExpression on vis_type if it exists 1`] = `"kibana | kibana_context | testing custom expressions"`; + 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`] = `"markdownvis '## hello _markdown_' fontSize=12 openLinksInNewTab=true "`; diff --git a/src/legacy/ui/public/visualize/loader/pipeline_helpers/build_pipeline.test.js b/src/legacy/ui/public/visualize/loader/pipeline_helpers/build_pipeline.test.js index a38b567b2f589..e02286c346e39 100644 --- a/src/legacy/ui/public/visualize/loader/pipeline_helpers/build_pipeline.test.js +++ b/src/legacy/ui/public/visualize/loader/pipeline_helpers/build_pipeline.test.js @@ -17,7 +17,7 @@ * under the License. */ -import { prepareJson, prepareString, buildPipelineVisFunction } from './build_pipeline'; +import { prepareJson, prepareString, buildPipelineVisFunction, buildPipeline } from './build_pipeline'; jest.mock('ui/agg_types/buckets/date_histogram', () => ({})); @@ -224,4 +224,25 @@ describe('visualize loader pipeline helpers: build pipeline', () => { expect(actual).toMatchSnapshot(); }); }); + + describe('buildPipeline', () => { + it('calls toExpression on vis_type if it exists', async () => { + const vis = { + getCurrentState: () => {}, + getUiState: () => null, + isHierarchical: () => false, + aggs: { + getResponseAggs: () => [], + }, + type: { + toExpression: () => 'testing custom expressions', + } + }; + const searchSource = { + getField: () => null, + }; + const expression = await buildPipeline(vis, { searchSource }); + expect(expression).toMatchSnapshot(); + }); + }); }); diff --git a/src/legacy/ui/public/visualize/loader/pipeline_helpers/build_pipeline.ts b/src/legacy/ui/public/visualize/loader/pipeline_helpers/build_pipeline.ts index 1205632641ab6..8e8c9ef737be0 100644 --- a/src/legacy/ui/public/visualize/loader/pipeline_helpers/build_pipeline.ts +++ b/src/legacy/ui/public/visualize/loader/pipeline_helpers/build_pipeline.ts @@ -464,9 +464,13 @@ export const buildPipeline = async ( visConfig.dimensions = await buildVislibDimensions(vis, params); pipeline += `vislib ${prepareJson('visConfig', visState.params)}`; + } else if (vis.type.toExpression) { + pipeline += await vis.type.toExpression(vis, params); } else { + const visConfig = visState.params; + visConfig.dimensions = schemas; pipeline += `visualization type='${vis.type.name}' - ${prepareJson('visConfig', visState.params)} + ${prepareJson('visConfig', visConfig)} metricsAtAllLevels=${vis.isHierarchical()} partialRows=${vis.type.requiresPartialRows || vis.params.showPartialRows || false} `; if (indexPattern) {