1
0
Fork 0
mirror of synced 2024-06-29 11:31:06 +12:00

update how we handle coercion of types

This commit is contained in:
Peter Clement 2022-02-11 14:20:25 +00:00
parent 0affc0d0c2
commit bb5ad1c2bf
3 changed files with 32 additions and 13 deletions

View file

@ -11,6 +11,8 @@
ActionButton,
notifications,
Modal,
Toggle,
Tooltip,
} from "@budibase/bbui"
import ConfigModal from "./ConfigModal.svelte"
@ -22,6 +24,7 @@
let blocks
let confirmDeleteDialog
$: rowControl = $automationStore.selectedAutomation.automation.rowControl
$: {
blocks = []
if (automation) {
@ -32,6 +35,13 @@
}
}
function toggleFieldControl(evt) {
automationStore.actions.toggleFieldControl(evt.detail)
automationStore.actions.save(
$automationStore.selectedAutomation?.automation
)
}
async function deleteAutomation() {
await automationStore.actions.delete(
$automationStore.selectedAutomation?.automation
@ -61,16 +71,11 @@
<div class="title">
<div class="subtitle">
<Heading size="S">{automation.name}</Heading>
<div style="display:flex;">
<div style="display:flex; align-items: center;">
<div class="iconPadding">
<div class="icon">
<Icon
hoverable
size="M"
on:click={configModal.show}
name="Settings"
/>
</div>
<Tooltip direction="left" text="Allow binding to all inputs">
<Toggle bind:value={rowControl} on:change={toggleFieldControl} />
</Tooltip>
</div>
<div class="iconPadding">
<div class="icon">

View file

@ -20,7 +20,7 @@
boolean: "true",
datetime: "2022-02-16T12:00:00.000Z ",
options: "1",
array: "1,2,3,4",
array: "1 2 3 4",
link: "ro_ta_123_456",
longform: "long form text",
}
@ -43,19 +43,32 @@
const coerce = (value, type) => {
if (type === "boolean") {
if (typeof value === "boolean") {
return value
}
return value === "true"
}
if (type === "number") {
if (typeof value === "number") {
return value
}
return Number(value)
}
if (type === "options") {
return [value]
}
if (type === "array") {
return value.split(",")
if (Array.isArray(value)) {
return value
}
return value.split(",").map(x => x.trim())
}
if (type === "link") {
if (Array.isArray(value)) {
return value
}
return [value]
}
@ -102,6 +115,7 @@
type={value.customType}
on:change={e => onChange(e, field, schema.type)}
{bindings}
allowJS={true}
/>
{/if}
{:else if $automationStore.selectedAutomation.automation.rowControl}
@ -116,7 +130,7 @@
type="string"
{bindings}
fillWidth={true}
allowJS={false}
allowJS={true}
/>
{/if}
{/if}

View file

@ -59,6 +59,6 @@
type="string"
{bindings}
fillWidth={true}
allowJS={false}
allowJS={true}
/>
{/if}