mirror of
https://github.com/apache/superset.git
synced 2024-09-12 00:29:39 -04:00
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.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
import {
|
import {
|
||||||
|
ensureIsArray,
|
||||||
getMetricLabel,
|
getMetricLabel,
|
||||||
QueryFormData,
|
QueryFormData,
|
||||||
QueryFormMetric,
|
QueryFormMetric,
|
||||||
@ -27,13 +28,14 @@ export function extractExtraMetrics(
|
|||||||
): QueryFormMetric[] {
|
): QueryFormMetric[] {
|
||||||
const { groupby, timeseries_limit_metric, x_axis_sort, metrics } = formData;
|
const { groupby, timeseries_limit_metric, x_axis_sort, metrics } = formData;
|
||||||
const extra_metrics: QueryFormMetric[] = [];
|
const extra_metrics: QueryFormMetric[] = [];
|
||||||
|
const limitMetric = ensureIsArray(timeseries_limit_metric)[0];
|
||||||
if (
|
if (
|
||||||
!(groupby || []).length &&
|
!(groupby || []).length &&
|
||||||
timeseries_limit_metric &&
|
limitMetric &&
|
||||||
getMetricLabel(timeseries_limit_metric) === x_axis_sort &&
|
getMetricLabel(limitMetric) === x_axis_sort &&
|
||||||
!metrics?.some(metric => getMetricLabel(metric) === x_axis_sort)
|
!metrics?.some(metric => getMetricLabel(metric) === x_axis_sort)
|
||||||
) {
|
) {
|
||||||
extra_metrics.push(timeseries_limit_metric);
|
extra_metrics.push(limitMetric);
|
||||||
}
|
}
|
||||||
return extra_metrics;
|
return extra_metrics;
|
||||||
}
|
}
|
||||||
|
@ -124,3 +124,13 @@ test('returns empty array if timeseries_limit_metric and x_axis_sort are include
|
|||||||
}),
|
}),
|
||||||
).toEqual([]);
|
).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
Block a user