Added basic logic for autogenerating JSON columns.

This commit is contained in:
devanshu052000 2025-01-06 04:16:55 +05:30
parent 868b36ebcb
commit 8972ff730a
2 changed files with 5 additions and 2 deletions

View file

@ -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';
};

View file

@ -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 }) ?? '';