From 8972ff730ae144cdf8b3376c800dd8e89445f455 Mon Sep 17 00:00:00 2001 From: devanshu052000 Date: Mon, 6 Jan 2025 04:16:55 +0530 Subject: [PATCH] Added basic logic for autogenerating JSON columns. --- .../AppBuilder/Widgets/Table/columns/autogenerateColumns.js | 6 ++++-- frontend/src/AppBuilder/Widgets/Table/columns/index.jsx | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/frontend/src/AppBuilder/Widgets/Table/columns/autogenerateColumns.js b/frontend/src/AppBuilder/Widgets/Table/columns/autogenerateColumns.js index 98faa12da0..83c07fc0ac 100644 --- a/frontend/src/AppBuilder/Widgets/Table/columns/autogenerateColumns.js +++ b/frontend/src/AppBuilder/Widgets/Table/columns/autogenerateColumns.js @@ -50,6 +50,7 @@ export default function autogenerateColumns( const currentKey = parentKey ? `${parentKey}.${key}` : key; if (isValueIsPlainObject(value)) { // if value is object particularly, then we only want nested keys till one level of nesting + accumulator.push(currentKey); accumulator.push(...limitToOneLevelNestingHelperFunc(value, currentKey)); } else if (isValueIsPremitiveOrArray(value)) { // check if value is premitive or array then simply push current key in the accumulator. @@ -98,7 +99,7 @@ export default function autogenerateColumns( id: uuidv4(), name: key, key: key, - columnType: convertDataTypeToColumnType(dataType), + columnType: convertDataTypeToColumnType(dataType, firstRow[key]), autogenerated: true, })); @@ -123,7 +124,8 @@ const dataTypeToColumnTypeMapping = { boolean: 'boolean', }; -const convertDataTypeToColumnType = (dataType) => { +const convertDataTypeToColumnType = (dataType, value) => { if (Object.keys(dataTypeToColumnTypeMapping).includes(dataType)) return dataTypeToColumnTypeMapping[dataType]; + if (dataType === 'object' && !Array.isArray(value)) return 'json'; else return 'string'; }; diff --git a/frontend/src/AppBuilder/Widgets/Table/columns/index.jsx b/frontend/src/AppBuilder/Widgets/Table/columns/index.jsx index b4875d4b31..c6a5945a49 100644 --- a/frontend/src/AppBuilder/Widgets/Table/columns/index.jsx +++ b/frontend/src/AppBuilder/Widgets/Table/columns/index.jsx @@ -186,6 +186,7 @@ export default function generateColumnsData({ switch (columnType) { case 'string': + case 'json': case undefined: case 'default': { const cellTextColor = getResolvedValue(column.textColor, { cellValue, rowData }) ?? '';