From a4cbd74b0847b56a98878acc4df421ccb050707c Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Tue, 19 Apr 2022 22:05:45 +0800 Subject: [PATCH] fix crash --- .../src/operators/renameOperator.ts | 12 +++++++++++- .../src/operators/timeCompareRenameOperator.ts | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/operators/renameOperator.ts b/superset-frontend/packages/superset-ui-chart-controls/src/operators/renameOperator.ts index fab802b146ac8..7ded21084b2d8 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/operators/renameOperator.ts +++ b/superset-frontend/packages/superset-ui-chart-controls/src/operators/renameOperator.ts @@ -29,7 +29,17 @@ export const renameOperator: PostProcessingFactory = ( queryObject, ) => { const metrics = ensureIsArray(queryObject.metrics); - if (metrics.length === 1) { + const columns = ensureIsArray(queryObject.columns); + const { x_axis: xAxis } = formData; + // remove metric name in the MultiIndex when + // 1) only 1 metric + // 2) exist dimentsion + // 3) exist xAxis + if ( + metrics.length === 1 && + columns.length > 0 && + (xAxis || queryObject.is_timeseries) + ) { const mainQueryMetricName = getMetricLabel(metrics[0]); return { operation: 'rename', diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/operators/timeCompareRenameOperator.ts b/superset-frontend/packages/superset-ui-chart-controls/src/operators/timeCompareRenameOperator.ts index 2dae01c5fa81c..bbb4e432a1c5a 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/operators/timeCompareRenameOperator.ts +++ b/superset-frontend/packages/superset-ui-chart-controls/src/operators/timeCompareRenameOperator.ts @@ -28,8 +28,16 @@ import { getMetricOffsetsMap, isValidTimeCompare } from './utils'; export const timeCompareRenameOperator: PostProcessingFactory = (formData, queryObject) => { const metrics = ensureIsArray(queryObject.metrics); + const columns = ensureIsArray(queryObject.columns); + const { x_axis: xAxis } = formData; + // remove metric name in the MultiIndex when + // 1) only 1 metric + // 2) exist dimentsion + // 3) exist xAxis if ( metrics.length === 1 && + columns.length > 0 && + (xAxis || queryObject.is_timeseries) && // "actual values" will add derived metric. isValidTimeCompare(formData, queryObject) && formData.comparison_type === ComparisionType.Values