mirror of https://github.com/apache/superset.git
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(
|
||||
formData: QueryFormData,
|
||||
): QueryFormMetric[] {
|
||||
const { groupby, timeseries_limit_metric, x_axis_sort } = formData;
|
||||
const { groupby, timeseries_limit_metric, x_axis_sort, metrics } = formData;
|
||||
const extra_metrics: QueryFormMetric[] = [];
|
||||
if (
|
||||
!(groupby || []).length &&
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -79,6 +79,7 @@ export const xAxisSortControl = {
|
|||
...ensureIsArray(controls?.metrics?.value as QueryFormMetric),
|
||||
controls?.timeseries_limit_metric?.value as QueryFormMetric,
|
||||
].filter(Boolean);
|
||||
const metricLabels = [...new Set(metrics.map(getMetricLabel))];
|
||||
const options = [
|
||||
...columns.map(column => {
|
||||
const value = getColumnLabel(column);
|
||||
|
@ -87,13 +88,10 @@ export const xAxisSortControl = {
|
|||
label: dataset?.verbose_map?.[value] || value,
|
||||
};
|
||||
}),
|
||||
...metrics.map(metric => {
|
||||
const value = getMetricLabel(metric);
|
||||
return {
|
||||
value,
|
||||
label: dataset?.verbose_map?.[value] || value,
|
||||
};
|
||||
}),
|
||||
...metricLabels.map(value => ({
|
||||
value,
|
||||
label: dataset?.verbose_map?.[value] || value,
|
||||
})),
|
||||
];
|
||||
|
||||
const shouldReset = !(
|
||||
|
|
|
@ -92,3 +92,35 @@ test('returns empty array if groupby populated', () => {
|
|||
}),
|
||||
).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