mirror of
https://github.com/apache/superset.git
synced 2024-09-12 08:39:45 -04:00
fix(chart-controls): Error if x_axis_sort and timeseries_limit_metric are included in main metrics (#23365)
This commit is contained in:
parent
b90a11191f
commit
63513a5873
@ -25,12 +25,13 @@ import {
|
|||||||
export function extractExtraMetrics(
|
export function extractExtraMetrics(
|
||||||
formData: QueryFormData,
|
formData: QueryFormData,
|
||||||
): QueryFormMetric[] {
|
): QueryFormMetric[] {
|
||||||
const { groupby, timeseries_limit_metric, x_axis_sort } = formData;
|
const { groupby, timeseries_limit_metric, x_axis_sort, metrics } = formData;
|
||||||
const extra_metrics: QueryFormMetric[] = [];
|
const extra_metrics: QueryFormMetric[] = [];
|
||||||
if (
|
if (
|
||||||
!(groupby || []).length &&
|
!(groupby || []).length &&
|
||||||
timeseries_limit_metric &&
|
timeseries_limit_metric &&
|
||||||
getMetricLabel(timeseries_limit_metric) === x_axis_sort
|
getMetricLabel(timeseries_limit_metric) === x_axis_sort &&
|
||||||
|
!metrics?.some(metric => getMetricLabel(metric) === x_axis_sort)
|
||||||
) {
|
) {
|
||||||
extra_metrics.push(timeseries_limit_metric);
|
extra_metrics.push(timeseries_limit_metric);
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,7 @@ export const xAxisSortControl = {
|
|||||||
...ensureIsArray(controls?.metrics?.value as QueryFormMetric),
|
...ensureIsArray(controls?.metrics?.value as QueryFormMetric),
|
||||||
controls?.timeseries_limit_metric?.value as QueryFormMetric,
|
controls?.timeseries_limit_metric?.value as QueryFormMetric,
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
|
const metricLabels = [...new Set(metrics.map(getMetricLabel))];
|
||||||
const options = [
|
const options = [
|
||||||
...columns.map(column => {
|
...columns.map(column => {
|
||||||
const value = getColumnLabel(column);
|
const value = getColumnLabel(column);
|
||||||
@ -87,13 +88,10 @@ export const xAxisSortControl = {
|
|||||||
label: dataset?.verbose_map?.[value] || value,
|
label: dataset?.verbose_map?.[value] || value,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
...metrics.map(metric => {
|
...metricLabels.map(value => ({
|
||||||
const value = getMetricLabel(metric);
|
value,
|
||||||
return {
|
label: dataset?.verbose_map?.[value] || value,
|
||||||
value,
|
})),
|
||||||
label: dataset?.verbose_map?.[value] || value,
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const shouldReset = !(
|
const shouldReset = !(
|
||||||
|
@ -92,3 +92,35 @@ test('returns empty array if groupby populated', () => {
|
|||||||
}),
|
}),
|
||||||
).toEqual([]);
|
).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('returns empty array if timeseries_limit_metric and x_axis_sort are included in main metrics array', () => {
|
||||||
|
expect(
|
||||||
|
extractExtraMetrics({
|
||||||
|
...baseFormData,
|
||||||
|
timeseries_limit_metric: 'a',
|
||||||
|
x_axis_sort: 'a',
|
||||||
|
}),
|
||||||
|
).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns empty array if timeseries_limit_metric and x_axis_sort are included in main metrics array with adhoc metrics', () => {
|
||||||
|
expect(
|
||||||
|
extractExtraMetrics({
|
||||||
|
...baseFormData,
|
||||||
|
metrics: [
|
||||||
|
'a',
|
||||||
|
{
|
||||||
|
expressionType: 'SIMPLE',
|
||||||
|
aggregate: 'SUM',
|
||||||
|
column: { column_name: 'num' },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
timeseries_limit_metric: {
|
||||||
|
expressionType: 'SIMPLE',
|
||||||
|
aggregate: 'SUM',
|
||||||
|
column: { column_name: 'num' },
|
||||||
|
},
|
||||||
|
x_axis_sort: 'SUM(num)',
|
||||||
|
}),
|
||||||
|
).toEqual([]);
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user