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