From eb3cd0faae542755d2b2044928dc5180176b36ca Mon Sep 17 00:00:00 2001 From: dej611 Date: Tue, 29 Sep 2020 15:05:21 +0200 Subject: [PATCH 1/8] :bug: Forward title and description to the visualization container --- .../datatable_visualization/expression.tsx | 10 +++++++- .../datatable_visualization/visualization.tsx | 4 ++++ .../editor_frame/state_helpers.ts | 4 +++- .../metric_expression.tsx | 24 +++++++++++++++---- .../metric_visualization.tsx | 4 +++- .../lens/public/metric_visualization/types.ts | 4 +++- .../pie_visualization/register_expression.tsx | 8 +++++++ .../pie_visualization/render_function.tsx | 7 +++++- .../public/pie_visualization/to_expression.ts | 2 ++ .../lens/public/pie_visualization/types.ts | 4 ++++ .../lens/public/visualization_container.tsx | 3 +++ .../public/xy_visualization/to_expression.ts | 2 ++ .../lens/public/xy_visualization/types.ts | 4 ++++ .../public/xy_visualization/xy_expression.tsx | 15 +++++++++++- 14 files changed, 85 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/lens/public/datatable_visualization/expression.tsx b/x-pack/plugins/lens/public/datatable_visualization/expression.tsx index dac3b23b98e3b..d2d22e46a74f7 100644 --- a/x-pack/plugins/lens/public/datatable_visualization/expression.tsx +++ b/x-pack/plugins/lens/public/datatable_visualization/expression.tsx @@ -31,6 +31,7 @@ export interface DatatableColumns { interface Args { title: string; + description?: string; columns: DatatableColumns & { type: 'lens_datatable_columns' }; } @@ -70,6 +71,10 @@ export const datatable: ExpressionFunctionDefinition< defaultMessage: 'Title', }), }, + description: { + types: ['string'], + help: '', + }, columns: { types: ['lens_datatable_columns'], help: '', @@ -205,7 +210,10 @@ export function DatatableComponent(props: DatatableRenderProps) { } return ( - + type: 'function', function: 'lens_datatable', arguments: { + title: [state.title || ''], + description: [state.description || ''], columns: [ { type: 'expression', diff --git a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/state_helpers.ts b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/state_helpers.ts index 6deb9ffd37a06..aa90bf1d1a329 100644 --- a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/state_helpers.ts +++ b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/state_helpers.ts @@ -61,6 +61,8 @@ export async function persistedStateToExpression( state: { visualization: visualizationState, datasourceStates: persistedDatasourceStates }, visualizationType, references, + title, + description, } = doc; if (!visualizationType) return null; const visualization = visualizations[visualizationType!]; @@ -79,7 +81,7 @@ export async function persistedStateToExpression( return buildExpression({ visualization, - visualizationState, + visualizationState: { ...(visualizationState as object), title, description }, datasourceMap: datasources, datasourceStates, datasourceLayers, diff --git a/x-pack/plugins/lens/public/metric_visualization/metric_expression.tsx b/x-pack/plugins/lens/public/metric_visualization/metric_expression.tsx index 3484837f65b43..e0e3f476a4088 100644 --- a/x-pack/plugins/lens/public/metric_visualization/metric_expression.tsx +++ b/x-pack/plugins/lens/public/metric_visualization/metric_expression.tsx @@ -41,6 +41,14 @@ export const metricChart: ExpressionFunctionDefinition< types: ['string'], help: 'The chart title.', }, + description: { + types: ['string'], + help: '', + }, + metricTitle: { + types: ['string'], + help: 'The title of the metric shown.', + }, accessor: { types: ['string'], help: 'The column whose value is being displayed', @@ -96,12 +104,16 @@ export function MetricChart({ args, formatFactory, }: MetricChartProps & { formatFactory: FormatFactory }) { - const { title, accessor, mode } = args; + const { metricTitle, title, description, accessor, mode } = args; let value = '-'; const firstTable = Object.values(data.tables)[0]; if (!accessor) { return ( - + ); } @@ -117,14 +129,18 @@ export function MetricChart({ } return ( - +
{value}
{mode === 'full' && (
- {title} + {metricTitle}
)}
diff --git a/x-pack/plugins/lens/public/metric_visualization/metric_visualization.tsx b/x-pack/plugins/lens/public/metric_visualization/metric_visualization.tsx index 72c07bed1acb2..1e6a007ddb3c7 100644 --- a/x-pack/plugins/lens/public/metric_visualization/metric_visualization.tsx +++ b/x-pack/plugins/lens/public/metric_visualization/metric_visualization.tsx @@ -30,7 +30,9 @@ const toExpression = ( type: 'function', function: 'lens_metric_chart', arguments: { - title: [(operation && operation.label) || ''], + title: [state.title || ''], + description: [state.description || ''], + metricTitle: [(operation && operation.label) || ''], accessor: [state.accessor], mode: [mode], }, diff --git a/x-pack/plugins/lens/public/metric_visualization/types.ts b/x-pack/plugins/lens/public/metric_visualization/types.ts index 86a781716b345..91f4d457d8015 100644 --- a/x-pack/plugins/lens/public/metric_visualization/types.ts +++ b/x-pack/plugins/lens/public/metric_visualization/types.ts @@ -5,11 +5,13 @@ */ export interface State { + title?: string; + description?: string; layerId: string; accessor?: string; } export interface MetricConfig extends State { - title: string; + metricTitle: string; mode: 'reduced' | 'full'; } diff --git a/x-pack/plugins/lens/public/pie_visualization/register_expression.tsx b/x-pack/plugins/lens/public/pie_visualization/register_expression.tsx index 89d93ab79233f..d93145f29aa89 100644 --- a/x-pack/plugins/lens/public/pie_visualization/register_expression.tsx +++ b/x-pack/plugins/lens/public/pie_visualization/register_expression.tsx @@ -37,6 +37,14 @@ export const pie: ExpressionFunctionDefinition< defaultMessage: 'Pie renderer', }), args: { + title: { + types: ['string'], + help: 'The chart title.', + }, + description: { + types: ['string'], + help: '', + }, groups: { types: ['string'], multi: true, diff --git a/x-pack/plugins/lens/public/pie_visualization/render_function.tsx b/x-pack/plugins/lens/public/pie_visualization/render_function.tsx index d97ab146e000d..8de810f9aa5d3 100644 --- a/x-pack/plugins/lens/public/pie_visualization/render_function.tsx +++ b/x-pack/plugins/lens/public/pie_visualization/render_function.tsx @@ -228,7 +228,12 @@ export function PieComponent( ); } return ( - +