Skip to content

Commit 6f5d9c9

Browse files
authored
fix(echarts): rename time series shifted without dimensions (#34541)
1 parent 8515792 commit 6f5d9c9

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

superset-frontend/packages/superset-ui-chart-controls/src/operators/renameOperator.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,19 @@ export const renameOperator: PostProcessingFactory<PostProcessingRename> = (
3636
const columns = ensureIsArray(
3737
queryObject.series_columns || queryObject.columns,
3838
);
39+
const timeOffsets = ensureIsArray(formData.time_compare);
3940
const { truncate_metric } = formData;
4041
const xAxisLabel = getXAxisLabel(formData);
4142
const isTimeComparisonValue = isTimeComparison(formData, queryObject);
4243

4344
// remove or rename top level of column name(metric name) in the MultiIndex when
4445
// 1) at least 1 metric
45-
// 2) dimension exist
46+
// 2) dimension exist or multiple time shift metrics exist
4647
// 3) xAxis exist
4748
// 4) truncate_metric in form_data and truncate_metric is true
4849
if (
4950
metrics.length > 0 &&
50-
columns.length > 0 &&
51+
(columns.length > 0 || timeOffsets.length > 1) &&
5152
xAxisLabel &&
5253
truncate_metric !== undefined &&
5354
!!truncate_metric
@@ -84,7 +85,8 @@ export const renameOperator: PostProcessingFactory<PostProcessingRename> = (
8485
ComparisonType.Percentage,
8586
ComparisonType.Ratio,
8687
].includes(formData.comparison_type) &&
87-
metrics.length === 1
88+
metrics.length === 1 &&
89+
renamePairs.length === 0
8890
) {
8991
renamePairs.push([getMetricLabel(metrics[0]), null]);
9092
}

superset-frontend/packages/superset-ui-chart-controls/test/operators/renameOperator.test.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ test('should skip renameOperator if series does not exist', () => {
6565
).toEqual(undefined);
6666
});
6767

68+
test('should skip renameOperator if series does not exist and a single time shift exists', () => {
69+
expect(
70+
renameOperator(
71+
{ ...formData, ...{ time_compare: ['1 year ago'] } },
72+
{
73+
...queryObject,
74+
...{
75+
columns: [],
76+
},
77+
},
78+
),
79+
).toEqual(undefined);
80+
});
81+
6882
test('should skip renameOperator if does not exist x_axis and is_timeseries', () => {
6983
expect(
7084
renameOperator(
@@ -93,6 +107,26 @@ test('should add renameOperator', () => {
93107
});
94108
});
95109

110+
test('should add renameOperator if a metric exists and multiple time shift', () => {
111+
expect(
112+
renameOperator(
113+
{
114+
...formData,
115+
...{ time_compare: ['1 year ago', '2 years ago'] },
116+
},
117+
{
118+
...queryObject,
119+
...{
120+
columns: [],
121+
},
122+
},
123+
),
124+
).toEqual({
125+
operation: 'rename',
126+
options: { columns: { 'count(*)': null }, inplace: true, level: 0 },
127+
});
128+
});
129+
96130
test('should add renameOperator if exists derived metrics', () => {
97131
[
98132
ComparisonType.Difference,
@@ -176,7 +210,6 @@ test('should add renameOperator if exist "actual value" time comparison', () =>
176210
operation: 'rename',
177211
options: {
178212
columns: {
179-
'count(*)': null,
180213
'count(*)__1 year ago': '1 year ago',
181214
'count(*)__1 year later': '1 year later',
182215
},

0 commit comments

Comments
 (0)