From 3f1d22ea0e48aa0809461171da2f340c2417382a Mon Sep 17 00:00:00 2001 From: Pedro Lamas Date: Fri, 16 Aug 2024 07:52:50 +0100 Subject: [PATCH] fix: null check cards on layout init (#1484) Signed-off-by: Pedro Lamas --- src/store/layout/mutations.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/store/layout/mutations.ts b/src/store/layout/mutations.ts index a81fb4553f..4f5491f7b2 100644 --- a/src/store/layout/mutations.ts +++ b/src/store/layout/mutations.ts @@ -32,13 +32,17 @@ export const mutations: MutationTree = { // migrate existing layouts const migratableLayoutKeys = ['dashboard'] - for (const layoutKey of Object.keys(payload.layouts)) { + for (const [layoutKey, currentLayout] of Object.entries(payload.layouts)) { + for (const [containerKey, components] of Object.entries(currentLayout)) { + currentLayout[containerKey] = components + .filter(card => card != null) + } + const migratableLayoutKey = migratableLayoutKeys.find(key => layoutKey.startsWith(key)) if (migratableLayoutKey) { const defaultLayout = defaultState.layouts[migratableLayoutKey] const defaultComponentIds = Object.values(defaultLayout).flat().map(card => card.id) - const currentLayout = payload.layouts[layoutKey] const currentComponentIds = Object.values(currentLayout).flat().map(card => card.id) for (const [containerKey, defaultContainerComponents] of Object.entries(defaultLayout)) { @@ -53,7 +57,7 @@ export const mutations: MutationTree = { // diagnostics specific layout updates if (layoutKey.startsWith('diagnostics')) { - const diagnostics = payload.layouts[layoutKey] as DiagnosticsCardContainer + const diagnostics = currentLayout as DiagnosticsCardContainer for (const diagnosticsCardConfigs of Object.values(diagnostics)) { for (const diagnosticsCardConfig of diagnosticsCardConfigs) {