Skip to content

Commit

Permalink
Studio // Dont override column config when one aleady exists
Browse files Browse the repository at this point in the history
Signed-off-by: Dinika Saxena <dinikasaxenas@gmail.com>
  • Loading branch information
Dinika authored and danburonline committed Feb 23, 2024
1 parent 28c90d9 commit a0b8672
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
58 changes: 36 additions & 22 deletions src/shared/components/EditTableForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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.
Expand All @@ -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);
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/shared/hooks/useAccessDataForTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ export const useAccessDataForTable = (
);
return result;
}

return {};
},
{
Expand Down

0 comments on commit a0b8672

Please sign in to comment.