Skip to content

Commit 618b60c

Browse files
committed
feat: save same column shape as it was received
1 parent 3137822 commit 618b60c

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

packages/module/src/ColumnManagementModal/ColumnManagementModal.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export interface ColumnManagementModalColumn {
1717
}
1818

1919
/** extends ModalProps */
20-
export interface ColumnManagementModalProps<T extends ColumnManagementModalColumn = ColumnManagementModalColumn> extends Omit<ModalProps, 'ref' | 'children'> {
20+
export interface ColumnManagementModalProps<T extends ColumnManagementModalColumn = ColumnManagementModalColumn>
21+
extends Omit<ModalProps, 'ref' | 'children'> {
2122
/** Flag to show the modal */
2223
isOpen?: boolean;
2324
/** Invoked when modal visibility is changed */
@@ -53,7 +54,7 @@ const ColumnManagementModal = <T extends ColumnManagementModalColumn = ColumnMan
5354
resetToDefaultLabel = 'Reset to default',
5455
...props
5556
}: ColumnManagementModalProps<T>) => {
56-
const [ currentColumns, setCurrentColumns ] = useState(() =>
57+
const [ currentColumns, setCurrentColumns ] = useState<T[]>(() =>
5758
appliedColumns.map((column) => ({ ...column, isShown: column.isShown ?? column.isShownByDefault }))
5859
);
5960

@@ -108,13 +109,13 @@ const ColumnManagementModal = <T extends ColumnManagementModalColumn = ColumnMan
108109
};
109110

110111
const handleSave = (items: ListManagerItem[]) => {
111-
const updatedColumns = items.map((item) => ({
112-
key: item.key,
113-
title: item.title,
114-
isShown: item.isSelected,
115-
isShownByDefault: item.isShownByDefault,
116-
isUntoggleable: item.isUntoggleable
117-
}));
112+
const updatedColumns = items.map((item) => {
113+
const originalColumn = currentColumns.find((col) => col.key === item.key);
114+
if (!originalColumn) {
115+
throw new Error(`Column with key ${item.key} not found`);
116+
}
117+
return { ...originalColumn, isShown: item.isSelected };
118+
});
118119
applyColumns(updatedColumns);
119120
onClose({} as KeyboardEvent);
120121
};

0 commit comments

Comments
 (0)