Commit 7fd7406d authored by Sarah Yasonik's avatar Sarah Yasonik Committed by Phil Hughes

Fix alert creation dropdown menu

parent 80886b6b
...@@ -36,15 +36,26 @@ function removeTimeSeriesNoData(queries) { ...@@ -36,15 +36,26 @@ function removeTimeSeriesNoData(queries) {
// { metricId: 2, ...query2Attrs }] }, // { metricId: 2, ...query2Attrs }] },
// { title: 'new title', y_label: 'MB', queries: [{ metricId: 3, ...query3Attrs }]} // { title: 'new title', y_label: 'MB', queries: [{ metricId: 3, ...query3Attrs }]}
// ] // ]
function groupQueriesByChartInfo(metrics) { export function groupQueriesByChartInfo(metrics) {
const metricsByChart = metrics.reduce((accumulator, metric) => { const metricsByChart = metrics.reduce((accumulator, metric) => {
const { queries, ...chart } = metric; const { queries, ...chart } = metric;
const metricId = chart.id ? chart.id.toString() : null;
const chartKey = `${chart.title}|${chart.y_label}`; const chartKey = `${chart.title}|${chart.y_label}`;
accumulator[chartKey] = accumulator[chartKey] || { ...chart, queries: [] }; accumulator[chartKey] = accumulator[chartKey] || { ...chart, queries: [] };
queries.forEach(queryAttrs => accumulator[chartKey].queries.push({ metricId, ...queryAttrs })); queries.forEach(queryAttrs => {
let metricId;
if (chart.id) {
metricId = chart.id.toString();
} else if (queryAttrs.metric_id) {
metricId = queryAttrs.metric_id.toString();
} else {
metricId = null;
}
accumulator[chartKey].queries.push({ metricId, ...queryAttrs });
});
return accumulator; return accumulator;
}, {}); }, {});
......
import { groupQueriesByChartInfo } from '~/monitoring/stores/utils';
describe('groupQueriesByChartInfo', () => {
let input;
let output;
it('groups metrics with the same chart title and y_axis label', () => {
input = [
{ title: 'title', y_label: 'MB', queries: [{}] },
{ title: 'title', y_label: 'MB', queries: [{}] },
{ title: 'new title', y_label: 'MB', queries: [{}] },
];
output = [
{ title: 'title', y_label: 'MB', queries: [{ metricId: null }, { metricId: null }] },
{ title: 'new title', y_label: 'MB', queries: [{ metricId: null }] },
];
expect(groupQueriesByChartInfo(input)).toEqual(output);
});
// Functionality associated with the /additional_metrics endpoint
it("associates a chart's stringified metric_id with the metric", () => {
input = [{ id: 3, title: 'new title', y_label: 'MB', queries: [{}] }];
output = [{ id: 3, title: 'new title', y_label: 'MB', queries: [{ metricId: '3' }] }];
expect(groupQueriesByChartInfo(input)).toEqual(output);
});
// Functionality associated with the /metrics_dashboard endpoint
it('aliases a stringified metrics_id on the metric to the metricId key', () => {
input = [{ title: 'new title', y_label: 'MB', queries: [{ metric_id: 3 }] }];
output = [{ title: 'new title', y_label: 'MB', queries: [{ metricId: '3', metric_id: 3 }] }];
expect(groupQueriesByChartInfo(input)).toEqual(output);
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment