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,11 +1223,14 @@ 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)
key === "id" // eslint-disable-next-line @typescript-eslint/no-explicit-any
? { id: key, label: isPreferredApiMongoDB ? "_id" : "id", group: undefined } .filter((key) => typeof (document as any)[key] === "string" || typeof (document as any)[key] === "number") // Only allow safe types for displayable React children
: { id: key, label: key, group: undefined }, .map((key) =>
); key === "id"
? { id: key, label: isPreferredApiMongoDB ? "_id" : "id", group: undefined }
: { id: key, label: key, group: undefined },
);
if (showPartitionKey(_collection, isPreferredApiMongoDB)) { if (showPartitionKey(_collection, isPreferredApiMongoDB)) {
columnDefinitions.push( columnDefinitions.push(