Adding more error tracking around column creation, to reduce confusion/users not understanding required settings.
This commit is contained in:
parent
c021a6e49c
commit
f959ea0add
|
@ -9,6 +9,7 @@
|
||||||
DatePicker,
|
DatePicker,
|
||||||
ModalContent,
|
ModalContent,
|
||||||
Context,
|
Context,
|
||||||
|
notifications,
|
||||||
} from "@budibase/bbui"
|
} from "@budibase/bbui"
|
||||||
import { createEventDispatcher } from "svelte"
|
import { createEventDispatcher } from "svelte"
|
||||||
import { cloneDeep } from "lodash/fp"
|
import { cloneDeep } from "lodash/fp"
|
||||||
|
@ -25,7 +26,6 @@
|
||||||
SWITCHABLE_TYPES,
|
SWITCHABLE_TYPES,
|
||||||
} from "constants/backend"
|
} from "constants/backend"
|
||||||
import { getAutoColumnInformation, buildAutoColumn } from "builderStore/utils"
|
import { getAutoColumnInformation, buildAutoColumn } from "builderStore/utils"
|
||||||
import { notifications } from "@budibase/bbui"
|
|
||||||
import ValuesList from "components/common/ValuesList.svelte"
|
import ValuesList from "components/common/ValuesList.svelte"
|
||||||
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
||||||
import { truncate } from "lodash"
|
import { truncate } from "lodash"
|
||||||
|
@ -72,13 +72,8 @@
|
||||||
$: invalid =
|
$: invalid =
|
||||||
!field.name ||
|
!field.name ||
|
||||||
(field.type === LINK_TYPE && !field.tableId) ||
|
(field.type === LINK_TYPE && !field.tableId) ||
|
||||||
Object.keys($tables.draft?.schema ?? {}).some(
|
Object.keys(errors).length !== 0
|
||||||
key => key !== originalName && key === field.name
|
$: errors = checkErrors(field)
|
||||||
) ||
|
|
||||||
columnNameInvalid
|
|
||||||
$: columnNameInvalid = PROHIBITED_COLUMN_NAMES.some(
|
|
||||||
name => field.name === name
|
|
||||||
)
|
|
||||||
|
|
||||||
// used to select what different options can be displayed for column type
|
// used to select what different options can be displayed for column type
|
||||||
$: canBeSearched =
|
$: canBeSearched =
|
||||||
|
@ -106,13 +101,17 @@
|
||||||
if (field.type === AUTO_TYPE) {
|
if (field.type === AUTO_TYPE) {
|
||||||
field = buildAutoColumn($tables.draft.name, field.name, field.subtype)
|
field = buildAutoColumn($tables.draft.name, field.name, field.subtype)
|
||||||
}
|
}
|
||||||
await tables.saveField({
|
try {
|
||||||
originalName,
|
await tables.saveField({
|
||||||
field,
|
originalName,
|
||||||
primaryDisplay,
|
field,
|
||||||
indexes,
|
primaryDisplay,
|
||||||
})
|
indexes,
|
||||||
dispatch("updatecolumns")
|
})
|
||||||
|
dispatch("updatecolumns")
|
||||||
|
} catch (err) {
|
||||||
|
notifications.error(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteColumn() {
|
function deleteColumn() {
|
||||||
|
@ -258,6 +257,32 @@
|
||||||
fieldToCheck.constraints.numericality = {}
|
fieldToCheck.constraints.numericality = {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkErrors(fieldInfo) {
|
||||||
|
function inUse(tbl, column, ogName = null) {
|
||||||
|
return Object.keys(tbl?.schema || {}).some(
|
||||||
|
key => key !== ogName && key === column
|
||||||
|
)
|
||||||
|
}
|
||||||
|
const newError = {}
|
||||||
|
if (PROHIBITED_COLUMN_NAMES.some(name => fieldInfo.name === name)) {
|
||||||
|
newError.name = `${PROHIBITED_COLUMN_NAMES.join(
|
||||||
|
", "
|
||||||
|
)} are not allowed as column names`
|
||||||
|
} else if (inUse($tables.draft, fieldInfo.name, originalName)) {
|
||||||
|
newError.name = `Column name already in use.`
|
||||||
|
}
|
||||||
|
if (fieldInfo.fieldName && fieldInfo.tableId) {
|
||||||
|
const relatedTable = $tables.list.find(
|
||||||
|
tbl => tbl._id === fieldInfo.tableId
|
||||||
|
)
|
||||||
|
console.log(relatedTable)
|
||||||
|
if (inUse(relatedTable, fieldInfo.fieldName)) {
|
||||||
|
newError.relatedName = `Column name already in use in table ${relatedTable.name}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newError
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ModalContent
|
<ModalContent
|
||||||
|
@ -270,9 +295,7 @@
|
||||||
label="Name"
|
label="Name"
|
||||||
bind:value={field.name}
|
bind:value={field.name}
|
||||||
disabled={uneditable || (linkEditDisabled && field.type === LINK_TYPE)}
|
disabled={uneditable || (linkEditDisabled && field.type === LINK_TYPE)}
|
||||||
error={columnNameInvalid
|
error={errors?.name}
|
||||||
? `${PROHIBITED_COLUMN_NAMES.join(", ")} are not allowed as column names`
|
|
||||||
: ""}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Select
|
<Select
|
||||||
|
@ -381,6 +404,7 @@
|
||||||
disabled={linkEditDisabled}
|
disabled={linkEditDisabled}
|
||||||
label={`Column name in other table`}
|
label={`Column name in other table`}
|
||||||
bind:value={field.fieldName}
|
bind:value={field.fieldName}
|
||||||
|
error={errors.relatedName}
|
||||||
/>
|
/>
|
||||||
{:else if field.type === FORMULA_TYPE}
|
{:else if field.type === FORMULA_TYPE}
|
||||||
<ModalBindableInput
|
<ModalBindableInput
|
||||||
|
|
|
@ -66,6 +66,9 @@ export function createTablesStore() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await api.post(`/api/tables`, updatedTable)
|
const response = await api.post(`/api/tables`, updatedTable)
|
||||||
|
if (response.status !== 200) {
|
||||||
|
throw (await response.json()).message
|
||||||
|
}
|
||||||
const savedTable = await response.json()
|
const savedTable = await response.json()
|
||||||
await fetch()
|
await fetch()
|
||||||
if (table.type === "external") {
|
if (table.type === "external") {
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue