From a0b86727ca9116598a1b95a19d666a6c188e2c44 Mon Sep 17 00:00:00 2001 From: Dinika Saxena Date: Wed, 21 Feb 2024 18:04:05 +0100 Subject: [PATCH] Studio // Dont override column config when one aleady exists Signed-off-by: Dinika Saxena --- src/shared/components/EditTableForm.tsx | 58 ++++++++++++++-------- src/shared/hooks/useAccessDataForTable.tsx | 1 + 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/shared/components/EditTableForm.tsx b/src/shared/components/EditTableForm.tsx index 893dfecc2..e3126f0cb 100644 --- a/src/shared/components/EditTableForm.tsx +++ b/src/shared/components/EditTableForm.tsx @@ -274,14 +274,18 @@ const EditTableForm: React.FC<{ return Object.assign(result, current); }, {}); - return Object.keys(mergedItem).map(title => ({ - '@type': '', - name: title, - format: '', - enableSearch: false, - enableSort: false, - enableFilter: false, - })); + return Object.keys(mergedItem).map(title => { + const currentItemConfig = findCurrentColumnConfig(title); + return { + '@type': '', + name: title, + format: '', + enableSearch: false, + enableSort: false, + enableFilter: false, + ...currentItemConfig, + }; + }); } const result = await querySparql( @@ -296,14 +300,19 @@ const EditTableForm: React.FC<{ .sort((a, b) => { return a.title > b.title ? 1 : -1; }) - .map(x => ({ - '@type': 'text', - name: x.dataIndex, - format: '', - enableSearch: false, - enableSort: false, - enableFilter: false, - })); + .map(header => { + const currentHeaderConfig = + findCurrentColumnConfig(header.dataIndex) ?? {}; + return { + '@type': 'text', + name: header.dataIndex, + format: '', + enableSearch: false, + enableSort: false, + enableFilter: false, + ...currentHeaderConfig, + }; + }); }) .catch(error => { // Sometimes delta's error message can be in `name` or `reason` field. @@ -323,12 +332,7 @@ const EditTableForm: React.FC<{ { onSuccess: data => { updateTableDataError(null); - if ( - isNil(configuration) || - (configuration as TableColumn[]).length === 0 - ) { - setConfiguration(data); - } + setConfiguration(data); }, onError: (error: Error) => { updateTableDataError(error); @@ -340,6 +344,16 @@ const EditTableForm: React.FC<{ } ); + const findCurrentColumnConfig = (name: string) => { + if (Array.isArray(configuration)) { + return configuration.find(column => column.name === name); + } + if (configuration?.name === name) { + return { ...configuration }; + } + return undefined; + }; + const onChangeName = (event: any) => { setName(event.target.value); setNameError(false); diff --git a/src/shared/hooks/useAccessDataForTable.tsx b/src/shared/hooks/useAccessDataForTable.tsx index 0a68ece7d..667b1f90c 100644 --- a/src/shared/hooks/useAccessDataForTable.tsx +++ b/src/shared/hooks/useAccessDataForTable.tsx @@ -633,6 +633,7 @@ export const useAccessDataForTable = ( ); return result; } + return {}; }, {