Allow selecting user column type
This commit is contained in:
parent
5783ae3e00
commit
a514358e57
|
@ -10,36 +10,73 @@
|
||||||
export let displayColumn = null
|
export let displayColumn = null
|
||||||
export let promptUpload = false
|
export let promptUpload = false
|
||||||
|
|
||||||
const typeOptions = [
|
const typeOptions = {
|
||||||
{
|
[FIELDS.STRING.type]: {
|
||||||
label: "Text",
|
label: "Text",
|
||||||
value: FIELDS.STRING.type,
|
value: FIELDS.STRING.type,
|
||||||
|
config: {
|
||||||
|
type: FIELDS.STRING.type,
|
||||||
|
constraints: FIELDS.STRING.constraints,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
[FIELDS.NUMBER.type]: {
|
||||||
label: "Number",
|
label: "Number",
|
||||||
value: FIELDS.NUMBER.type,
|
value: FIELDS.NUMBER.type,
|
||||||
|
config: {
|
||||||
|
type: FIELDS.NUMBER.type,
|
||||||
|
constraints: FIELDS.NUMBER.constraints,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
[FIELDS.DATETIME.type]: {
|
||||||
label: "Date",
|
label: "Date",
|
||||||
value: FIELDS.DATETIME.type,
|
value: FIELDS.DATETIME.type,
|
||||||
|
config: {
|
||||||
|
type: FIELDS.DATETIME.type,
|
||||||
|
constraints: FIELDS.DATETIME.constraints,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
[FIELDS.OPTIONS.type]: {
|
||||||
label: "Options",
|
label: "Options",
|
||||||
value: FIELDS.OPTIONS.type,
|
value: FIELDS.OPTIONS.type,
|
||||||
|
config: {
|
||||||
|
type: FIELDS.OPTIONS.type,
|
||||||
|
constraints: FIELDS.OPTIONS.constraints,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
[FIELDS.ARRAY.type]: {
|
||||||
label: "Multi-select",
|
label: "Multi-select",
|
||||||
value: FIELDS.ARRAY.type,
|
value: FIELDS.ARRAY.type,
|
||||||
|
config: {
|
||||||
|
type: FIELDS.ARRAY.type,
|
||||||
|
constraints: FIELDS.ARRAY.constraints,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
[FIELDS.BARCODEQR.type]: {
|
||||||
label: "Barcode/QR",
|
label: "Barcode/QR",
|
||||||
value: FIELDS.BARCODEQR.type,
|
value: FIELDS.BARCODEQR.type,
|
||||||
|
config: {
|
||||||
|
type: FIELDS.BARCODEQR.type,
|
||||||
|
constraints: FIELDS.BARCODEQR.constraints,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
[FIELDS.LONGFORM.type]: {
|
||||||
label: "Long Form Text",
|
label: "Long Form Text",
|
||||||
value: FIELDS.LONGFORM.type,
|
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 fileInput
|
||||||
let error = null
|
let error = null
|
||||||
|
@ -48,6 +85,7 @@
|
||||||
let validation = {}
|
let validation = {}
|
||||||
let validateHash = ""
|
let validateHash = ""
|
||||||
let errors = {}
|
let errors = {}
|
||||||
|
let selectedColumnTypes = {}
|
||||||
|
|
||||||
$: displayColumnOptions = Object.keys(schema || {}).filter(column => {
|
$: displayColumnOptions = Object.keys(schema || {}).filter(column => {
|
||||||
return validation[column]
|
return validation[column]
|
||||||
|
@ -72,6 +110,13 @@
|
||||||
rows = response.rows
|
rows = response.rows
|
||||||
schema = response.schema
|
schema = response.schema
|
||||||
fileName = response.fileName
|
fileName = response.fileName
|
||||||
|
selectedColumnTypes = Object.entries(response.schema).reduce(
|
||||||
|
(acc, [colName, fieldConfig]) => ({
|
||||||
|
...acc,
|
||||||
|
[colName]: fieldConfig.type,
|
||||||
|
}),
|
||||||
|
{}
|
||||||
|
)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loading = false
|
loading = false
|
||||||
error = e
|
error = e
|
||||||
|
@ -98,8 +143,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleChange = (name, e) => {
|
const handleChange = (name, e) => {
|
||||||
schema[name].type = e.detail
|
const { config } = typeOptions[e.detail]
|
||||||
schema[name].constraints = FIELDS[e.detail.toUpperCase()].constraints
|
schema[name].type = config.type
|
||||||
|
schema[name].subtype = config.subtype
|
||||||
|
schema[name].constraints = config.constraints
|
||||||
}
|
}
|
||||||
|
|
||||||
const openFileUpload = (promptUpload, fileInput) => {
|
const openFileUpload = (promptUpload, fileInput) => {
|
||||||
|
@ -142,9 +189,9 @@
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<span>{column.name}</span>
|
<span>{column.name}</span>
|
||||||
<Select
|
<Select
|
||||||
bind:value={column.type}
|
bind:value={selectedColumnTypes[column.name]}
|
||||||
on:change={e => handleChange(name, e)}
|
on:change={e => handleChange(name, e)}
|
||||||
options={typeOptions}
|
options={Object.values(typeOptions)}
|
||||||
placeholder={null}
|
placeholder={null}
|
||||||
getOptionLabel={option => option.label}
|
getOptionLabel={option => option.label}
|
||||||
getOptionValue={option => option.value}
|
getOptionValue={option => option.value}
|
||||||
|
|
Loading…
Reference in New Issue