Skip to content

Commit

Permalink
gating trendlines if reduced time range is present
Browse files Browse the repository at this point in the history
  • Loading branch information
drewdaemon committed Oct 14, 2022
1 parent 5b0dbe3 commit 8ee436c
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ describe('getLayerMetaInfo', () => {
isStaticValue: false,
sortingHint: undefined,
hasTimeShift: true,
hasReducedTimeRange: true,
})),
getTableSpec: jest.fn(),
getVisualDefaults: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1868,6 +1868,7 @@ describe('IndexPattern Data Source', () => {
isBucketed: true,
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
} as OperationDescriptor);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -119,6 +119,7 @@ export function columnToOperation(
? 'version'
: undefined,
hasTimeShift: Boolean(timeShift),
hasReducedTimeRange: Boolean(reducedTimeRange),
interval: isColumnOfType<DateHistogramIndexPatternColumn>('date_histogram', column)
? column.params.interval
: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: undefined,
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
},
},
{
Expand All @@ -1294,6 +1295,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: 'ratio',
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
},
},
],
Expand Down Expand Up @@ -1373,6 +1375,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: undefined,
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
},
},
{
Expand All @@ -1384,6 +1387,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: 'ratio',
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
},
},
],
Expand Down Expand Up @@ -2198,6 +2202,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: undefined,
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
},
},
],
Expand All @@ -2222,6 +2227,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: undefined,
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
},
},
],
Expand Down Expand Up @@ -2272,6 +2278,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: 'interval',
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
interval: 'auto',
},
},
Expand All @@ -2284,6 +2291,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: 'ratio',
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
interval: undefined,
},
},
Expand Down Expand Up @@ -2349,6 +2357,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: 'ordinal',
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
interval: undefined,
},
},
Expand All @@ -2361,6 +2370,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: 'interval',
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
interval: 'auto',
},
},
Expand All @@ -2373,6 +2383,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: 'ratio',
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
interval: undefined,
},
},
Expand Down Expand Up @@ -2459,6 +2470,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: 'ordinal',
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
interval: undefined,
},
},
Expand All @@ -2471,6 +2483,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: 'interval',
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
interval: 'auto',
},
},
Expand All @@ -2483,6 +2496,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: 'ratio',
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
interval: undefined,
},
},
Expand Down Expand Up @@ -2592,6 +2606,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: 'ordinal',
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
interval: undefined,
},
},
Expand All @@ -2604,6 +2619,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: 'interval',
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
interval: 'auto',
},
},
Expand All @@ -2616,6 +2632,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: undefined,
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
interval: undefined,
},
},
Expand Down Expand Up @@ -3123,6 +3140,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: undefined,
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
},
},
{
Expand All @@ -3134,6 +3152,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: undefined,
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
},
},
],
Expand Down Expand Up @@ -3201,6 +3220,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: 'interval',
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
interval: 'auto',
},
},
Expand All @@ -3213,6 +3233,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: undefined,
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
interval: undefined,
},
},
Expand All @@ -3225,6 +3246,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: undefined,
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
interval: undefined,
},
},
Expand Down Expand Up @@ -3291,6 +3313,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: undefined,
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
interval: 'auto',
},
},
Expand All @@ -3303,6 +3326,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: undefined,
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
interval: undefined,
},
},
Expand All @@ -3315,6 +3339,7 @@ describe('IndexPattern Data Source suggestions', () => {
scale: undefined,
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
interval: undefined,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ describe('IndexPattern Data Source', () => {
dataType: 'number',
isBucketed: false,
hasTimeShift: false,
hasReducedTimeRange: false,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ export function getTextBasedDatasource({
label: columnLabelMap[columnId] ?? column?.fieldName,
isBucketed: Boolean(column?.meta?.type !== 'number'),
hasTimeShift: false,
hasReducedTimeRange: false,
};
}
return null;
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/lens/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ export interface OperationMetadata {
*/
export interface OperationDescriptor extends Operation {
hasTimeShift: boolean;
hasReducedTimeRange: boolean;
}

export interface VisualizationConfigProps<T = unknown> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ describe('Datatable Visualization', () => {
label: 'label',
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
});

const expression = datatableVisualization.toExpression(
Expand Down Expand Up @@ -577,6 +578,7 @@ describe('Datatable Visualization', () => {
label: 'label',
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
});

const expression = datatableVisualization.toExpression(
Expand Down Expand Up @@ -712,6 +714,7 @@ describe('Datatable Visualization', () => {
label: 'label',
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
});

const error = datatableVisualization.getErrorMessages({
Expand All @@ -737,6 +740,7 @@ describe('Datatable Visualization', () => {
label: 'label',
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
});

const error = datatableVisualization.getErrorMessages({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ describe('metric_visualization', () => {
label: 'shazm',
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
};
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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');
Expand Down
Loading

0 comments on commit 8ee436c

Please sign in to comment.