Skip to content

Commit

Permalink
fix: Chart crashing if timeseries_limit_metric is an empty array (apa…
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabryje authored Mar 24, 2023
1 parent 8c374f3 commit 4530542
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
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([]);
});

0 comments on commit 4530542

Please sign in to comment.