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 9e1076900f6..86643e26822 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 @@ -43,15 +43,17 @@ export const renameOperator: PostProcessingFactory = ( // remove or rename top level of column name(metric name) in the MultiIndex when // 1) at least 1 metric - // 2) dimension exist or multiple time shift metrics exist - // 3) xAxis exist - // 4) truncate_metric in form_data and truncate_metric is true + // 2) xAxis exist + // 3a) isTimeComparisonValue + // 3b-1) dimension exist or multiple time shift metrics exist + // 3b-2) truncate_metric in form_data and truncate_metric is true if ( metrics.length > 0 && - (columns.length > 0 || timeOffsets.length > 1) && xAxisLabel && - truncate_metric !== undefined && - !!truncate_metric + (isTimeComparisonValue || + ((columns.length > 0 || timeOffsets.length > 1) && + truncate_metric !== undefined && + !!truncate_metric)) ) { const renamePairs: [string, string | null][] = []; if ( diff --git a/superset-frontend/packages/superset-ui-chart-controls/test/operators/renameOperator.test.ts b/superset-frontend/packages/superset-ui-chart-controls/test/operators/renameOperator.test.ts index 19d594a7f61..26669a75103 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/test/operators/renameOperator.test.ts +++ b/superset-frontend/packages/superset-ui-chart-controls/test/operators/renameOperator.test.ts @@ -160,6 +160,44 @@ test('should add renameOperator if exists derived metrics', () => { }); }); +test('should add renameOperator if isTimeComparisonValue without columns', () => { + [ + ComparisonType.Difference, + ComparisonType.Ratio, + ComparisonType.Percentage, + ].forEach(type => { + expect( + renameOperator( + { + ...formData, + ...{ + comparison_type: type, + time_compare: ['1 year ago'], + }, + }, + { + ...queryObject, + ...{ + columns: [], + metrics: ['sum(val)', 'avg(val2)'], + }, + }, + ), + ).toEqual({ + operation: 'rename', + options: { + columns: { + [`${type}__avg(val2)__avg(val2)__1 year ago`]: + 'avg(val2), 1 year ago', + [`${type}__sum(val)__sum(val)__1 year ago`]: 'sum(val), 1 year ago', + }, + inplace: true, + level: 0, + }, + }); + }); +}); + test('should add renameOperator if x_axis does not exist', () => { expect( renameOperator(