From f196329cae3effae5c653a6843cf8f9346ef31d3 Mon Sep 17 00:00:00 2001 From: shahzad31 Date: Wed, 3 Nov 2021 13:58:48 +0100 Subject: [PATCH 1/4] fix labels and duplicate breakdowns --- .../configurations/lens_attributes.test.ts | 6 +++--- .../configurations/lens_attributes.ts | 12 +++++++++++- .../configurations/test_data/sample_attribute.ts | 2 +- .../configurations/test_data/sample_attribute_kpi.ts | 2 +- .../series_editor/columns/series_actions.tsx | 2 +- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.test.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.test.ts index 139f9fe67c751e..c17a6c3fd2ee5d 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.test.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.test.ts @@ -136,7 +136,7 @@ describe('Lens Attribute', () => { expect(lnsAttr.getMainYAxis(layerConfig, 'layer0', '')).toEqual({ dataType: 'number', isBucketed: false, - label: 'Pages loaded', + label: 'test-series', operationType: 'formula', params: { format: { @@ -361,7 +361,7 @@ describe('Lens Attribute', () => { 'transaction.type: page-load and processor.event: transaction and transaction.type : *', }, isBucketed: false, - label: 'Pages loaded', + label: 'test-series', operationType: 'formula', params: { format: { @@ -571,7 +571,7 @@ describe('Lens Attribute', () => { 'transaction.type: page-load and processor.event: transaction and transaction.type : *', }, isBucketed: false, - label: 'Pages loaded', + label: 'test-series', operationType: 'formula', params: { format: { diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.ts index 5e769882a2793e..ee3009f7204fb2 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.ts @@ -482,7 +482,17 @@ export class LensAttributes { getMainYAxis(layerConfig: LayerConfig, layerId: string, columnFilter: string) { const { breakdown } = layerConfig; - const { sourceField, operationType, label } = layerConfig.seriesConfig.yAxisColumns[0]; + const { + sourceField, + operationType, + label: colLabel, + } = layerConfig.seriesConfig.yAxisColumns[0]; + + let label = layerConfig.name || colLabel; + + if (layerConfig.seriesConfig.reportType === ReportTypes.CORE_WEB_VITAL) { + label = colLabel; + } if (sourceField === RECORDS_PERCENTAGE_FIELD) { return getDistributionInPercentageColumn({ label, layerId, columnFilter }).main; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/test_data/sample_attribute.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/test_data/sample_attribute.ts index 8254a5a816921b..0ecc38197b1eb9 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/test_data/sample_attribute.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/test_data/sample_attribute.ts @@ -60,7 +60,7 @@ export const sampleAttribute = { 'transaction.type: page-load and processor.event: transaction and transaction.type : *', }, isBucketed: false, - label: 'Pages loaded', + label: 'test-series', operationType: 'formula', params: { format: { diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/test_data/sample_attribute_kpi.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/test_data/sample_attribute_kpi.ts index 8fbda9f6adc522..09324de96a8250 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/test_data/sample_attribute_kpi.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/test_data/sample_attribute_kpi.ts @@ -43,7 +43,7 @@ export const sampleAttributeKpi = { query: 'transaction.type: page-load and processor.event: transaction', }, isBucketed: false, - label: 'Page views', + label: 'test-series', operationType: 'count', scale: 'ratio', sourceField: 'Records', diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/series_actions.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/series_actions.tsx index 37b5b1571f84d3..c1462ce74b4264 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/series_actions.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/series_actions.tsx @@ -30,7 +30,7 @@ export function SeriesActions({ seriesId, series, seriesConfig, onEditClick }: P if (allSeries.find(({ name }) => name === copySeriesId)) { copySeriesId = copySeriesId + allSeries.length; } - setSeries(allSeries.length, { ...series, name: copySeriesId }); + setSeries(allSeries.length, { ...series, name: copySeriesId, breakdown: undefined }); }; const toggleSeries = () => { From 5a1a3d36715a26aa8672315d786d02e89cf21acd Mon Sep 17 00:00:00 2001 From: shahzad31 Date: Tue, 9 Nov 2021 18:30:09 +0100 Subject: [PATCH 2/4] fix labels --- .../configurations/lens_attributes.ts | 6 +++--- .../series_editor/columns/data_type_select.tsx | 13 ++++++++++++- .../series_editor/report_metric_options.tsx | 6 ++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.ts index 43d251c67e7e2b..717c92c71435c0 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.ts @@ -407,7 +407,7 @@ export class LensAttributes { const { type: fieldType } = fieldMeta ?? {}; if (columnType === TERMS_COLUMN) { - return this.getTermsColumn(fieldName, columnLabel || label); + return this.getTermsColumn(fieldName, label || columnLabel); } if (fieldName === RECORDS_FIELD || columnType === FILTER_RECORDS) { @@ -439,14 +439,14 @@ export class LensAttributes { columnType, columnFilter: columnFilters?.[0], operationType, - label: columnLabel || label, + label: label || columnLabel, seriesConfig: layerConfig.seriesConfig, }); } if (operationType === 'unique_count') { return this.getCardinalityColumn({ sourceField: fieldName, - label: columnLabel || label, + label: label || columnLabel, seriesConfig: layerConfig.seriesConfig, }); } diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/data_type_select.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/data_type_select.tsx index 71fd147e8e2640..a52c4cee493e0f 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/data_type_select.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/data_type_select.tsx @@ -63,6 +63,17 @@ export const dataTypes: Array<{ id: AppDataType; label: string }> = [ const SELECT_DATA_TYPE = 'SELECT_DATA_TYPE'; +export const getInitialSeriesName = ( + dataType: AppDataType, + seriesId: number, + selectedMetric?: string +) => { + if (selectedMetric) { + return `${dataType}-${selectedMetric.toLowerCase().replaceAll(' ', '-')}-${seriesId + 1}`; + } + return `${dataType}-${seriesId + 1}`; +}; + export function DataTypesSelect({ seriesId, series }: Props) { const { setSeries, reportType } = useSeriesStorage(); const [showOptions, setShowOptions] = useState(false); @@ -72,7 +83,7 @@ export function DataTypesSelect({ seriesId, series }: Props) { setSeries(seriesId, { dataType, time: series.time, - name: `${dataType}-series-${seriesId + 1}`, + name: getInitialSeriesName(dataType, seriesId), }); } }; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/report_metric_options.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/report_metric_options.tsx index eca18f0eb0dd40..750540d76fdf09 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/report_metric_options.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/report_metric_options.tsx @@ -22,6 +22,7 @@ import { useSeriesStorage } from '../hooks/use_series_storage'; import { SeriesConfig, SeriesUrl } from '../types'; import { useAppIndexPatternContext } from '../hooks/use_app_index_pattern'; import { RECORDS_FIELD, RECORDS_PERCENTAGE_FIELD } from '../configurations/constants'; +import { getInitialSeriesName } from './columns/data_type_select'; interface Props { seriesId: number; @@ -38,8 +39,13 @@ export function ReportMetricOptions({ seriesId, series, seriesConfig }: Props) { const { indexPatterns, loading } = useAppIndexPatternContext(); const onChange = (value?: string) => { + let currName = series.name; + if (currName === getInitialSeriesName(series.dataType, seriesId) && value) { + currName = getInitialSeriesName(series.dataType, seriesId, seriesConfig?.labels[value]); + } setSeries(seriesId, { ...series, + name: currName, selectedMetricField: value, }); }; From c49ee2dbe5be1e8d6d629c8f380f4c30f6dc3eb6 Mon Sep 17 00:00:00 2001 From: shahzad31 Date: Tue, 9 Nov 2021 18:34:52 +0100 Subject: [PATCH 3/4] revert --- .../configurations/lens_attributes.test.ts | 6 +++--- .../configurations/lens_attributes.ts | 12 +----------- .../configurations/test_data/sample_attribute.ts | 2 +- .../test_data/sample_attribute_kpi.ts | 2 +- .../series_editor/columns/data_type_select.tsx | 13 +------------ .../series_editor/report_metric_options.tsx | 6 ------ 6 files changed, 7 insertions(+), 34 deletions(-) diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.test.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.test.ts index a0400f0c7bbaeb..135cf3c59a1ce2 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.test.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.test.ts @@ -137,7 +137,7 @@ describe('Lens Attribute', () => { expect(lnsAttr.getMainYAxis(layerConfig, 'layer0', '')).toEqual({ dataType: 'number', isBucketed: false, - label: 'test-series', + label: 'Pages loaded', operationType: 'formula', params: { format: { @@ -362,7 +362,7 @@ describe('Lens Attribute', () => { 'transaction.type: page-load and processor.event: transaction and transaction.type : *', }, isBucketed: false, - label: 'test-series', + label: 'Pages loaded', operationType: 'formula', params: { format: { @@ -572,7 +572,7 @@ describe('Lens Attribute', () => { 'transaction.type: page-load and processor.event: transaction and transaction.type : *', }, isBucketed: false, - label: 'test-series', + label: 'Pages loaded', operationType: 'formula', params: { format: { diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.ts index 717c92c71435c0..5e02865c2b1bb0 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.ts @@ -482,17 +482,7 @@ export class LensAttributes { getMainYAxis(layerConfig: LayerConfig, layerId: string, columnFilter: string) { const { breakdown } = layerConfig; - const { - sourceField, - operationType, - label: colLabel, - } = layerConfig.seriesConfig.yAxisColumns[0]; - - let label = layerConfig.name || colLabel; - - if (layerConfig.seriesConfig.reportType === ReportTypes.CORE_WEB_VITAL) { - label = colLabel; - } + const { sourceField, operationType, label } = layerConfig.seriesConfig.yAxisColumns[0]; if (sourceField === RECORDS_PERCENTAGE_FIELD) { return getDistributionInPercentageColumn({ label, layerId, columnFilter }).main; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/test_data/sample_attribute.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/test_data/sample_attribute.ts index eca32dac25f2ce..cfbd2a5df0358a 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/test_data/sample_attribute.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/test_data/sample_attribute.ts @@ -60,7 +60,7 @@ export const sampleAttribute = { 'transaction.type: page-load and processor.event: transaction and transaction.type : *', }, isBucketed: false, - label: 'test-series', + label: 'Pages loaded', operationType: 'formula', params: { format: { diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/test_data/sample_attribute_kpi.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/test_data/sample_attribute_kpi.ts index 0bf2c2402d49a1..668049dcc122bd 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/test_data/sample_attribute_kpi.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/test_data/sample_attribute_kpi.ts @@ -43,7 +43,7 @@ export const sampleAttributeKpi = { query: 'transaction.type: page-load and processor.event: transaction', }, isBucketed: false, - label: 'test-series', + label: 'Page views', operationType: 'count', scale: 'ratio', sourceField: 'Records', diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/data_type_select.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/data_type_select.tsx index a52c4cee493e0f..71fd147e8e2640 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/data_type_select.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/data_type_select.tsx @@ -63,17 +63,6 @@ export const dataTypes: Array<{ id: AppDataType; label: string }> = [ const SELECT_DATA_TYPE = 'SELECT_DATA_TYPE'; -export const getInitialSeriesName = ( - dataType: AppDataType, - seriesId: number, - selectedMetric?: string -) => { - if (selectedMetric) { - return `${dataType}-${selectedMetric.toLowerCase().replaceAll(' ', '-')}-${seriesId + 1}`; - } - return `${dataType}-${seriesId + 1}`; -}; - export function DataTypesSelect({ seriesId, series }: Props) { const { setSeries, reportType } = useSeriesStorage(); const [showOptions, setShowOptions] = useState(false); @@ -83,7 +72,7 @@ export function DataTypesSelect({ seriesId, series }: Props) { setSeries(seriesId, { dataType, time: series.time, - name: getInitialSeriesName(dataType, seriesId), + name: `${dataType}-series-${seriesId + 1}`, }); } }; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/report_metric_options.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/report_metric_options.tsx index 750540d76fdf09..eca18f0eb0dd40 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/report_metric_options.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/report_metric_options.tsx @@ -22,7 +22,6 @@ import { useSeriesStorage } from '../hooks/use_series_storage'; import { SeriesConfig, SeriesUrl } from '../types'; import { useAppIndexPatternContext } from '../hooks/use_app_index_pattern'; import { RECORDS_FIELD, RECORDS_PERCENTAGE_FIELD } from '../configurations/constants'; -import { getInitialSeriesName } from './columns/data_type_select'; interface Props { seriesId: number; @@ -39,13 +38,8 @@ export function ReportMetricOptions({ seriesId, series, seriesConfig }: Props) { const { indexPatterns, loading } = useAppIndexPatternContext(); const onChange = (value?: string) => { - let currName = series.name; - if (currName === getInitialSeriesName(series.dataType, seriesId) && value) { - currName = getInitialSeriesName(series.dataType, seriesId, seriesConfig?.labels[value]); - } setSeries(seriesId, { ...series, - name: currName, selectedMetricField: value, }); }; From 9974a15bed3a44451fc833802783eafb5954f89e Mon Sep 17 00:00:00 2001 From: shahzad31 Date: Tue, 9 Nov 2021 18:35:29 +0100 Subject: [PATCH 4/4] revert --- .../exploratory_view/configurations/lens_attributes.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.ts index 5e02865c2b1bb0..3e6e6d9cb83b02 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.ts @@ -407,7 +407,7 @@ export class LensAttributes { const { type: fieldType } = fieldMeta ?? {}; if (columnType === TERMS_COLUMN) { - return this.getTermsColumn(fieldName, label || columnLabel); + return this.getTermsColumn(fieldName, columnLabel || label); } if (fieldName === RECORDS_FIELD || columnType === FILTER_RECORDS) { @@ -439,14 +439,14 @@ export class LensAttributes { columnType, columnFilter: columnFilters?.[0], operationType, - label: label || columnLabel, + label: columnLabel || label, seriesConfig: layerConfig.seriesConfig, }); } if (operationType === 'unique_count') { return this.getCardinalityColumn({ sourceField: fieldName, - label: label || columnLabel, + label: columnLabel || label, seriesConfig: layerConfig.seriesConfig, }); }