Skip to content

Commit a6dcdcb

Browse files
committed
fix: filter incidents by max severities over time
Incidents were filtered based on individual alert severities rather than their overall incident severity. The filter now correctly shows incidents if any of the selected severities was ever the maximum/dominant severity at any point in time. For example, an incident that transitions from Warning to Critical over time will now appear when either "Warning" or "Critical" filters are selected, matching the multi-colored timeline visualization. Added getIncidentMaximumSeveritiesOverTime() function to determine all severities that were maximum at different time periods, ensuring filter behavior aligns with the incident's rendered colors.
1 parent fba8b08 commit a6dcdcb

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

web/src/components/Incidents/utils.ts

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,44 @@ export function generateDateArray(days: number): Array<number> {
314314
* const filteredIncidents = filterIncident(filters, incidents);
315315
* ```
316316
*/
317+
/**
318+
* Determines all maximum severities that an incident has had over time.
319+
* This looks at each time period and finds what was the maximum severity at that time,
320+
* then returns all unique maximum severities that occurred.
321+
*
322+
* @param incident - The incident to evaluate
323+
* @returns Array of severity strings that were maximum severities at some point in time
324+
*/
325+
function getIncidentMaximumSeveritiesOverTime(incident: Incident): string[] {
326+
const severityRank = { '2': 2, '1': 1, '0': 0 };
327+
const getSeverityName = (value: string) => {
328+
return value === '2' ? 'Critical' : value === '1' ? 'Warning' : 'Informative';
329+
};
330+
331+
// Group values by timestamp to find maximum severity at each point in time
332+
const timestampSeverities: Record<string, string> = {};
333+
334+
incident.values.forEach(([timestamp, severity]) => {
335+
const timestampStr = timestamp.toString();
336+
if (
337+
!timestampSeverities[timestampStr] ||
338+
severityRank[severity] > severityRank[timestampSeverities[timestampStr]]
339+
) {
340+
timestampSeverities[timestampStr] = severity;
341+
}
342+
});
343+
344+
// Get unique maximum severities that occurred over time
345+
const maxSeverities = new Set<string>();
346+
Object.values(timestampSeverities).forEach((severity) => {
347+
maxSeverities.add(getSeverityName(severity));
348+
});
349+
350+
return Array.from(maxSeverities);
351+
}
352+
317353
export function filterIncident(filters: IncidentFiltersCombined, incidents: Array<Incident>) {
318-
const conditions = {
319-
Critical: 'critical',
320-
Warning: 'warning',
321-
Informative: 'informative',
354+
const stateConditions = {
322355
Firing: 'firing',
323356
Resolved: 'resolved',
324357
};
@@ -328,14 +361,17 @@ export function filterIncident(filters: IncidentFiltersCombined, incidents: Arra
328361
return true;
329362
}
330363

364+
// Filter by maximum severities that occurred at any point in time
331365
const isSeverityMatch =
332366
filters.severity.length > 0
333-
? filters.severity.some((filter) => incident[conditions[filter]] === true)
367+
? filters.severity.some((selectedSeverity) =>
368+
getIncidentMaximumSeveritiesOverTime(incident).includes(selectedSeverity),
369+
)
334370
: true; // True if no severity filters
335371

336372
const isStateMatch =
337373
filters.state.length > 0
338-
? filters.state.some((filter) => incident[conditions[filter]] === true)
374+
? filters.state.some((filter) => incident[stateConditions[filter]] === true)
339375
: true; // True if no state filters
340376

341377
const isIncidentIdMatch =

0 commit comments

Comments
 (0)