mirror of https://github.com/apache/superset.git
fix: Chart crashing if timeseries_limit_metric is an empty array (#23480)
This commit is contained in:
parent
8c374f391d
commit
4530542ac4
|
@ -17,6 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
import {
|
||||
ensureIsArray,
|
||||
getMetricLabel,
|
||||
QueryFormData,
|
||||
QueryFormMetric,
|
||||
|
@ -27,13 +28,14 @@ export function extractExtraMetrics(
|
|||
): QueryFormMetric[] {
|
||||
const { groupby, timeseries_limit_metric, x_axis_sort, metrics } = formData;
|
||||
const extra_metrics: QueryFormMetric[] = [];
|
||||
const limitMetric = ensureIsArray(timeseries_limit_metric)[0];
|
||||
if (
|
||||
!(groupby || []).length &&
|
||||
timeseries_limit_metric &&
|
||||
getMetricLabel(timeseries_limit_metric) === x_axis_sort &&
|
||||
limitMetric &&
|
||||
getMetricLabel(limitMetric) === x_axis_sort &&
|
||||
!metrics?.some(metric => getMetricLabel(metric) === x_axis_sort)
|
||||
) {
|
||||
extra_metrics.push(timeseries_limit_metric);
|
||||
extra_metrics.push(limitMetric);
|
||||
}
|
||||
return extra_metrics;
|
||||
}
|
||||
|
|
|
@ -124,3 +124,13 @@ test('returns empty array if timeseries_limit_metric and x_axis_sort are include
|
|||
}),
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
test('returns emoty array if timeseries_limit_metric is an empty array', () => {
|
||||
expect(
|
||||
extractExtraMetrics({
|
||||
...baseFormData,
|
||||
// @ts-ignore
|
||||
timeseries_limit_metric: [],
|
||||
}),
|
||||
).toEqual([]);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue