2017-12-20 05:33:33 -06:00
|
|
|
import _ 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
|
2018-08-26 10:14:40 -05:00
|
|
|
const events = _.partition(annotations, 'id');
|
2017-10-23 08:46:36 -05:00
|
|
|
|
2018-08-26 10:14:40 -05:00
|
|
|
const eventsById = _.groupBy(events[0], 'id');
|
2017-10-23 08:46:36 -05:00
|
|
|
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';
|
2017-10-23 08:46:36 -05:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return _.head(eventGroup);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
dedup = _.concat(dedup, events[1]);
|
|
|
|
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
|
|
|
}
|