From 6e87e089ac64c412491fe67ca743b7857e565f6a Mon Sep 17 00:00:00 2001 From: Faton Ramadani Date: Fri, 12 Apr 2024 16:08:51 +0200 Subject: [PATCH] fix(frontend): Correctly handle undefined actions --- .../apps/components/display/table/AppAggridTable.svelte | 8 ++++---- frontend/src/lib/components/apps/editor/AppInputs.svelte | 8 +++++--- .../src/lib/components/apps/editor/SettingsPanel.svelte | 5 ++++- frontend/src/lib/components/apps/editor/appUtils.ts | 2 +- .../lib/components/apps/editor/component/Component.svelte | 4 ++-- .../inlineScriptsPanel/InlineScriptsPanelWithTable.svelte | 2 +- frontend/src/lib/components/apps/utils.ts | 2 +- 7 files changed, 18 insertions(+), 13 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 028db8577d..5831dccdd5 100644 --- a/frontend/src/lib/components/apps/components/display/table/AppAggridTable.svelte +++ b/frontend/src/lib/components/apps/components/display/table/AppAggridTable.svelte @@ -36,7 +36,7 @@ export let initializing: boolean | undefined = undefined export let render: boolean export let customCss: ComponentCustomCSS<'aggridcomponent'> | undefined = undefined - export let actions: TableAction[] = [] + export let actions: TableAction[] | undefined = undefined const context = getContext('AppViewerContext') @@ -198,7 +198,7 @@ function actionRenderer(params) { const { rowIndex, data: row } = params - if (rowIndex === -1) { + if (rowIndex === -1 || actions == undefined || actions.length == 0) { return null } @@ -261,7 +261,7 @@ : [] // Add the action column if actions are defined - if (actions.length > 0) { + if (actions && actions.length > 0) { columnDefs.push({ headerName: 'Actions', cellRenderer: actionRenderer, @@ -385,7 +385,7 @@ : [] // Add the action column if actions are defined - if (actions.length > 0) { + if (actions && actions.length > 0) { columnDefs.push({ headerName: 'Actions', cellRenderer: actionRenderer, diff --git a/frontend/src/lib/components/apps/editor/AppInputs.svelte b/frontend/src/lib/components/apps/editor/AppInputs.svelte index 58d4aab692..6f78090318 100644 --- a/frontend/src/lib/components/apps/editor/AppInputs.svelte +++ b/frontend/src/lib/components/apps/editor/AppInputs.svelte @@ -33,9 +33,11 @@
- {#each gridItem.data.actions as actionButton (actionButton.id)} - - {/each} + {#if Array.isArray(gridItem.data.actions)} + {#each gridItem.data.actions as actionButton (actionButton.id)} + + {/each} + {/if}
{:else} diff --git a/frontend/src/lib/components/apps/editor/SettingsPanel.svelte b/frontend/src/lib/components/apps/editor/SettingsPanel.svelte index 65b79ad007..ee04cda5c8 100644 --- a/frontend/src/lib/components/apps/editor/SettingsPanel.svelte +++ b/frontend/src/lib/components/apps/editor/SettingsPanel.svelte @@ -89,7 +89,10 @@ ) } - if (parent.data.type === 'aggridcomponent' || parent.data.type === 'aggridcomponentee') { + if ( + 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 d38a30269e..48304b06cc 100644 --- a/frontend/src/lib/components/apps/editor/appUtils.ts +++ b/frontend/src/lib/components/apps/editor/appUtils.ts @@ -74,7 +74,7 @@ export function dfs( return [item.id, id] } else if ( (item.data.type == 'aggridcomponent' || item.data.type == 'aggridcomponentee') && - item.data.actions.find((x) => id == x.id) + item.data.actions?.find((x) => id == x.id) ) { return [item.id, id] } else { diff --git a/frontend/src/lib/components/apps/editor/component/Component.svelte b/frontend/src/lib/components/apps/editor/component/Component.svelte index 48ac8cae2c..9e9aca33f9 100644 --- a/frontend/src/lib/components/apps/editor/component/Component.svelte +++ b/frontend/src/lib/components/apps/editor/component/Component.svelte @@ -351,7 +351,7 @@ bind:initializing componentInput={component.componentInput} customCss={component.customCss} - actions={component.actions} + actions={component.actions ?? []} {render} /> {:else if component.type === 'aggridcomponentee'} @@ -362,7 +362,7 @@ bind:initializing componentInput={component.componentInput} customCss={component.customCss} - actions={component.actions} + actions={component.actions ?? []} {render} /> {:else if component.type === 'textcomponent'} diff --git a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanelWithTable.svelte b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanelWithTable.svelte index 71bcf040fa..65111cf03a 100644 --- a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanelWithTable.svelte +++ b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanelWithTable.svelte @@ -34,7 +34,7 @@ {/each} {/if} -{#if gridItem?.data?.type === 'aggridcomponent' || gridItem?.data?.type === 'aggridcomponentee'} +{#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} { + gridItem.data.actions?.forEach((actionButton) => { if (actionButton.componentInput?.type === 'runnable') { if (actionButton.componentInput.runnable?.type === 'runnableByName') { acc.push(actionButton.componentInput.runnable.name)