-
Notifications
You must be signed in to change notification settings - Fork 782
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: searchable columns + nested (#2225)
- Loading branch information
Showing
4 changed files
with
165 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,125 @@ | ||
import { AlertTable } from "./alert-table"; | ||
import { useAlertTableCols } from "./alert-table-utils"; | ||
import { AlertDto, AlertKnownKeys, Preset, getTabsFromPreset } from "./models"; | ||
import { AlertTable } from "./alert-table"; | ||
import { useAlertTableCols } from "./alert-table-utils"; | ||
import { AlertDto, AlertKnownKeys, Preset, getTabsFromPreset } from "./models"; | ||
|
||
const getPresetAlerts = (alert: AlertDto, presetName: string): boolean => { | ||
if (presetName === "deleted") { | ||
return alert.deleted === true; | ||
} | ||
const getPresetAlerts = (alert: AlertDto, presetName: string): boolean => { | ||
if (presetName === "deleted") { | ||
return alert.deleted === true; | ||
} | ||
|
||
if (presetName === "groups") { | ||
return alert.group === true; | ||
} | ||
if (presetName === "groups") { | ||
return alert.group === true; | ||
} | ||
|
||
if (presetName === "feed") { | ||
return alert.deleted === false && alert.dismissed === false; | ||
} | ||
if (presetName === "feed") { | ||
return alert.deleted === false && alert.dismissed === false; | ||
} | ||
|
||
if (presetName === "dismissed") { | ||
return alert.dismissed === true; | ||
} | ||
if (presetName === "dismissed") { | ||
return alert.dismissed === true; | ||
} | ||
|
||
if (presetName === "without-incident") { | ||
return alert.incident === null; | ||
} | ||
if (presetName === "without-incident") { | ||
return alert.incident === null; | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
return true; | ||
}; | ||
interface Props { | ||
alerts: AlertDto[]; | ||
preset: Preset; | ||
isAsyncLoading: boolean; | ||
setTicketModalAlert: (alert: AlertDto | null) => void; | ||
setNoteModalAlert: (alert: AlertDto | null) => void; | ||
setRunWorkflowModalAlert: (alert: AlertDto | null) => void; | ||
setDismissModalAlert: (alert: AlertDto[] | null) => void; | ||
setChangeStatusAlert: (alert: AlertDto | null) => void; | ||
mutateAlerts: () => void; | ||
} | ||
|
||
interface Props { | ||
alerts: AlertDto[]; | ||
preset: Preset; | ||
isAsyncLoading: boolean; | ||
setTicketModalAlert: (alert: AlertDto | null) => void; | ||
setNoteModalAlert: (alert: AlertDto | null) => void; | ||
setRunWorkflowModalAlert: (alert: AlertDto | null) => void; | ||
setDismissModalAlert: (alert: AlertDto[] | null) => void; | ||
setChangeStatusAlert: (alert: AlertDto | null) => void; | ||
mutateAlerts: () => void; | ||
} | ||
export default function AlertTableTabPanel({ | ||
alerts, | ||
preset, | ||
isAsyncLoading, | ||
setTicketModalAlert, | ||
setNoteModalAlert, | ||
setRunWorkflowModalAlert, | ||
setDismissModalAlert, | ||
setChangeStatusAlert, | ||
mutateAlerts, | ||
}: Props) { | ||
const sortedPresetAlerts = alerts | ||
.filter((alert) => getPresetAlerts(alert, preset.name)) | ||
.sort((a, b) => { | ||
// Shahar: we want noise alert first. If no noisy (most of the cases) we want the most recent first. | ||
const noisyA = a.isNoisy && a.status == "firing" ? 1 : 0; | ||
const noisyB = b.isNoisy && b.status == "firing" ? 1 : 0; | ||
|
||
export default function AlertTableTabPanel({ | ||
alerts, | ||
preset, | ||
isAsyncLoading, | ||
setTicketModalAlert, | ||
setNoteModalAlert, | ||
setRunWorkflowModalAlert, | ||
setDismissModalAlert, | ||
setChangeStatusAlert, | ||
mutateAlerts | ||
}: Props) { | ||
const sortedPresetAlerts = alerts | ||
.filter((alert) => getPresetAlerts(alert, preset.name)) | ||
.sort((a, b) => { | ||
// Shahar: we want noise alert first. If no noisy (most of the cases) we want the most recent first. | ||
const noisyA = (a.isNoisy && a.status == "firing") ? 1 : 0; | ||
const noisyB = (b.isNoisy && b.status == "firing") ? 1 : 0; | ||
// Primary sort based on noisy flag (true first) | ||
if (noisyA !== noisyB) { | ||
return noisyB - noisyA; | ||
} | ||
|
||
// Primary sort based on noisy flag (true first) | ||
if (noisyA !== noisyB) { | ||
return noisyB - noisyA; | ||
} | ||
|
||
// Secondary sort based on time (most recent first) | ||
return b.lastReceived.getTime() - a.lastReceived.getTime(); | ||
// Secondary sort based on time (most recent first) | ||
return b.lastReceived.getTime() - a.lastReceived.getTime(); | ||
}); | ||
|
||
const additionalColsToGenerate = [ | ||
...new Set( | ||
alerts | ||
.flatMap((alert) => Object.keys(alert)) | ||
.filter((key) => AlertKnownKeys.includes(key) === false) | ||
), | ||
]; | ||
const additionalColsToGenerate = [ | ||
...new Set( | ||
alerts.flatMap((alert) => { | ||
const keys = Object.keys(alert).filter( | ||
(key) => !AlertKnownKeys.includes(key) | ||
); | ||
return keys.flatMap((key) => { | ||
if ( | ||
typeof alert[key as keyof AlertDto] === "object" && | ||
alert[key as keyof AlertDto] !== null | ||
) { | ||
return Object.keys(alert[key as keyof AlertDto] as object).map( | ||
(subKey) => `${key}.${subKey}` | ||
); | ||
} | ||
return key; | ||
}); | ||
}) | ||
), | ||
]; | ||
|
||
const alertTableColumns = useAlertTableCols({ | ||
additionalColsToGenerate: additionalColsToGenerate, | ||
isCheckboxDisplayed: | ||
preset.name !== "deleted" && preset.name !== "dismissed", | ||
isMenuDisplayed: true, | ||
setTicketModalAlert: setTicketModalAlert, | ||
setNoteModalAlert: setNoteModalAlert, | ||
setRunWorkflowModalAlert: setRunWorkflowModalAlert, | ||
setDismissModalAlert: setDismissModalAlert, | ||
setChangeStatusAlert: setChangeStatusAlert, | ||
presetName: preset.name, | ||
presetNoisy: preset.is_noisy, | ||
}); | ||
const alertTableColumns = useAlertTableCols({ | ||
additionalColsToGenerate: additionalColsToGenerate, | ||
isCheckboxDisplayed: | ||
preset.name !== "deleted" && preset.name !== "dismissed", | ||
isMenuDisplayed: true, | ||
setTicketModalAlert: setTicketModalAlert, | ||
setNoteModalAlert: setNoteModalAlert, | ||
setRunWorkflowModalAlert: setRunWorkflowModalAlert, | ||
setDismissModalAlert: setDismissModalAlert, | ||
setChangeStatusAlert: setChangeStatusAlert, | ||
presetName: preset.name, | ||
presetNoisy: preset.is_noisy, | ||
}); | ||
|
||
const presetTabs = getTabsFromPreset(preset); | ||
const presetTabs = getTabsFromPreset(preset); | ||
|
||
return ( | ||
<AlertTable | ||
alerts={sortedPresetAlerts} | ||
columns={alertTableColumns} | ||
setDismissedModalAlert={setDismissModalAlert} | ||
isAsyncLoading={isAsyncLoading} | ||
presetName={preset.name} | ||
presetPrivate={preset.is_private} | ||
presetNoisy={preset.is_noisy} | ||
presetStatic={preset.name === "feed" || preset.name === "groups" || preset.name === "dismissed" || preset.name === "without-incident"} | ||
presetId={preset.id} | ||
presetTabs={presetTabs} | ||
mutateAlerts={mutateAlerts} | ||
/> | ||
); | ||
} | ||
return ( | ||
<AlertTable | ||
alerts={sortedPresetAlerts} | ||
columns={alertTableColumns} | ||
setDismissedModalAlert={setDismissModalAlert} | ||
isAsyncLoading={isAsyncLoading} | ||
presetName={preset.name} | ||
presetPrivate={preset.is_private} | ||
presetNoisy={preset.is_noisy} | ||
presetStatic={ | ||
preset.name === "feed" || | ||
preset.name === "groups" || | ||
preset.name === "dismissed" || | ||
preset.name === "without-incident" | ||
} | ||
presetId={preset.id} | ||
presetTabs={presetTabs} | ||
mutateAlerts={mutateAlerts} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters