Adding validation around invalid JSON inputs and allowing input via a code mirror editor in data UI.
This commit is contained in:
parent
003b6424a2
commit
193014fc83
|
@ -6,16 +6,20 @@
|
||||||
Toggle,
|
Toggle,
|
||||||
TextArea,
|
TextArea,
|
||||||
Multiselect,
|
Multiselect,
|
||||||
|
Label,
|
||||||
} from "@budibase/bbui"
|
} from "@budibase/bbui"
|
||||||
import Dropzone from "components/common/Dropzone.svelte"
|
import Dropzone from "components/common/Dropzone.svelte"
|
||||||
import { capitalise } from "helpers"
|
import { capitalise } from "helpers"
|
||||||
import LinkedRowSelector from "components/common/LinkedRowSelector.svelte"
|
import LinkedRowSelector from "components/common/LinkedRowSelector.svelte"
|
||||||
|
import Editor from "../../integration/QueryEditor.svelte"
|
||||||
|
|
||||||
export let defaultValue
|
export let defaultValue
|
||||||
export let meta
|
export let meta
|
||||||
export let value = defaultValue || (meta.type === "boolean" ? false : "")
|
export let value = defaultValue || (meta.type === "boolean" ? false : "")
|
||||||
export let readonly
|
export let readonly
|
||||||
|
|
||||||
|
$: stringVal =
|
||||||
|
typeof value === "object" ? JSON.stringify(value, null, 2) : value
|
||||||
$: type = meta?.type
|
$: type = meta?.type
|
||||||
$: label = meta.name ? capitalise(meta.name) : ""
|
$: label = meta.name ? capitalise(meta.name) : ""
|
||||||
</script>
|
</script>
|
||||||
|
@ -40,6 +44,14 @@
|
||||||
<LinkedRowSelector bind:linkedRows={value} schema={meta} />
|
<LinkedRowSelector bind:linkedRows={value} schema={meta} />
|
||||||
{:else if type === "longform"}
|
{:else if type === "longform"}
|
||||||
<TextArea {label} bind:value />
|
<TextArea {label} bind:value />
|
||||||
|
{:else if type === "json"}
|
||||||
|
<Label>{label}</Label>
|
||||||
|
<Editor
|
||||||
|
editorHeight="250"
|
||||||
|
mode="json"
|
||||||
|
on:change={({ detail }) => (value = detail.value)}
|
||||||
|
value={stringVal}
|
||||||
|
/>
|
||||||
{:else}
|
{:else}
|
||||||
<Input
|
<Input
|
||||||
{label}
|
{label}
|
||||||
|
|
|
@ -67,6 +67,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatcher("save", { schema, json })
|
dispatcher("save", { schema, json })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,13 @@ exports.validate = async ({ appId, tableId, row, table }) => {
|
||||||
errors[fieldName] = "Field not in list"
|
errors[fieldName] = "Field not in list"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
} else if (type === FieldTypes.JSON && typeof row[fieldName] === "string") {
|
||||||
|
// this should only happen if there is an error
|
||||||
|
try {
|
||||||
|
JSON.parse(row[fieldName])
|
||||||
|
} catch (err) {
|
||||||
|
errors[fieldName] = [`Contains invalid JSON`]
|
||||||
|
}
|
||||||
} else if (type === FieldTypes.FORMULA) {
|
} else if (type === FieldTypes.FORMULA) {
|
||||||
res = validateJs.single(
|
res = validateJs.single(
|
||||||
processStringSync(table.schema[fieldName].formula, row),
|
processStringSync(table.schema[fieldName].formula, row),
|
||||||
|
|
Loading…
Reference in New Issue