Disable saving options types when an invalid option name exists
This commit is contained in:
parent
37b1bc45cf
commit
8d1300753b
|
@ -95,6 +95,7 @@
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
let autoColumnInfo = getAutoColumnInformation()
|
let autoColumnInfo = getAutoColumnInformation()
|
||||||
|
let optionsValid = true
|
||||||
|
|
||||||
$: rowGoldenSample = RowUtils.generateGoldenSample($rows)
|
$: rowGoldenSample = RowUtils.generateGoldenSample($rows)
|
||||||
$: if (primaryDisplay) {
|
$: if (primaryDisplay) {
|
||||||
|
@ -138,7 +139,8 @@
|
||||||
$: invalid =
|
$: invalid =
|
||||||
!editableColumn?.name ||
|
!editableColumn?.name ||
|
||||||
(editableColumn?.type === LINK_TYPE && !editableColumn?.tableId) ||
|
(editableColumn?.type === LINK_TYPE && !editableColumn?.tableId) ||
|
||||||
Object.keys(errors).length !== 0
|
Object.keys(errors).length !== 0 ||
|
||||||
|
!optionsValid
|
||||||
$: errors = checkErrors(editableColumn)
|
$: errors = checkErrors(editableColumn)
|
||||||
$: datasource = $datasources.list.find(
|
$: datasource = $datasources.list.find(
|
||||||
source => source._id === table?.sourceId
|
source => source._id === table?.sourceId
|
||||||
|
@ -562,6 +564,7 @@
|
||||||
<OptionsEditor
|
<OptionsEditor
|
||||||
bind:constraints={editableColumn.constraints}
|
bind:constraints={editableColumn.constraints}
|
||||||
bind:optionColors={editableColumn.optionColors}
|
bind:optionColors={editableColumn.optionColors}
|
||||||
|
bind:valid={optionsValid}
|
||||||
/>
|
/>
|
||||||
{:else if editableColumn.type === FieldType.LONGFORM}
|
{:else if editableColumn.type === FieldType.LONGFORM}
|
||||||
<div>
|
<div>
|
||||||
|
@ -585,6 +588,7 @@
|
||||||
<OptionsEditor
|
<OptionsEditor
|
||||||
bind:constraints={editableColumn.constraints}
|
bind:constraints={editableColumn.constraints}
|
||||||
bind:optionColors={editableColumn.optionColors}
|
bind:optionColors={editableColumn.optionColors}
|
||||||
|
bind:valid={optionsValid}
|
||||||
/>
|
/>
|
||||||
{:else if editableColumn.type === DATE_TYPE && !editableColumn.autocolumn}
|
{:else if editableColumn.type === DATE_TYPE && !editableColumn.autocolumn}
|
||||||
<div class="split-label">
|
<div class="split-label">
|
||||||
|
|
|
@ -5,10 +5,11 @@
|
||||||
import { tick } from "svelte"
|
import { tick } from "svelte"
|
||||||
import { Constants } from "@budibase/frontend-core"
|
import { Constants } from "@budibase/frontend-core"
|
||||||
import { getSequentialName } from "helpers/duplicate"
|
import { getSequentialName } from "helpers/duplicate"
|
||||||
import { writable } from "svelte/store"
|
import { derived, writable } from "svelte/store"
|
||||||
|
|
||||||
export let constraints
|
export let constraints
|
||||||
export let optionColors = {}
|
export let optionColors = {}
|
||||||
|
export let valid = true
|
||||||
|
|
||||||
const flipDurationMs = 130
|
const flipDurationMs = 130
|
||||||
const { OptionColours } = Constants
|
const { OptionColours } = Constants
|
||||||
|
@ -21,11 +22,22 @@
|
||||||
invalid: false,
|
invalid: false,
|
||||||
}))
|
}))
|
||||||
)
|
)
|
||||||
|
const enrichedOptions = derived(options, $options => {
|
||||||
|
let enriched = []
|
||||||
|
$options.forEach(option => {
|
||||||
|
enriched.push({
|
||||||
|
...option,
|
||||||
|
valid: option.name && !enriched.some(opt => opt.name === option.name),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return enriched
|
||||||
|
})
|
||||||
|
|
||||||
let openOption = null
|
let openOption = null
|
||||||
let anchor = null
|
let anchor = null
|
||||||
|
|
||||||
$: options.subscribe(updateConstraints)
|
$: options.subscribe(updateConstraints)
|
||||||
|
$: valid = $enrichedOptions.every(option => option.valid)
|
||||||
|
|
||||||
const updateConstraints = options => {
|
const updateConstraints = options => {
|
||||||
constraints.inclusion = options.map(option => option.name)
|
constraints.inclusion = options.map(option => option.name)
|
||||||
|
@ -74,25 +86,9 @@
|
||||||
openOption = null
|
openOption = null
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleNameChange = (id, newName) => {
|
const handleNameChange = (id, name) => {
|
||||||
// Check we don't already have this option
|
|
||||||
const existing = $options.some(option => {
|
|
||||||
return (option.name === newName) & (option.id !== id)
|
|
||||||
})
|
|
||||||
const invalid = !newName || existing
|
|
||||||
options.update(state => {
|
options.update(state => {
|
||||||
state.find(option => option.id === id).invalid = invalid
|
state.find(option => option.id === id).name = name
|
||||||
return state.slice()
|
|
||||||
})
|
|
||||||
|
|
||||||
// Stop if invalid
|
|
||||||
if (invalid) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update name
|
|
||||||
options.update(state => {
|
|
||||||
state.find(option => option.id === id).name = newName
|
|
||||||
return state.slice()
|
return state.slice()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -111,11 +107,11 @@
|
||||||
on:consider={e => options.set(e.detail.items)}
|
on:consider={e => options.set(e.detail.items)}
|
||||||
on:finalize={e => options.set(e.detail.items)}
|
on:finalize={e => options.set(e.detail.items)}
|
||||||
>
|
>
|
||||||
{#each $options as option (option.id)}
|
{#each $enrichedOptions as option (option.id)}
|
||||||
<div
|
<div
|
||||||
class="option"
|
class="option"
|
||||||
animate:flip={{ duration: flipDurationMs }}
|
animate:flip={{ duration: flipDurationMs }}
|
||||||
class:invalid={option.invalid}
|
class:invalid={!option.valid}
|
||||||
>
|
>
|
||||||
<div class="drag-handle">
|
<div class="drag-handle">
|
||||||
<Icon name="DragHandle" size="L" />
|
<Icon name="DragHandle" size="L" />
|
||||||
|
|
Loading…
Reference in New Issue