1
0
Fork 0
mirror of synced 2024-10-05 12:34:50 +13:00

Handle internal types frontend

This commit is contained in:
Adria Navarro 2023-09-14 16:06:02 +02:00
parent 85a9b9ab21
commit 29b2e3b8f1
2 changed files with 48 additions and 3 deletions

View file

@ -72,8 +72,28 @@
fieldName: $tables.selected.name, fieldName: $tables.selected.name,
} }
const typeMapping = {}
if ($admin.isDev) { 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) { $: if (primaryDisplay) {
@ -82,6 +102,7 @@
const initialiseField = (field, savingColumn) => { const initialiseField = (field, savingColumn) => {
isCreating = !field isCreating = !field
if (field && !savingColumn) { if (field && !savingColumn) {
editableColumn = cloneDeep(field) editableColumn = cloneDeep(field)
originalName = editableColumn.name ? editableColumn.name + "" : null originalName = editableColumn.name ? editableColumn.name + "" : null
@ -89,6 +110,14 @@
primaryDisplay = primaryDisplay =
$tables.selected.primaryDisplay == null || $tables.selected.primaryDisplay == null ||
$tables.selected.primaryDisplay === editableColumn.name $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) { } else if (!savingColumn) {
let highestNumber = 0 let highestNumber = 0
Object.keys(table.schema).forEach(columnName => { Object.keys(table.schema).forEach(columnName => {
@ -105,6 +134,7 @@
editableColumn.name = "Column 01" editableColumn.name = "Column 01"
} }
} }
allowedTypes = getAllowedTypes() allowedTypes = getAllowedTypes()
} }
@ -186,6 +216,10 @@
let saveColumn = cloneDeep(editableColumn) let saveColumn = cloneDeep(editableColumn)
if (typeMapping[saveColumn.type]) {
saveColumn = { ...saveColumn, ...typeMapping[saveColumn.type] }
}
if (saveColumn.type === AUTO_TYPE) { if (saveColumn.type === AUTO_TYPE) {
saveColumn = buildAutoColumn( saveColumn = buildAutoColumn(
$tables.selected.name, $tables.selected.name,
@ -426,6 +460,8 @@
onMount(() => { onMount(() => {
mounted = true mounted = true
}) })
$: console.log({ type: editableColumn.type, allowedTypes, typeMapping })
</script> </script>
<Layout noPadding gap="S"> <Layout noPadding gap="S">

View file

@ -19,12 +19,21 @@ const TypeIconMap = {
formula: "Calculator", formula: "Calculator",
json: "Brackets", json: "Brackets",
bigint: "TagBold", bigint: "TagBold",
internal: {
user: "User",
},
} }
export const getColumnIcon = column => { export const getColumnIcon = column => {
if (column.schema.autocolumn) { if (column.schema.autocolumn) {
return "MagicWand" return "MagicWand"
} }
const type = column.schema.type const { type, subtype } = column.schema
return TypeIconMap[type] || "Text"
const result =
typeof TypeIconMap[type] === "object" && subtype
? TypeIconMap[type][subtype]
: TypeIconMap[type]
return result || "Text"
} }