Accumulate properties rather than replace for column definitions

This commit is contained in:
Laurent Nguyen 2024-06-21 12:05:50 +02:00
parent ce0cfed128
commit bea3aa8b55

View File

@ -1246,9 +1246,18 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
return columnDefinitions; return columnDefinitions;
}; };
/**
* Extract column definitions from document and add to the definitions
* @param document
*/
const setColumnDefinitionsFromDocument = (document: unknown): void => { const setColumnDefinitionsFromDocument = (document: unknown): void => {
// TODO Add fields rather than replace const currentIds = new Set(columnDefinitions.map((columnDefinition) => columnDefinition.id));
setColumnDefinitions(extractColumnDefinitionsFromDocument(document)); extractColumnDefinitionsFromDocument(document).forEach((columnDefinition) => {
if (!currentIds.has(columnDefinition.id)) {
columnDefinitions.push(columnDefinition);
}
});
setColumnDefinitions([...columnDefinitions]);
}; };
/** /**
@ -1359,6 +1368,7 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
return () => resizeObserver.disconnect(); // clean up return () => resizeObserver.disconnect(); // clean up
}, []); }, []);
// Column definition is a map<id, ColumnDefinition> to garantee uniqueness
const [columnDefinitions, setColumnDefinitions] = useState<ColumnDefinition[]>(() => const [columnDefinitions, setColumnDefinitions] = useState<ColumnDefinition[]>(() =>
extractColumnDefinitionsFromDocument({ extractColumnDefinitionsFromDocument({
id: "id", id: "id",