diff --git a/packages/builder/src/components/backend/TableNavigator/TableDataImport.svelte b/packages/builder/src/components/backend/TableNavigator/TableDataImport.svelte index 7bf2bbbbab..6f44135006 100644 --- a/packages/builder/src/components/backend/TableNavigator/TableDataImport.svelte +++ b/packages/builder/src/components/backend/TableNavigator/TableDataImport.svelte @@ -10,36 +10,73 @@ export let displayColumn = null export let promptUpload = false - const typeOptions = [ - { + const typeOptions = { + [FIELDS.STRING.type]: { label: "Text", value: FIELDS.STRING.type, + config: { + type: FIELDS.STRING.type, + constraints: FIELDS.STRING.constraints, + }, }, - { + [FIELDS.NUMBER.type]: { label: "Number", value: FIELDS.NUMBER.type, + config: { + type: FIELDS.NUMBER.type, + constraints: FIELDS.NUMBER.constraints, + }, }, - { + [FIELDS.DATETIME.type]: { label: "Date", value: FIELDS.DATETIME.type, + config: { + type: FIELDS.DATETIME.type, + constraints: FIELDS.DATETIME.constraints, + }, }, - { + [FIELDS.OPTIONS.type]: { label: "Options", value: FIELDS.OPTIONS.type, + config: { + type: FIELDS.OPTIONS.type, + constraints: FIELDS.OPTIONS.constraints, + }, }, - { + [FIELDS.ARRAY.type]: { label: "Multi-select", value: FIELDS.ARRAY.type, + config: { + type: FIELDS.ARRAY.type, + constraints: FIELDS.ARRAY.constraints, + }, }, - { + [FIELDS.BARCODEQR.type]: { label: "Barcode/QR", value: FIELDS.BARCODEQR.type, + config: { + type: FIELDS.BARCODEQR.type, + constraints: FIELDS.BARCODEQR.constraints, + }, }, - { + [FIELDS.LONGFORM.type]: { label: "Long Form Text", value: FIELDS.LONGFORM.type, + config: { + type: FIELDS.LONGFORM.type, + constraints: FIELDS.LONGFORM.constraints, + }, }, - ] + user: { + label: "User", + value: "user", + config: { + type: FIELDS.USER.type, + subtype: FIELDS.USER.subtype, + constraints: FIELDS.USER.constraints, + }, + }, + } let fileInput let error = null @@ -48,6 +85,7 @@ let validation = {} let validateHash = "" let errors = {} + let selectedColumnTypes = {} $: displayColumnOptions = Object.keys(schema || {}).filter(column => { return validation[column] @@ -72,6 +110,13 @@ rows = response.rows schema = response.schema fileName = response.fileName + selectedColumnTypes = Object.entries(response.schema).reduce( + (acc, [colName, fieldConfig]) => ({ + ...acc, + [colName]: fieldConfig.type, + }), + {} + ) } catch (e) { loading = false error = e @@ -98,8 +143,10 @@ } const handleChange = (name, e) => { - schema[name].type = e.detail - schema[name].constraints = FIELDS[e.detail.toUpperCase()].constraints + const { config } = typeOptions[e.detail] + schema[name].type = config.type + schema[name].subtype = config.subtype + schema[name].constraints = config.constraints } const openFileUpload = (promptUpload, fileInput) => { @@ -142,9 +189,9 @@
{column.name}