mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-06 06:48:21 +00:00
Added basic logic for autogenerating JSON columns.
This commit is contained in:
parent
868b36ebcb
commit
8972ff730a
2 changed files with 5 additions and 2 deletions
|
|
@ -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';
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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 }) ?? '';
|
||||
|
|
|
|||
Loading…
Reference in a new issue