Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit fe0d8a2

Browse files
committed
Studio // Dont override column config when one aleady exists
Signed-off-by: Dinika Saxena <dinikasaxenas@gmail.com>
1 parent 5e83b58 commit fe0d8a2

File tree

2 files changed

+37
-22
lines changed

2 files changed

+37
-22
lines changed

src/shared/components/EditTableForm.tsx

+36-22
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,18 @@ const EditTableForm: React.FC<{
274274
return Object.assign(result, current);
275275
}, {});
276276

277-
return Object.keys(mergedItem).map(title => ({
278-
'@type': '',
279-
name: title,
280-
format: '',
281-
enableSearch: false,
282-
enableSort: false,
283-
enableFilter: false,
284-
}));
277+
return Object.keys(mergedItem).map(title => {
278+
const currentItemConfig = findCurrentColumnConfig(title);
279+
return {
280+
'@type': '',
281+
name: title,
282+
format: '',
283+
enableSearch: false,
284+
enableSort: false,
285+
enableFilter: false,
286+
...currentItemConfig,
287+
};
288+
});
285289
}
286290

287291
const result = await querySparql(
@@ -296,14 +300,19 @@ const EditTableForm: React.FC<{
296300
.sort((a, b) => {
297301
return a.title > b.title ? 1 : -1;
298302
})
299-
.map(x => ({
300-
'@type': 'text',
301-
name: x.dataIndex,
302-
format: '',
303-
enableSearch: false,
304-
enableSort: false,
305-
enableFilter: false,
306-
}));
303+
.map(header => {
304+
const currentHeaderConfig =
305+
findCurrentColumnConfig(header.dataIndex) ?? {};
306+
return {
307+
'@type': 'text',
308+
name: header.dataIndex,
309+
format: '',
310+
enableSearch: false,
311+
enableSort: false,
312+
enableFilter: false,
313+
...currentHeaderConfig,
314+
};
315+
});
307316
})
308317
.catch(error => {
309318
// Sometimes delta's error message can be in `name` or `reason` field.
@@ -323,12 +332,7 @@ const EditTableForm: React.FC<{
323332
{
324333
onSuccess: data => {
325334
updateTableDataError(null);
326-
if (
327-
isNil(configuration) ||
328-
(configuration as TableColumn[]).length === 0
329-
) {
330-
setConfiguration(data);
331-
}
335+
setConfiguration(data);
332336
},
333337
onError: (error: Error) => {
334338
updateTableDataError(error);
@@ -340,6 +344,16 @@ const EditTableForm: React.FC<{
340344
}
341345
);
342346

347+
const findCurrentColumnConfig = (name: string) => {
348+
if (Array.isArray(configuration)) {
349+
return configuration.find(column => column.name === name);
350+
}
351+
if (configuration?.name === name) {
352+
return { ...configuration };
353+
}
354+
return undefined;
355+
};
356+
343357
const onChangeName = (event: any) => {
344358
setName(event.target.value);
345359
setNameError(false);

src/shared/hooks/useAccessDataForTable.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ export const useAccessDataForTable = (
633633
);
634634
return result;
635635
}
636+
636637
return {};
637638
},
638639
{

0 commit comments

Comments
 (0)