2017-12-20 12:33:33 +01:00
|
|
|
import _ from 'lodash';
|
2017-10-23 16:46:36 +03:00
|
|
|
|
2019-08-01 14:38:34 +02:00
|
|
|
export function dedupAnnotations(annotations: any) {
|
2017-10-23 16:46:36 +03:00
|
|
|
let dedup = [];
|
|
|
|
|
|
2018-04-13 19:48:37 +02:00
|
|
|
// Split events by annotationId property existence
|
2018-08-26 17:14:40 +02:00
|
|
|
const events = _.partition(annotations, 'id');
|
2017-10-23 16:46:36 +03:00
|
|
|
|
2018-08-26 17:14:40 +02:00
|
|
|
const eventsById = _.groupBy(events[0], 'id');
|
2017-10-23 16:46:36 +03:00
|
|
|
dedup = _.map(eventsById, eventGroup => {
|
|
|
|
|
if (eventGroup.length > 1 && !_.every(eventGroup, isPanelAlert)) {
|
|
|
|
|
// Get first non-panel alert
|
|
|
|
|
return _.find(eventGroup, event => {
|
2017-12-20 12:33:33 +01:00
|
|
|
return event.eventType !== 'panel-alert';
|
2017-10-23 16:46:36 +03:00
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
return _.head(eventGroup);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
dedup = _.concat(dedup, events[1]);
|
|
|
|
|
return dedup;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-01 14:38:34 +02:00
|
|
|
function isPanelAlert(event: { eventType: string }) {
|
2017-12-20 12:33:33 +01:00
|
|
|
return event.eventType === 'panel-alert';
|
2017-10-23 16:46:36 +03:00
|
|
|
}
|