Handle internal types frontend
This commit is contained in:
parent
a79960bf23
commit
752ae0ac2b
|
@ -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">
|
||||||
|
|
|
@ -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"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue