Compare commits

...

1 Commits

Author SHA1 Message Date
rusackas
7cd415c4af fix(chart): stop duplicate metrics when switching between Waterfall and other chart types
The Waterfall control panel never drained the shared standardized-controls
metric/column queue on viz-type switch (no formDataOverrides), so metrics
picked up when entering Waterfall stayed queued and got re-applied on top
of the original ones when switching back to a multi-metric chart (e.g.
Line), producing duplicate measures. Add the same formDataOverrides
pattern used by the other single-metric echarts charts (Pie, Gauge,
Sunburst, etc.) so Waterfall shifts exactly one metric and pops all
columns from the queue.

Fixes #32835

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-28 03:25:37 -07:00
2 changed files with 68 additions and 0 deletions

View File

@@ -23,6 +23,7 @@ import {
D3_TIME_FORMAT_DOCS,
DEFAULT_TIME_FORMAT,
formatSelectOptions,
getStandardizedControls,
sharedControls,
} from '@superset-ui/chart-controls';
import { showValueControl } from '../controls';
@@ -245,6 +246,11 @@ const config: ControlPanelConfig = {
multi: false,
},
},
formDataOverrides: formData => ({
...formData,
metric: getStandardizedControls().shiftMetric(),
groupby: getStandardizedControls().popAllColumns(),
}),
};
export default config;

View File

@@ -0,0 +1,62 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { SqlaFormData } from '@superset-ui/core';
// Mock getStandardizedControls so we can assert the Waterfall control panel
// actually consumes (shifts/pops) the queued metrics and columns instead of
// leaving them for the next viz-type switch to pick up again. Regression
// test for https://github.com/apache/superset/issues/32835, where switching
// away from and back to another chart type (e.g. Line) produced duplicate
// metrics because Waterfall never drained the shared standardized-controls
// queue.
const mockShiftMetric = jest.fn(() => 'shiftedMetric');
const mockPopAllColumns = jest.fn(() => ['poppedColumn']);
jest.mock('@superset-ui/chart-controls', () => {
const actual = jest.requireActual('@superset-ui/chart-controls');
return {
...actual,
getStandardizedControls: jest.fn(() => ({
shiftMetric: mockShiftMetric,
popAllColumns: mockPopAllColumns,
})),
};
});
// eslint-disable-next-line import/first
import controlPanel from '../../src/Waterfall/controlPanel';
test('formDataOverrides consumes a single metric and all columns from getStandardizedControls', () => {
expect(controlPanel.formDataOverrides).toBeDefined();
const dummyFormData = { someProp: 'test' } as unknown as SqlaFormData;
const newFormData = controlPanel.formDataOverrides!(dummyFormData);
// original properties are preserved
expect(newFormData.someProp).toBe('test');
// only a single metric is taken (Waterfall only supports one metric),
// leaving any remaining queued metrics for the next viz-type switch
expect(newFormData.metric).toBe('shiftedMetric');
expect(mockShiftMetric).toHaveBeenCalled();
// all queued columns are consumed for the (single) groupby control
expect(newFormData.groupby).toEqual(['poppedColumn']);
expect(mockPopAllColumns).toHaveBeenCalled();
});