From 752ae0ac2bb1ac4034323e44c2c534a7555cd1c7 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 14 Sep 2023 16:06:02 +0200 Subject: [PATCH] Handle internal types frontend --- .../DataTable/modals/CreateEditColumn.svelte | 38 ++++++++++++++++++- .../src/components/grid/lib/utils.js | 13 ++++++- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index c4342f9b0b..f61e69943d 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -72,8 +72,28 @@ fieldName: $tables.selected.name, } + const typeMapping = {} + if ($admin.isDev) { - fieldDefinitions = { ...fieldDefinitions, ...cloneDeep(DEV_FIELDS) } + fieldDefinitions = { + ...fieldDefinitions, + ...Object.entries(DEV_FIELDS).reduce((p, [key, field]) => { + if (field.subtype) { + const composedType = `${field.type}_${field.subtype}` + p[key] = { + ...field, + type: composedType, + } + typeMapping[composedType] = { + type: field.type, + subtype: field.subtype, + } + } else { + p[key] = field + } + return p + }, {}), + } } $: if (primaryDisplay) { @@ -82,6 +102,7 @@ const initialiseField = (field, savingColumn) => { isCreating = !field + if (field && !savingColumn) { editableColumn = cloneDeep(field) originalName = editableColumn.name ? editableColumn.name + "" : null @@ -89,6 +110,14 @@ primaryDisplay = $tables.selected.primaryDisplay == null || $tables.selected.primaryDisplay === editableColumn.name + + const mapped = Object.entries(typeMapping).find( + ([_, v]) => v.type === field.type && v.subtype === field.subtype + ) + if (mapped) { + editableColumn.type = mapped[0] + delete editableColumn.subtype + } } else if (!savingColumn) { let highestNumber = 0 Object.keys(table.schema).forEach(columnName => { @@ -105,6 +134,7 @@ editableColumn.name = "Column 01" } } + allowedTypes = getAllowedTypes() } @@ -186,6 +216,10 @@ let saveColumn = cloneDeep(editableColumn) + if (typeMapping[saveColumn.type]) { + saveColumn = { ...saveColumn, ...typeMapping[saveColumn.type] } + } + if (saveColumn.type === AUTO_TYPE) { saveColumn = buildAutoColumn( $tables.selected.name, @@ -426,6 +460,8 @@ onMount(() => { mounted = true }) + + $: console.log({ type: editableColumn.type, allowedTypes, typeMapping }) diff --git a/packages/frontend-core/src/components/grid/lib/utils.js b/packages/frontend-core/src/components/grid/lib/utils.js index d4298e6a1b..feff3da625 100644 --- a/packages/frontend-core/src/components/grid/lib/utils.js +++ b/packages/frontend-core/src/components/grid/lib/utils.js @@ -19,12 +19,21 @@ const TypeIconMap = { formula: "Calculator", json: "Brackets", bigint: "TagBold", + internal: { + user: "User", + }, } export const getColumnIcon = column => { if (column.schema.autocolumn) { return "MagicWand" } - const type = column.schema.type - return TypeIconMap[type] || "Text" + const { type, subtype } = column.schema + + const result = + typeof TypeIconMap[type] === "object" && subtype + ? TypeIconMap[type][subtype] + : TypeIconMap[type] + + return result || "Text" }