tripnomics_7.5.5/public/app/features/annotations/events_processing.ts
venbatechnologies@gmail.com 91fce5c4bf Initial commit
2021-07-05 13:49:40 +05:30

28 lines
722 B
TypeScript

import _ from 'lodash';
export function dedupAnnotations(annotations: any) {
let dedup = [];
// 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) => {
return event.eventType !== 'panel-alert';
});
} else {
return _.head(eventGroup);
}
});
dedup = _.concat(dedup, events[1]);
return dedup;
}
function isPanelAlert(event: { eventType: string }) {
return event.eventType === 'panel-alert';
}