From 40a64a05d56c7516eaf09aa6389c62b30d777719 Mon Sep 17 00:00:00 2001 From: Faton Ramadani Date: Fri, 12 Apr 2024 16:16:43 +0200 Subject: [PATCH] fix(frontend): Correctly handle undefined actions --- .../apps/components/display/table/AppAggridTable.svelte | 2 +- frontend/src/lib/components/apps/editor/SettingsPanel.svelte | 4 ++-- frontend/src/lib/components/apps/editor/appUtils.ts | 5 ++++- .../inlineScriptsPanel/InlineScriptsPanelWithTable.svelte | 4 ++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/frontend/src/lib/components/apps/components/display/table/AppAggridTable.svelte b/frontend/src/lib/components/apps/components/display/table/AppAggridTable.svelte index 5831dccdd5..aa42fd5283 100644 --- a/frontend/src/lib/components/apps/components/display/table/AppAggridTable.svelte +++ b/frontend/src/lib/components/apps/components/display/table/AppAggridTable.svelte @@ -198,7 +198,7 @@ function actionRenderer(params) { const { rowIndex, data: row } = params - if (rowIndex === -1 || actions == undefined || actions.length == 0) { + if (rowIndex === -1 || actions == undefined || actions?.length == 0) { return null } diff --git a/frontend/src/lib/components/apps/editor/SettingsPanel.svelte b/frontend/src/lib/components/apps/editor/SettingsPanel.svelte index ee04cda5c8..d87f93c74d 100644 --- a/frontend/src/lib/components/apps/editor/SettingsPanel.svelte +++ b/frontend/src/lib/components/apps/editor/SettingsPanel.svelte @@ -90,8 +90,8 @@ } if ( - parent.data.type === 'aggridcomponent' || - (parent.data.type === 'aggridcomponentee' && Array.isArray(parent.data.actions)) + (parent.data.type === 'aggridcomponent' || parent.data.type === 'aggridcomponentee') && + Array.isArray(parent.data.actions) ) { parent.data.actions = parent.data.actions.filter( (x) => x.id !== tableActionSettings?.item.id diff --git a/frontend/src/lib/components/apps/editor/appUtils.ts b/frontend/src/lib/components/apps/editor/appUtils.ts index 4550569b74..b79fd4df13 100644 --- a/frontend/src/lib/components/apps/editor/appUtils.ts +++ b/frontend/src/lib/components/apps/editor/appUtils.ts @@ -517,7 +517,10 @@ export function getAllGridItems(app: App): GridItem[] { .map((x) => { if (x?.data?.type === 'tablecomponent') { return [x, ...x?.data?.actionButtons?.map((x) => ({ data: x, id: x.id }))] - } else if (x?.data?.type === 'aggridcomponent' || x?.data?.type === 'aggridcomponentee') { + } else if ( + (x?.data?.type === 'aggridcomponent' || x?.data?.type === 'aggridcomponentee') && + Array.isArray(x?.data?.actions) + ) { return [x, ...x?.data?.actions?.map((x) => ({ data: x, id: x.id }))] } else if (x?.data?.type === 'menucomponent') { return [x, ...x?.data?.menuItems?.map((x) => ({ data: x, id: x.id }))] diff --git a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanelWithTable.svelte b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanelWithTable.svelte index fa8b626e51..c305a0c776 100644 --- a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanelWithTable.svelte +++ b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanelWithTable.svelte @@ -34,8 +34,8 @@ {/each} {/if} -{#if gridItem?.data?.type === 'aggridcomponent' || (gridItem?.data?.type === 'aggridcomponentee' && Array.isArray(gridItem.data.actions))} - {#each gridItem.data.actions ?? [] as actionButton, index (index)} +{#if (gridItem?.data?.type === 'aggridcomponent' || gridItem?.data?.type === 'aggridcomponentee') && Array.isArray(gridItem.data.actions)} + {#each gridItem.data.actions as actionButton, index (index)} {#if actionButton?.id === $selectedComponentInEditor || actionButton?.id + '_transformer' === $selectedComponentInEditor}