Only allow data fields that can be rendered (string and numbers) in column selection

This commit is contained in:
Laurent Nguyen 2024-06-21 11:42:02 +02:00
parent c0a79c1e67
commit ce0cfed128

View File

@ -1055,8 +1055,6 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
); );
setOnLoadStartKey(undefined); setOnLoadStartKey(undefined);
} }
// Update column definitions
}; };
let loadNextPage = useCallback( let loadNextPage = useCallback(
@ -1225,7 +1223,10 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
}); });
const extractColumnDefinitionsFromDocument = (document: unknown): ColumnDefinition[] => { const extractColumnDefinitionsFromDocument = (document: unknown): ColumnDefinition[] => {
let columnDefinitions: ColumnDefinition[] = Object.keys(document).map((key) => let columnDefinitions: ColumnDefinition[] = Object.keys(document)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.filter((key) => typeof (document as any)[key] === "string" || typeof (document as any)[key] === "number") // Only allow safe types for displayable React children
.map((key) =>
key === "id" key === "id"
? { id: key, label: isPreferredApiMongoDB ? "_id" : "id", group: undefined } ? { id: key, label: isPreferredApiMongoDB ? "_id" : "id", group: undefined }
: { id: key, label: key, group: undefined }, : { id: key, label: key, group: undefined },