From 3f71eab044b889bbeea1f4a26542988bb5938b55 Mon Sep 17 00:00:00 2001 From: Gavin Reynolds Date: Thu, 18 Jul 2024 16:20:53 +0100 Subject: [PATCH] Guard against computed or alert column state being undefined Signed-off-by: Gavin Reynolds --- src/components/ColumnsModal/ColumnsModalComponent.jsx | 4 ++-- src/config/column-generator.jsx | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/ColumnsModal/ColumnsModalComponent.jsx b/src/components/ColumnsModal/ColumnsModalComponent.jsx index eddc2ccd..51aa156b 100644 --- a/src/components/ColumnsModal/ColumnsModalComponent.jsx +++ b/src/components/ColumnsModal/ColumnsModalComponent.jsx @@ -62,8 +62,8 @@ import DraggableColumnsModalItem from './subcomponents/DraggableColumnsModalItem const TableColumnsModalComponent = () => { const displayColumnsModal = useSelector((state) => state.settings.displayColumnsModal); - const alertCustomDetailFields = useSelector((state) => state.settings.alertCustomDetailFields); - const computedFields = useSelector((state) => state.settings.computedFields); + const alertCustomDetailFields = useSelector((state) => state.settings.alertCustomDetailFields) || []; + const computedFields = useSelector((state) => state.settings.computedFields) || []; const incidentTableColumns = useSelector((state) => state.incidentTable.incidentTableColumns); const { incidentTableState, diff --git a/src/config/column-generator.jsx b/src/config/column-generator.jsx index 3d334328..76e76328 100644 --- a/src/config/column-generator.jsx +++ b/src/config/column-generator.jsx @@ -908,6 +908,9 @@ export const customAlertColumns = (savedColumns) => { export const customComputedColumns = (savedColumns) => { const allColumns = defaultColumns(); + if (!savedColumns) { + return []; + } return savedColumns.map((column) => { if ( column.columnType === 'computed' @@ -921,6 +924,9 @@ export const customComputedColumns = (savedColumns) => { export const columnsForSavedColumns = (savedColumns) => { const allColumns = defaultColumns(); + if (!savedColumns) { + return []; + } const columns = savedColumns .map((column) => { const foundColumn = allColumns.find((c) => c.originalHeader === column.Header);