mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* Performance: Standardize lodash imports to use destructured members Changes lodash imports of the form `import x from 'lodash/x'` to `import { x } from 'lodash'` to reduce bundle size. * Remove unnecessary _ import from Graph component * Enforce lodash import style * Fix remaining lodash imports
28 lines
761 B
TypeScript
28 lines
761 B
TypeScript
import { concat, every, find, groupBy, head, map, partition } 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';
|
|
}
|