2021-04-21 08:38:00 +01:00
|
|
|
import { concat, every, find, groupBy, head, map, partition } 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
|
2021-04-21 08:38:00 +01:00
|
|
|
const events = partition(annotations, 'id');
|
2017-10-23 16:46:36 +03:00
|
|
|
|
2021-04-21 08:38:00 +01:00
|
|
|
const eventsById = groupBy(events[0], 'id');
|
|
|
|
|
dedup = map(eventsById, (eventGroup) => {
|
|
|
|
|
if (eventGroup.length > 1 && !every(eventGroup, isPanelAlert)) {
|
2017-10-23 16:46:36 +03:00
|
|
|
// Get first non-panel alert
|
2021-04-21 08:38:00 +01:00
|
|
|
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 {
|
2021-04-21 08:38:00 +01:00
|
|
|
return head(eventGroup);
|
2017-10-23 16:46:36 +03:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2021-04-21 08:38:00 +01:00
|
|
|
dedup = concat(dedup, events[1]);
|
2017-10-23 16:46:36 +03:00
|
|
|
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
|
|
|
}
|