diff --git a/x-pack/plugins/lens/public/app_plugin/show_underlying_data.test.ts b/x-pack/plugins/lens/public/app_plugin/show_underlying_data.test.ts index f1941005cb31b..c6f97c9670031 100644 --- a/x-pack/plugins/lens/public/app_plugin/show_underlying_data.test.ts +++ b/x-pack/plugins/lens/public/app_plugin/show_underlying_data.test.ts @@ -75,6 +75,7 @@ describe('getLayerMetaInfo', () => { isStaticValue: false, sortingHint: undefined, hasTimeShift: true, + hasReducedTimeRange: true, })), getTableSpec: jest.fn(), getVisualDefaults: jest.fn(), diff --git a/x-pack/plugins/lens/public/datasources/form_based/form_based.test.ts b/x-pack/plugins/lens/public/datasources/form_based/form_based.test.ts index 26a3d2233d6dd..e8ac68460beb9 100644 --- a/x-pack/plugins/lens/public/datasources/form_based/form_based.test.ts +++ b/x-pack/plugins/lens/public/datasources/form_based/form_based.test.ts @@ -1868,6 +1868,7 @@ describe('IndexPattern Data Source', () => { isBucketed: true, isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, } as OperationDescriptor); }); diff --git a/x-pack/plugins/lens/public/datasources/form_based/form_based.tsx b/x-pack/plugins/lens/public/datasources/form_based/form_based.tsx index 92ae8c6a6f873..d41218f785d9b 100644 --- a/x-pack/plugins/lens/public/datasources/form_based/form_based.tsx +++ b/x-pack/plugins/lens/public/datasources/form_based/form_based.tsx @@ -105,7 +105,7 @@ export function columnToOperation( uniqueLabel?: string, dataView?: IndexPattern ): OperationDescriptor { - const { dataType, label, isBucketed, scale, operationType, timeShift } = column; + const { dataType, label, isBucketed, scale, operationType, timeShift, reducedTimeRange } = column; const fieldTypes = 'sourceField' in column ? dataView?.getFieldByName(column.sourceField)?.esTypes : undefined; return { @@ -119,6 +119,7 @@ export function columnToOperation( ? 'version' : undefined, hasTimeShift: Boolean(timeShift), + hasReducedTimeRange: Boolean(reducedTimeRange), interval: isColumnOfType('date_histogram', column) ? column.params.interval : undefined, diff --git a/x-pack/plugins/lens/public/datasources/form_based/form_based_suggestions.test.tsx b/x-pack/plugins/lens/public/datasources/form_based/form_based_suggestions.test.tsx index d7a544a723e04..2489659f0da55 100644 --- a/x-pack/plugins/lens/public/datasources/form_based/form_based_suggestions.test.tsx +++ b/x-pack/plugins/lens/public/datasources/form_based/form_based_suggestions.test.tsx @@ -1283,6 +1283,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: undefined, isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, }, }, { @@ -1294,6 +1295,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: 'ratio', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, }, }, ], @@ -1373,6 +1375,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: undefined, isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, }, }, { @@ -1384,6 +1387,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: 'ratio', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, }, }, ], @@ -2198,6 +2202,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: undefined, isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, }, }, ], @@ -2222,6 +2227,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: undefined, isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, }, }, ], @@ -2272,6 +2278,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: 'interval', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, interval: 'auto', }, }, @@ -2284,6 +2291,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: 'ratio', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, interval: undefined, }, }, @@ -2349,6 +2357,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: 'ordinal', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, interval: undefined, }, }, @@ -2361,6 +2370,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: 'interval', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, interval: 'auto', }, }, @@ -2373,6 +2383,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: 'ratio', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, interval: undefined, }, }, @@ -2459,6 +2470,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: 'ordinal', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, interval: undefined, }, }, @@ -2471,6 +2483,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: 'interval', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, interval: 'auto', }, }, @@ -2483,6 +2496,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: 'ratio', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, interval: undefined, }, }, @@ -2592,6 +2606,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: 'ordinal', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, interval: undefined, }, }, @@ -2604,6 +2619,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: 'interval', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, interval: 'auto', }, }, @@ -2616,6 +2632,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: undefined, isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, interval: undefined, }, }, @@ -3123,6 +3140,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: undefined, isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, }, }, { @@ -3134,6 +3152,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: undefined, isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, }, }, ], @@ -3201,6 +3220,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: 'interval', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, interval: 'auto', }, }, @@ -3213,6 +3233,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: undefined, isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, interval: undefined, }, }, @@ -3225,6 +3246,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: undefined, isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, interval: undefined, }, }, @@ -3291,6 +3313,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: undefined, isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, interval: 'auto', }, }, @@ -3303,6 +3326,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: undefined, isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, interval: undefined, }, }, @@ -3315,6 +3339,7 @@ describe('IndexPattern Data Source suggestions', () => { scale: undefined, isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, interval: undefined, }, }, diff --git a/x-pack/plugins/lens/public/datasources/text_based/text_based_languages.test.ts b/x-pack/plugins/lens/public/datasources/text_based/text_based_languages.test.ts index 968a1ac1e496c..cef1bfa96b8a5 100644 --- a/x-pack/plugins/lens/public/datasources/text_based/text_based_languages.test.ts +++ b/x-pack/plugins/lens/public/datasources/text_based/text_based_languages.test.ts @@ -728,6 +728,7 @@ describe('IndexPattern Data Source', () => { dataType: 'number', isBucketed: false, hasTimeShift: false, + hasReducedTimeRange: false, }); }); diff --git a/x-pack/plugins/lens/public/datasources/text_based/text_based_languages.tsx b/x-pack/plugins/lens/public/datasources/text_based/text_based_languages.tsx index 8aa5648ab2d1b..afe6368477cc9 100644 --- a/x-pack/plugins/lens/public/datasources/text_based/text_based_languages.tsx +++ b/x-pack/plugins/lens/public/datasources/text_based/text_based_languages.tsx @@ -587,6 +587,7 @@ export function getTextBasedDatasource({ label: columnLabelMap[columnId] ?? column?.fieldName, isBucketed: Boolean(column?.meta?.type !== 'number'), hasTimeShift: false, + hasReducedTimeRange: false, }; } return null; diff --git a/x-pack/plugins/lens/public/types.ts b/x-pack/plugins/lens/public/types.ts index 7b29b0a14f9ab..f0f52f546468c 100644 --- a/x-pack/plugins/lens/public/types.ts +++ b/x-pack/plugins/lens/public/types.ts @@ -693,6 +693,7 @@ export interface OperationMetadata { */ export interface OperationDescriptor extends Operation { hasTimeShift: boolean; + hasReducedTimeRange: boolean; } export interface VisualizationConfigProps { diff --git a/x-pack/plugins/lens/public/visualizations/datatable/visualization.test.tsx b/x-pack/plugins/lens/public/visualizations/datatable/visualization.test.tsx index cc4b108a23bda..e6683aee13499 100644 --- a/x-pack/plugins/lens/public/visualizations/datatable/visualization.test.tsx +++ b/x-pack/plugins/lens/public/visualizations/datatable/visualization.test.tsx @@ -526,6 +526,7 @@ describe('Datatable Visualization', () => { label: 'label', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, }); const expression = datatableVisualization.toExpression( @@ -577,6 +578,7 @@ describe('Datatable Visualization', () => { label: 'label', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, }); const expression = datatableVisualization.toExpression( @@ -712,6 +714,7 @@ describe('Datatable Visualization', () => { label: 'label', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, }); const error = datatableVisualization.getErrorMessages({ @@ -737,6 +740,7 @@ describe('Datatable Visualization', () => { label: 'label', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, }); const error = datatableVisualization.getErrorMessages({ diff --git a/x-pack/plugins/lens/public/visualizations/legacy_metric/visualization.test.ts b/x-pack/plugins/lens/public/visualizations/legacy_metric/visualization.test.ts index 3fa5ea3dd0393..517e331634880 100644 --- a/x-pack/plugins/lens/public/visualizations/legacy_metric/visualization.test.ts +++ b/x-pack/plugins/lens/public/visualizations/legacy_metric/visualization.test.ts @@ -271,6 +271,7 @@ describe('metric_visualization', () => { label: 'shazm', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, }; }, }; diff --git a/x-pack/plugins/lens/public/visualizations/metric/dimension_editor.test.tsx b/x-pack/plugins/lens/public/visualizations/metric/dimension_editor.test.tsx index 62275dde1fad3..9826e60a83bc9 100644 --- a/x-pack/plugins/lens/public/visualizations/metric/dimension_editor.test.tsx +++ b/x-pack/plugins/lens/public/visualizations/metric/dimension_editor.test.tsx @@ -8,7 +8,7 @@ /* eslint-disable max-classes-per-file */ import React, { FormEvent } from 'react'; -import { VisualizationDimensionEditorProps } from '../../types'; +import { OperationDescriptor, VisualizationDimensionEditorProps } from '../../types'; import { CustomPaletteParams, PaletteOutput, PaletteRegistry } from '@kbn/coloring'; import { MetricVisualizationState } from './visualization'; @@ -91,6 +91,9 @@ describe('dimension editor', () => { state: fullState, datasource: { hasDefaultTimeField: jest.fn(), + getOperationForColumnId: jest.fn(() => ({ + hasReducedTimeRange: false, + })), } as unknown as DatasourcePublicAPI, removeLayer: jest.fn(), addLayer: jest.fn(), @@ -305,16 +308,37 @@ describe('dimension editor', () => { expect( getHarnessWithState(stateWOTrend, { hasDefaultTimeField: () => false, + getOperationForColumnId: (id) => ({} as OperationDescriptor), } as DatasourcePublicAPI).isDisabled('trendline') ).toBeTruthy(); expect( getHarnessWithState(stateWOTrend, { hasDefaultTimeField: () => true, + getOperationForColumnId: (id) => ({} as OperationDescriptor), } as DatasourcePublicAPI).isDisabled('trendline') ).toBeFalsy(); }); }); + it('should disable trendline when a metric dimension has a reduced time range', () => { + expect( + getHarnessWithState(stateWOTrend, { + hasDefaultTimeField: () => true, + getOperationForColumnId: (id) => + ({ hasReducedTimeRange: id === stateWOTrend.metricAccessor } as OperationDescriptor), + } as DatasourcePublicAPI).isDisabled('trendline') + ).toBeTruthy(); + expect( + getHarnessWithState(stateWOTrend, { + hasDefaultTimeField: () => true, + getOperationForColumnId: (id) => + ({ + hasReducedTimeRange: id === stateWOTrend.secondaryMetricAccessor, + } as OperationDescriptor), + } as DatasourcePublicAPI).isDisabled('trendline') + ).toBeTruthy(); + }); + describe('responding to buttons', () => { it('enables trendline', () => { getHarnessWithState(stateWOTrend).setSupportingVis('trendline'); diff --git a/x-pack/plugins/lens/public/visualizations/metric/dimension_editor.tsx b/x-pack/plugins/lens/public/visualizations/metric/dimension_editor.tsx index 17d768dd5a212..4ca35b060e023 100644 --- a/x-pack/plugins/lens/public/visualizations/metric/dimension_editor.tsx +++ b/x-pack/plugins/lens/public/visualizations/metric/dimension_editor.tsx @@ -263,26 +263,52 @@ function PrimaryMetricEditor(props: SubProps) { const togglePalette = () => setIsPaletteOpen(!isPaletteOpen); - const hasDefaultTimeField = props.datasource?.hasDefaultTimeField(); const supportingVisLabel = i18n.translate('xpack.lens.metric.supportingVis.label', { defaultMessage: 'Supporting visualization', }); - const supportingVisHelpText = - !hasDefaultTimeField && !state.maxAccessor - ? i18n.translate('xpack.lens.metric.supportingVis.needBoth', { - defaultMessage: - 'Use a data view with a default time field to enable trendlines. Add a maximum dimension to enable the progress bar', - }) - : !hasDefaultTimeField - ? i18n.translate('xpack.lens.metric.supportingVis.needDefaultTimeField', { - defaultMessage: 'Use a data view with a default time field to enable trendlines.', - }) - : !state.maxAccessor - ? i18n.translate('xpack.lens.metric.summportingVis.needMaxDimension', { - defaultMessage: 'Add a maximum dimension to enable the progress bar.', - }) - : null; + const hasDefaultTimeField = props.datasource?.hasDefaultTimeField(); + const metricHasReducedTimeRange = Boolean( + state.metricAccessor && + props.datasource?.getOperationForColumnId(state.metricAccessor)?.hasReducedTimeRange + ); + const secondaryMetricHasReducedTimeRange = Boolean( + state.secondaryMetricAccessor && + props.datasource?.getOperationForColumnId(state.secondaryMetricAccessor)?.hasReducedTimeRange + ); + + const supportingVisHelpTexts: string[] = []; + + const supportsTrendline = + hasDefaultTimeField && !metricHasReducedTimeRange && !secondaryMetricHasReducedTimeRange; + + if (!supportsTrendline) { + supportingVisHelpTexts.push( + !hasDefaultTimeField + ? i18n.translate('xpack.lens.metric.supportingVis.needDefaultTimeField', { + defaultMessage: 'Use a data view with a default time field to enable trend lines.', + }) + : metricHasReducedTimeRange + ? i18n.translate('xpack.lens.metric.supportingVis.metricHasReducedTimeRange', { + defaultMessage: + 'Remove the reduced time range on this dimension to enable trend lines.', + }) + : secondaryMetricHasReducedTimeRange + ? i18n.translate('xpack.lens.metric.supportingVis.secondaryMetricHasReducedTimeRange', { + defaultMessage: + 'Remove the reduced time range on the secondary metric dimension to enable trend lines.', + }) + : '' + ); + } + + if (!state.maxAccessor) { + supportingVisHelpTexts.push( + i18n.translate('xpack.lens.metric.summportingVis.needMaxDimension', { + defaultMessage: 'Add a maximum dimension to enable the progress bar.', + }) + ); + } const buttonIdPrefix = `${idPrefix}--`; @@ -292,7 +318,9 @@ function PrimaryMetricEditor(props: SubProps) { display="columnCompressed" fullWidth label={supportingVisLabel} - helpText={supportingVisHelpText} + helpText={supportingVisHelpTexts.map((text) => ( +
{text}
+ ))} > { label: 'date_histogram', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, }; } return null; @@ -1685,6 +1686,7 @@ describe('xy_visualization', () => { label: 'date_histogram', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, }; } return null; @@ -1715,6 +1717,7 @@ describe('xy_visualization', () => { label: 'date_histogram', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, }; } return null; @@ -1759,6 +1762,7 @@ describe('xy_visualization', () => { label: 'histogram', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, }; } return null; @@ -1791,6 +1795,7 @@ describe('xy_visualization', () => { label: 'top values', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, }; } return null; @@ -1821,6 +1826,7 @@ describe('xy_visualization', () => { label: 'top values', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, }; } return null; @@ -1930,6 +1936,7 @@ describe('xy_visualization', () => { label: 'date_histogram', isStaticValue: false, hasTimeShift: false, + hasReducedTimeRange: false, }; } return null;