From 6a67ed98a99240d25e3eb023a74a68e50732f289 Mon Sep 17 00:00:00 2001 From: Marco Liberati Date: Tue, 14 Jul 2020 16:19:54 +0200 Subject: [PATCH] [7.x] [Visualize] Fix export table for table export links (#71249) (#71629) Co-authored-by: Elastic Machine --- .../public/__snapshots__/table_vis_fn.test.ts.snap | 1 + .../vis_type_table/public/agg_table/agg_table.js | 2 +- .../vis_type_table/public/table_vis_fn.test.ts | 1 + src/plugins/vis_type_table/public/vis_controller.ts | 12 +++++++++++- .../public/expressions/visualization_renderer.tsx | 1 + .../visualizations/public/legacy/build_pipeline.ts | 4 ++-- 6 files changed, 17 insertions(+), 4 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 a8fe25582717c..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 @@ -30,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/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.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, diff --git a/src/plugins/vis_type_table/public/vis_controller.ts b/src/plugins/vis_type_table/public/vis_controller.ts index a5086e0c9a2d8..d87812b9f5d69 100644 --- a/src/plugins/vis_type_table/public/vis_controller.ts +++ b/src/plugins/vis_type_table/public/vis_controller.ts @@ -78,8 +78,18 @@ 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: visParams.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);