mirror of
https://github.com/apache/superset.git
synced 2026-06-01 21:59:26 +00:00
fix(explore): Metric control breaks when saved metric deleted from dataset (#17503)
This commit is contained in:
committed by
GitHub
parent
83e49fc9ee
commit
7353a2bd75
@@ -120,6 +120,62 @@ test('remove selected custom metric when metric gets removed from dataset', () =
|
||||
expect(screen.getByText('SUM(Column B)')).toBeVisible();
|
||||
});
|
||||
|
||||
test('remove selected custom metric when metric gets removed from dataset for single-select metric control', () => {
|
||||
let metricValue = 'metric_b';
|
||||
|
||||
const onChange = (val: any) => {
|
||||
metricValue = val;
|
||||
};
|
||||
|
||||
const { rerender } = render(
|
||||
<DndMetricSelect
|
||||
{...defaultProps}
|
||||
value={metricValue}
|
||||
onChange={onChange}
|
||||
multi={false}
|
||||
/>,
|
||||
{
|
||||
useDnd: true,
|
||||
},
|
||||
);
|
||||
|
||||
expect(screen.getByText('Metric B')).toBeVisible();
|
||||
expect(
|
||||
screen.queryByText('Drop column or metric here'),
|
||||
).not.toBeInTheDocument();
|
||||
|
||||
const newPropsWithRemovedMetric = {
|
||||
...defaultProps,
|
||||
savedMetrics: [
|
||||
{
|
||||
metric_name: 'metric_a',
|
||||
expression: 'expression_a',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
// rerender twice - first to update columns, second to update value
|
||||
rerender(
|
||||
<DndMetricSelect
|
||||
{...newPropsWithRemovedMetric}
|
||||
value={metricValue}
|
||||
onChange={onChange}
|
||||
multi={false}
|
||||
/>,
|
||||
);
|
||||
rerender(
|
||||
<DndMetricSelect
|
||||
{...newPropsWithRemovedMetric}
|
||||
value={metricValue}
|
||||
onChange={onChange}
|
||||
multi={false}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(screen.queryByText('Metric B')).not.toBeInTheDocument();
|
||||
expect(screen.getByText('Drop column or metric here')).toBeVisible();
|
||||
});
|
||||
|
||||
test('remove selected adhoc metric when column gets removed from dataset', async () => {
|
||||
let metricValues = ['metric_a', 'metric_b', adhocMetricA, adhocMetricB];
|
||||
const onChange = (val: any[]) => {
|
||||
|
||||
@@ -87,7 +87,7 @@ const getMetricsMatchingCurrentDataset = (
|
||||
savedMetrics: (savedMetricType | Metric)[],
|
||||
prevColumns: ColumnMeta[],
|
||||
prevSavedMetrics: (savedMetricType | Metric)[],
|
||||
) => {
|
||||
): ValueType[] => {
|
||||
const areSavedMetricsEqual =
|
||||
!prevSavedMetrics || isEqual(prevSavedMetrics, savedMetrics);
|
||||
const areColsEqual = !prevColumns || isEqual(prevColumns, columns);
|
||||
@@ -96,16 +96,17 @@ const getMetricsMatchingCurrentDataset = (
|
||||
return values;
|
||||
}
|
||||
return values.reduce((acc: ValueType[], metric) => {
|
||||
if (
|
||||
(typeof metric === 'string' || (metric as Metric).metric_name) &&
|
||||
(areSavedMetricsEqual ||
|
||||
if (typeof metric === 'string' || (metric as Metric).metric_name) {
|
||||
if (
|
||||
areSavedMetricsEqual ||
|
||||
savedMetrics?.some(
|
||||
savedMetric =>
|
||||
savedMetric.metric_name === metric ||
|
||||
savedMetric.metric_name === (metric as Metric).metric_name,
|
||||
))
|
||||
) {
|
||||
acc.push(metric);
|
||||
)
|
||||
) {
|
||||
acc.push(metric);
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user