Add basic datasource validation error
This commit is contained in:
parent
fa930de15e
commit
0d1f5c698e
|
@ -7206,7 +7206,8 @@
|
||||||
{
|
{
|
||||||
"type": "table",
|
"type": "table",
|
||||||
"label": "Data",
|
"label": "Data",
|
||||||
"key": "dataSource"
|
"key": "dataSource",
|
||||||
|
"validator": "checkValidDatasource"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "radio",
|
"type": "radio",
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
getActionDependentContextKeys,
|
getActionDependentContextKeys,
|
||||||
} from "../utils/buttonActions.js"
|
} from "../utils/buttonActions.js"
|
||||||
import { gridLayout } from "utils/grid"
|
import { gridLayout } from "utils/grid"
|
||||||
|
import { validateComponentSetting } from "utils/componentsValidator"
|
||||||
|
|
||||||
export let instance = {}
|
export let instance = {}
|
||||||
export let parent = null
|
export let parent = null
|
||||||
|
@ -103,6 +104,7 @@
|
||||||
let settingsDefinition
|
let settingsDefinition
|
||||||
let settingsDefinitionMap
|
let settingsDefinitionMap
|
||||||
let missingRequiredSettings = false
|
let missingRequiredSettings = false
|
||||||
|
let invalidSettings = false
|
||||||
|
|
||||||
// Temporary styles which can be added in the app preview for things like
|
// Temporary styles which can be added in the app preview for things like
|
||||||
// DND. We clear these whenever a new instance is received.
|
// DND. We clear these whenever a new instance is received.
|
||||||
|
@ -141,12 +143,16 @@
|
||||||
$: showEmptyState = definition?.showEmptyState !== false
|
$: showEmptyState = definition?.showEmptyState !== false
|
||||||
$: hasMissingRequiredSettings = missingRequiredSettings?.length > 0
|
$: hasMissingRequiredSettings = missingRequiredSettings?.length > 0
|
||||||
$: editable = !!definition?.editable && !hasMissingRequiredSettings
|
$: editable = !!definition?.editable && !hasMissingRequiredSettings
|
||||||
|
$: hasInvalidSettings = invalidSettings?.length > 0
|
||||||
$: requiredAncestors = definition?.requiredAncestors || []
|
$: requiredAncestors = definition?.requiredAncestors || []
|
||||||
$: missingRequiredAncestors = requiredAncestors.filter(
|
$: missingRequiredAncestors = requiredAncestors.filter(
|
||||||
ancestor => !$component.ancestors.includes(`${BudibasePrefix}${ancestor}`)
|
ancestor => !$component.ancestors.includes(`${BudibasePrefix}${ancestor}`)
|
||||||
)
|
)
|
||||||
$: hasMissingRequiredAncestors = missingRequiredAncestors?.length > 0
|
$: hasMissingRequiredAncestors = missingRequiredAncestors?.length > 0
|
||||||
$: errorState = hasMissingRequiredSettings || hasMissingRequiredAncestors
|
$: errorState =
|
||||||
|
hasMissingRequiredSettings ||
|
||||||
|
hasMissingRequiredAncestors ||
|
||||||
|
hasInvalidSettings
|
||||||
|
|
||||||
// Interactive components can be selected, dragged and highlighted inside
|
// Interactive components can be selected, dragged and highlighted inside
|
||||||
// the builder preview
|
// the builder preview
|
||||||
|
@ -338,6 +344,21 @@
|
||||||
return missing
|
return missing
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Check for invalid settings
|
||||||
|
invalidSettings = settingsDefinition.reduce((invalidSettings, setting) => {
|
||||||
|
if (setting.validator) {
|
||||||
|
const error = validateComponentSetting(
|
||||||
|
setting.validator,
|
||||||
|
instance[setting.key]
|
||||||
|
)
|
||||||
|
if (error) {
|
||||||
|
invalidSettings.push(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return invalidSettings
|
||||||
|
}, [])
|
||||||
|
|
||||||
// When considering bindings we can ignore children, so we remove that
|
// When considering bindings we can ignore children, so we remove that
|
||||||
// before storing the reference stringified version
|
// before storing the reference stringified version
|
||||||
const noChildren = JSON.stringify({ ...instance, _children: null })
|
const noChildren = JSON.stringify({ ...instance, _children: null })
|
||||||
|
@ -692,6 +713,7 @@
|
||||||
<ComponentErrorState
|
<ComponentErrorState
|
||||||
{missingRequiredSettings}
|
{missingRequiredSettings}
|
||||||
{missingRequiredAncestors}
|
{missingRequiredAncestors}
|
||||||
|
{invalidSettings}
|
||||||
/>
|
/>
|
||||||
{:else}
|
{:else}
|
||||||
<svelte:component this={constructor} bind:this={ref} {...initialSettings}>
|
<svelte:component this={constructor} bind:this={ref} {...initialSettings}>
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
| { key: string; label: string }[]
|
| { key: string; label: string }[]
|
||||||
| undefined
|
| undefined
|
||||||
export let missingRequiredAncestors: string[] | undefined
|
export let missingRequiredAncestors: string[] | undefined
|
||||||
|
export let invalidSettings: string[] | undefined
|
||||||
|
|
||||||
const component = getContext<Component>("component")
|
const component = getContext<Component>("component")
|
||||||
const { styleable, builderStore } = getContext<SDK>("sdk")
|
const { styleable, builderStore } = getContext<SDK>("sdk")
|
||||||
|
@ -16,6 +17,7 @@
|
||||||
$: styles = { ...$component.styles, normal: {}, custom: null, empty: true }
|
$: styles = { ...$component.styles, normal: {}, custom: null, empty: true }
|
||||||
$: requiredSetting = missingRequiredSettings?.[0]
|
$: requiredSetting = missingRequiredSettings?.[0]
|
||||||
$: requiredAncestor = missingRequiredAncestors?.[0]
|
$: requiredAncestor = missingRequiredAncestors?.[0]
|
||||||
|
$: invalidSetting = invalidSettings?.[0]
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if $builderStore.inBuilder}
|
{#if $builderStore.inBuilder}
|
||||||
|
@ -24,6 +26,8 @@
|
||||||
<Icon name="Alert" color="var(--spectrum-global-color-static-red-600)" />
|
<Icon name="Alert" color="var(--spectrum-global-color-static-red-600)" />
|
||||||
{#if requiredAncestor}
|
{#if requiredAncestor}
|
||||||
<MissingRequiredAncestor {requiredAncestor} />
|
<MissingRequiredAncestor {requiredAncestor} />
|
||||||
|
{:else if invalidSetting}
|
||||||
|
{invalidSetting}
|
||||||
{:else if requiredSetting}
|
{:else if requiredSetting}
|
||||||
<MissingRequiredSetting {requiredSetting} />
|
<MissingRequiredSetting {requiredSetting} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
const validators = {
|
||||||
|
checkValidDatasource: (a: any) => {
|
||||||
|
return `Ups... "${a.label}" not found`
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
export function validateComponentSetting(
|
||||||
|
key: keyof typeof validators,
|
||||||
|
value: any
|
||||||
|
) {
|
||||||
|
const validator = validators[key]
|
||||||
|
return validator(value)
|
||||||
|
}
|
Loading…
Reference in New Issue