Use field ids instead of playing with the type/subtype
This commit is contained in:
parent
b19c5ae5c6
commit
23702391ff
|
@ -51,13 +51,18 @@
|
||||||
export let field
|
export let field
|
||||||
|
|
||||||
let mounted = false
|
let mounted = false
|
||||||
let fieldDefinitions = Object.entries(FIELDS).reduce(
|
const fieldDefinitions = Object.values(FIELDS).reduce((acc, field) => {
|
||||||
(acc, [fieldName, field]) => {
|
const fieldId = makeFieldId(field)
|
||||||
acc[field.compositeType?.toUpperCase() || fieldName] = field
|
|
||||||
|
acc[fieldId] = { ...field, fieldId }
|
||||||
return acc
|
return acc
|
||||||
},
|
}, {})
|
||||||
{}
|
|
||||||
)
|
function makeFieldId(field) {
|
||||||
|
return `${field.type}${field.subtype || ""}`.toUpperCase()
|
||||||
|
}
|
||||||
|
|
||||||
|
$: console.warn(fieldDefinitions)
|
||||||
|
|
||||||
let originalName
|
let originalName
|
||||||
let linkEditDisabled
|
let linkEditDisabled
|
||||||
|
@ -145,9 +150,8 @@
|
||||||
$tables.selected.primaryDisplay == null ||
|
$tables.selected.primaryDisplay == null ||
|
||||||
$tables.selected.primaryDisplay === editableColumn.name
|
$tables.selected.primaryDisplay === editableColumn.name
|
||||||
|
|
||||||
if (editableColumn.type === FieldType.BB_REFERENCE) {
|
editableColumn.fieldId = makeFieldId(editableColumn)
|
||||||
editableColumn.type = `${editableColumn.type}_${editableColumn.subtype}`
|
|
||||||
}
|
|
||||||
// Here we are setting the relationship values based on the editableColumn
|
// Here we are setting the relationship values based on the editableColumn
|
||||||
// This part of the code is used when viewing an existing field hence the check
|
// This part of the code is used when viewing an existing field hence the check
|
||||||
// for the tableId
|
// for the tableId
|
||||||
|
@ -176,6 +180,8 @@
|
||||||
} else {
|
} else {
|
||||||
editableColumn.name = "Column 01"
|
editableColumn.name = "Column 01"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
editableColumn.fieldId = makeFieldId(editableColumn)
|
||||||
}
|
}
|
||||||
|
|
||||||
allowedTypes = getAllowedTypes()
|
allowedTypes = getAllowedTypes()
|
||||||
|
@ -255,13 +261,7 @@
|
||||||
|
|
||||||
let saveColumn = cloneDeep(editableColumn)
|
let saveColumn = cloneDeep(editableColumn)
|
||||||
|
|
||||||
// Handle types on composite types
|
delete saveColumn.fieldId
|
||||||
const definition = fieldDefinitions[saveColumn.type.toUpperCase()]
|
|
||||||
if (definition && saveColumn.type === definition.compositeType) {
|
|
||||||
saveColumn.type = definition.type
|
|
||||||
saveColumn.subtype = definition.subtype
|
|
||||||
delete saveColumn.compositeType
|
|
||||||
}
|
|
||||||
|
|
||||||
if (saveColumn.type === AUTO_TYPE) {
|
if (saveColumn.type === AUTO_TYPE) {
|
||||||
saveColumn = buildAutoColumn(
|
saveColumn = buildAutoColumn(
|
||||||
|
@ -390,38 +390,48 @@
|
||||||
|
|
||||||
if (!external) {
|
if (!external) {
|
||||||
return [
|
return [
|
||||||
FIELDS.STRING,
|
fieldDefinitions.STRING,
|
||||||
FIELDS.BARCODEQR,
|
fieldDefinitions.BARCODEQR,
|
||||||
FIELDS.LONGFORM,
|
fieldDefinitions.LONGFORM,
|
||||||
FIELDS.OPTIONS,
|
fieldDefinitions.OPTIONS,
|
||||||
FIELDS.ARRAY,
|
fieldDefinitions.ARRAY,
|
||||||
FIELDS.NUMBER,
|
fieldDefinitions.NUMBER,
|
||||||
FIELDS.BIGINT,
|
fieldDefinitions.BIGINT,
|
||||||
FIELDS.BOOLEAN,
|
fieldDefinitions.BOOLEAN,
|
||||||
FIELDS.DATETIME,
|
fieldDefinitions.DATETIME,
|
||||||
FIELDS.ATTACHMENT,
|
fieldDefinitions.ATTACHMENT,
|
||||||
FIELDS.LINK,
|
fieldDefinitions.LINK,
|
||||||
FIELDS.FORMULA,
|
fieldDefinitions.FORMULA,
|
||||||
FIELDS.JSON,
|
fieldDefinitions.JSON,
|
||||||
FIELDS.USER,
|
fieldDefinitions[
|
||||||
|
makeFieldId({
|
||||||
|
type: FieldType.BB_REFERENCE,
|
||||||
|
subtype: FieldSubtype.USER,
|
||||||
|
})
|
||||||
|
],
|
||||||
{ name: "Auto Column", type: AUTO_TYPE },
|
{ name: "Auto Column", type: AUTO_TYPE },
|
||||||
]
|
]
|
||||||
} else {
|
} else {
|
||||||
let fields = [
|
let fields = [
|
||||||
FIELDS.STRING,
|
fieldDefinitions.STRING,
|
||||||
FIELDS.BARCODEQR,
|
fieldDefinitions.BARCODEQR,
|
||||||
FIELDS.LONGFORM,
|
fieldDefinitions.LONGFORM,
|
||||||
FIELDS.OPTIONS,
|
fieldDefinitions.OPTIONS,
|
||||||
FIELDS.DATETIME,
|
fieldDefinitions.DATETIME,
|
||||||
FIELDS.NUMBER,
|
fieldDefinitions.NUMBER,
|
||||||
FIELDS.BOOLEAN,
|
fieldDefinitions.BOOLEAN,
|
||||||
FIELDS.FORMULA,
|
fieldDefinitions.FORMULA,
|
||||||
FIELDS.BIGINT,
|
fieldDefinitions.BIGINT,
|
||||||
FIELDS.BB_REFERENCE_USER,
|
fieldDefinitions[
|
||||||
|
getFieldId({
|
||||||
|
type: FieldType.BB_REFERENCE,
|
||||||
|
subtype: FieldSubtype.USER,
|
||||||
|
})
|
||||||
|
],
|
||||||
]
|
]
|
||||||
// no-sql or a spreadsheet
|
// no-sql or a spreadsheet
|
||||||
if (!external || table.sql) {
|
if (!external || table.sql) {
|
||||||
fields = [...fields, FIELDS.LINK, FIELDS.ARRAY]
|
fields = [...fields, fieldDefinitions.LINK, fieldDefinitions.ARRAY]
|
||||||
}
|
}
|
||||||
return fields
|
return fields
|
||||||
}
|
}
|
||||||
|
@ -509,11 +519,11 @@
|
||||||
{/if}
|
{/if}
|
||||||
<Select
|
<Select
|
||||||
disabled={!typeEnabled}
|
disabled={!typeEnabled}
|
||||||
value={editableColumn.type}
|
bind:value={editableColumn.fieldId}
|
||||||
on:change={handleTypeChange}
|
on:change={handleTypeChange}
|
||||||
options={allowedTypes}
|
options={allowedTypes}
|
||||||
getOptionLabel={field => field.name}
|
getOptionLabel={field => field.name}
|
||||||
getOptionValue={field => field.compositeType || field.type}
|
getOptionValue={field => field.fieldId}
|
||||||
getOptionIcon={field => field.icon}
|
getOptionIcon={field => field.icon}
|
||||||
isOptionEnabled={option => {
|
isOptionEnabled={option => {
|
||||||
if (option.type == AUTO_TYPE) {
|
if (option.type == AUTO_TYPE) {
|
||||||
|
|
Loading…
Reference in New Issue