From 3b80c01d3e2a3bb10d4760a2c0c9df7dc1b67822 Mon Sep 17 00:00:00 2001 From: dej611 Date: Thu, 9 Jul 2020 15:54:52 +0200 Subject: [PATCH 1/5] :bug: Fix export name for the csv file to match table name --- .../vis_type_table/public/agg_table/agg_table.js | 2 +- src/plugins/vis_type_table/public/table_vis_fn.ts | 3 ++- src/plugins/vis_type_table/public/vis_controller.ts | 13 ++++++++++++- .../public/expressions/visualization_renderer.tsx | 1 + .../visualizations/public/legacy/build_pipeline.ts | 4 ++-- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/plugins/vis_type_table/public/agg_table/agg_table.js b/src/plugins/vis_type_table/public/agg_table/agg_table.js index bd7626a493338..1e98a06c2a6a9 100644 --- a/src/plugins/vis_type_table/public/agg_table/agg_table.js +++ b/src/plugins/vis_type_table/public/agg_table/agg_table.js @@ -116,7 +116,7 @@ export function KbnAggTable(config, RecursionHelper) { return; } - self.csv.filename = (exportTitle || table.title || 'table') + '.csv'; + self.csv.filename = (exportTitle || table.title || 'unsaved') + '.csv'; $scope.rows = table.rows; $scope.formattedColumns = []; diff --git a/src/plugins/vis_type_table/public/table_vis_fn.ts b/src/plugins/vis_type_table/public/table_vis_fn.ts index 9739a7a284e6c..f50697749268c 100644 --- a/src/plugins/vis_type_table/public/table_vis_fn.ts +++ b/src/plugins/vis_type_table/public/table_vis_fn.ts @@ -58,13 +58,14 @@ export const createTableVisFn = (): ExpressionFunctionDefinition< }, }, fn(input, args) { - const visConfig = args.visConfig && JSON.parse(args.visConfig); + const { title, ...visConfig } = args.visConfig && JSON.parse(args.visConfig); const convertedData = tableVisResponseHandler(input, visConfig.dimensions); return { type: 'render', as: 'visualization', value: { + title, visData: convertedData, visType: 'table', visConfig, diff --git a/src/plugins/vis_type_table/public/vis_controller.ts b/src/plugins/vis_type_table/public/vis_controller.ts index a5086e0c9a2d8..c235a80d6a2a6 100644 --- a/src/plugins/vis_type_table/public/vis_controller.ts +++ b/src/plugins/vis_type_table/public/vis_controller.ts @@ -78,8 +78,19 @@ export function getTableVisualizationControllerClass( if (!this.$scope) { return; } + + // How things get into this $scope? + // To inject variables into this $scope there's the following pipeline of stuff to check: + // - visualize_embeddable => that's what the editor creates to wrap this Angular component + // - build_pipeline => it serialize all the params into an Angular template compiled on the fly + // - table_vis_fn => unserialize the params and prepare them for the final React/Angular bridge + // - visualization_renderer => creates the wrapper component for this controller and passes the params + // + // In case some prop is missing check into the top of the chain if they are available and check + // the list above that it is passing through + this.$scope.vis = this.vis; - this.$scope.visState = { params: visParams }; + this.$scope.visState = { params: visParams, title: this.vis.title }; this.$scope.esResponse = esResponse; this.$scope.visParams = visParams; diff --git a/src/plugins/visualizations/public/expressions/visualization_renderer.tsx b/src/plugins/visualizations/public/expressions/visualization_renderer.tsx index 0fd81c753da24..1bca5b4f0d539 100644 --- a/src/plugins/visualizations/public/expressions/visualization_renderer.tsx +++ b/src/plugins/visualizations/public/expressions/visualization_renderer.tsx @@ -33,6 +33,7 @@ export const visualization = () => ({ const visType = config.visType || visConfig.type; const vis = new ExprVis({ + title: config.title, type: visType as string, params: visConfig as VisParams, }); diff --git a/src/plugins/visualizations/public/legacy/build_pipeline.ts b/src/plugins/visualizations/public/legacy/build_pipeline.ts index 62ff1f83426b9..2ef07bf18c91c 100644 --- a/src/plugins/visualizations/public/legacy/build_pipeline.ts +++ b/src/plugins/visualizations/public/legacy/build_pipeline.ts @@ -490,7 +490,7 @@ export const buildPipeline = async ( const { indexPattern, searchSource } = vis.data; const query = searchSource!.getField('query'); const filters = searchSource!.getField('filter'); - const { uiState } = vis; + const { uiState, title } = vis; // context let pipeline = `kibana | kibana_context `; @@ -519,7 +519,7 @@ export const buildPipeline = async ( timefilter: params.timefilter, }); if (buildPipelineVisFunction[vis.type.name]) { - pipeline += buildPipelineVisFunction[vis.type.name](vis.params, schemas, uiState); + pipeline += buildPipelineVisFunction[vis.type.name]({ title, ...vis.params }, schemas, uiState); } else if (vislibCharts.includes(vis.type.name)) { const visConfig = { ...vis.params }; visConfig.dimensions = await buildVislibDimensions(vis, params); From 8940633d4acb37b31e96693567c007cf95238806 Mon Sep 17 00:00:00 2001 From: dej611 Date: Thu, 9 Jul 2020 16:28:58 +0200 Subject: [PATCH 2/5] :camera_flash: Update snapshot for table_vis_fn test --- .../public/__snapshots__/table_vis_fn.test.ts.snap | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/vis_type_table/public/__snapshots__/table_vis_fn.test.ts.snap b/src/plugins/vis_type_table/public/__snapshots__/table_vis_fn.test.ts.snap index a8fe25582717c..5ac907f8c4ad8 100644 --- a/src/plugins/vis_type_table/public/__snapshots__/table_vis_fn.test.ts.snap +++ b/src/plugins/vis_type_table/public/__snapshots__/table_vis_fn.test.ts.snap @@ -8,6 +8,7 @@ Object { "params": Object { "listenOnChange": true, }, + "title": undefined, "visConfig": Object { "dimensions": Object { "buckets": Array [], From deea1c8dd87b67b4575bfafed3f7e8df8ba403e9 Mon Sep 17 00:00:00 2001 From: dej611 Date: Tue, 14 Jul 2020 10:52:02 +0200 Subject: [PATCH 3/5] :camera_flash: Add title to test and updated snapshot --- .../public/__snapshots__/table_vis_fn.test.ts.snap | 2 +- src/plugins/vis_type_table/public/table_vis_fn.test.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/plugins/vis_type_table/public/__snapshots__/table_vis_fn.test.ts.snap b/src/plugins/vis_type_table/public/__snapshots__/table_vis_fn.test.ts.snap index 5ac907f8c4ad8..dac5ea46f836f 100644 --- a/src/plugins/vis_type_table/public/__snapshots__/table_vis_fn.test.ts.snap +++ b/src/plugins/vis_type_table/public/__snapshots__/table_vis_fn.test.ts.snap @@ -8,7 +8,7 @@ Object { "params": Object { "listenOnChange": true, }, - "title": undefined, + "title": "My Chart title", "visConfig": Object { "dimensions": Object { "buckets": Array [], diff --git a/src/plugins/vis_type_table/public/table_vis_fn.test.ts b/src/plugins/vis_type_table/public/table_vis_fn.test.ts index 9accf8950d910..6cb3f3e0f3779 100644 --- a/src/plugins/vis_type_table/public/table_vis_fn.test.ts +++ b/src/plugins/vis_type_table/public/table_vis_fn.test.ts @@ -37,6 +37,7 @@ describe('interpreter/functions#table', () => { columns: [{ id: 'col-0-1', name: 'Count' }], }; const visConfig = { + title: 'My Chart title', perPage: 10, showPartialRows: false, showMetricsAtAllLevels: false, From 60b02e3af513afaba04c30c5054156ed7f196a93 Mon Sep 17 00:00:00 2001 From: dej611 Date: Tue, 14 Jul 2020 12:43:02 +0200 Subject: [PATCH 4/5] :bug: Pick the title from the params rather than the vis --- src/plugins/vis_type_table/public/vis_controller.ts | 3 +-- .../visualizations/public/components/visualization_chart.tsx | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/plugins/vis_type_table/public/vis_controller.ts b/src/plugins/vis_type_table/public/vis_controller.ts index c235a80d6a2a6..d87812b9f5d69 100644 --- a/src/plugins/vis_type_table/public/vis_controller.ts +++ b/src/plugins/vis_type_table/public/vis_controller.ts @@ -88,9 +88,8 @@ export function getTableVisualizationControllerClass( // // In case some prop is missing check into the top of the chain if they are available and check // the list above that it is passing through - this.$scope.vis = this.vis; - this.$scope.visState = { params: visParams, title: this.vis.title }; + this.$scope.visState = { params: visParams, title: visParams.title }; this.$scope.esResponse = esResponse; this.$scope.visParams = visParams; diff --git a/src/plugins/visualizations/public/components/visualization_chart.tsx b/src/plugins/visualizations/public/components/visualization_chart.tsx index fba0afa89ca53..12082403dcc60 100644 --- a/src/plugins/visualizations/public/components/visualization_chart.tsx +++ b/src/plugins/visualizations/public/components/visualization_chart.tsx @@ -62,8 +62,8 @@ class VisualizationChart extends React.Component { // has been initialized throw new Error('Visualization implementation was not initialized on first render.'); } - - return this.visualization.render(visData, visParams); + // need to pass the title here again to refresh in case of save in-place or renaming + return this.visualization.render(visData, { ...visParams, title: vis.title }); }) ); From 8f6047e56d19e056c7f552572968b424418d2d40 Mon Sep 17 00:00:00 2001 From: dej611 Date: Tue, 14 Jul 2020 12:47:26 +0200 Subject: [PATCH 5/5] :fire: Remove unused props --- .../public/__snapshots__/table_vis_fn.test.ts.snap | 2 +- src/plugins/vis_type_table/public/table_vis_fn.ts | 3 +-- .../visualizations/public/components/visualization_chart.tsx | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/plugins/vis_type_table/public/__snapshots__/table_vis_fn.test.ts.snap b/src/plugins/vis_type_table/public/__snapshots__/table_vis_fn.test.ts.snap index dac5ea46f836f..dc6571de969f0 100644 --- a/src/plugins/vis_type_table/public/__snapshots__/table_vis_fn.test.ts.snap +++ b/src/plugins/vis_type_table/public/__snapshots__/table_vis_fn.test.ts.snap @@ -8,7 +8,6 @@ Object { "params": Object { "listenOnChange": true, }, - "title": "My Chart title", "visConfig": Object { "dimensions": Object { "buckets": Array [], @@ -31,6 +30,7 @@ Object { "columnIndex": null, "direction": null, }, + "title": "My Chart title", "totalFunc": "sum", }, "visData": Object { diff --git a/src/plugins/vis_type_table/public/table_vis_fn.ts b/src/plugins/vis_type_table/public/table_vis_fn.ts index f50697749268c..9739a7a284e6c 100644 --- a/src/plugins/vis_type_table/public/table_vis_fn.ts +++ b/src/plugins/vis_type_table/public/table_vis_fn.ts @@ -58,14 +58,13 @@ export const createTableVisFn = (): ExpressionFunctionDefinition< }, }, fn(input, args) { - const { title, ...visConfig } = args.visConfig && JSON.parse(args.visConfig); + const visConfig = args.visConfig && JSON.parse(args.visConfig); const convertedData = tableVisResponseHandler(input, visConfig.dimensions); return { type: 'render', as: 'visualization', value: { - title, visData: convertedData, visType: 'table', visConfig, diff --git a/src/plugins/visualizations/public/components/visualization_chart.tsx b/src/plugins/visualizations/public/components/visualization_chart.tsx index 12082403dcc60..fba0afa89ca53 100644 --- a/src/plugins/visualizations/public/components/visualization_chart.tsx +++ b/src/plugins/visualizations/public/components/visualization_chart.tsx @@ -62,8 +62,8 @@ class VisualizationChart extends React.Component { // has been initialized throw new Error('Visualization implementation was not initialized on first render.'); } - // need to pass the title here again to refresh in case of save in-place or renaming - return this.visualization.render(visData, { ...visParams, title: vis.title }); + + return this.visualization.render(visData, visParams); }) );