grafana/public/app/features/annotations/events_processing.ts

28 lines
718 B
TypeScript
Raw Normal View History

2017-12-20 05:33:33 -06:00
import _ from 'lodash';
export function dedupAnnotations(annotations: any) {
let dedup = [];
2018-04-13 12:48:37 -05:00
// Split events by annotationId property existence
const events = _.partition(annotations, 'id');
const eventsById = _.groupBy(events[0], 'id');
dedup = _.map(eventsById, eventGroup => {
if (eventGroup.length > 1 && !_.every(eventGroup, isPanelAlert)) {
// Get first non-panel alert
return _.find(eventGroup, event => {
2017-12-20 05:33:33 -06:00
return event.eventType !== 'panel-alert';
});
} else {
return _.head(eventGroup);
}
});
dedup = _.concat(dedup, events[1]);
return dedup;
}
function isPanelAlert(event: { eventType: string }) {
2017-12-20 05:33:33 -06:00
return event.eventType === 'panel-alert';
}