Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Chart crashing if timeseries_limit_metric is an empty array #23480

Merged
merged 1 commit into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/
import {
ensureIsArray,
getMetricLabel,
QueryFormData,
QueryFormMetric,
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
});