Require required schema fields before saving

This commit is contained in:
Peter Clement 2021-09-13 15:50:46 +01:00
parent d86c238d53
commit 82db0950c3
8 changed files with 57 additions and 40 deletions

View File

@ -94,7 +94,6 @@ const automationActions = store => ({
addTestDataToAutomation: data => {
store.update(state => {
state.selectedAutomation.addTestData(data)
console.log(state)
return state
})
},

View File

@ -0,0 +1,14 @@
import DiscordLogo from "assets/discord.svg"
import ZapierLogo from "assets/zapier.png"
import IntegromatLogo from "assets/integromat.png"
import SlackLogo from "assets/slack.svg"
import n8nlogo from "assets/n8nlogo.png"
export const externalActions = {
zapier: { name: "zapier", icon: ZapierLogo },
discord: { name: "discord", icon: DiscordLogo },
slack: { name: "slack", icon: SlackLogo },
integromat: { name: "integromat", icon: IntegromatLogo },
n8n:{ name: "n8n", icon: n8nlogo },
}

View File

@ -15,6 +15,7 @@
import ResultsModal from "./ResultsModal.svelte"
import ActionModal from "./ActionModal.svelte"
import { database } from "stores/backend"
import { externalActions } from "./ExternalActions"
export let onSelect
export let block
@ -70,6 +71,14 @@
class="splitHeader"
>
<div style="display: flex;">
{#if externalActions[block.stepId]}
<img
alt={externalActions[block.stepId].name}
width="35px"
height="35px"
src={externalActions[block.stepId].icon}
/>
{:else}
<svg
width="35px"
height="35px"
@ -79,6 +88,7 @@
>
<use xlink:href="#spectrum-icon-18-{block.icon}" />
</svg>
{/if}
<div class="iconAlign">
<Body size="XS">When this happens:</Body>

View File

@ -16,9 +16,7 @@
}
// get the outputs so we can define the fields
let schemaProperties = Object.entries(
trigger.schema?.outputs?.properties || {}
)
let schemaProperties = Object.entries(trigger.schema.outputs.properties || {})
// check to see if there is existing test data in the store
$: testData = Object.keys(
@ -27,6 +25,11 @@
? $automationStore.selectedAutomation.automation.testData
: {}
// Checj the schema to see if required fields have been entered
$: isError = !trigger.schema.outputs.required.every(
required => testData[required]
)
function parseTestJSON(e) {
try {
const obj = JSON.parse(e.detail)
@ -42,7 +45,9 @@
title="Add test data"
confirmText="Save"
showConfirmButton={true}
disabled={isError}
onConfirm={() => {
automationStore.actions.addTestDataToAutomation(testData)
automationStore.actions.trigger(
$automationStore.selectedAutomation,
testData
@ -53,7 +58,7 @@
<Tabs selected="Form" quiet
><Tab icon="Form" title="Form"
><AutomationBlockSetup
{testData}
bind:testData
{schemaProperties}
block={trigger}
/></Tab

View File

@ -30,7 +30,7 @@
$: inputData = testData ? testData : block.inputs
const debouncedOnChange = debounce(async function (e, key) {
async function onChange(e, key) {
if (testData) {
testData[key] = e.detail
} else {
@ -40,7 +40,7 @@
automation: $automationStore.selectedAutomation?.automation,
})
}
}, 800)
}
function getAvailableBindings(block, automation) {
if (!block || !automation) {
@ -80,7 +80,7 @@
<Label>{value.title || key}</Label>
{#if value.type === "string" && value.enum}
<Select
on:change={e => debouncedOnChange(e, key)}
on:change={e => onChange(e, key)}
value={inputData[key]}
options={value.enum}
getOptionLabel={(x, idx) => (value.pretty ? value.pretty[idx] : x)}
@ -88,7 +88,7 @@
{:else if value.customType === "password"}
<Input
type="password"
on:change={e => debouncedOnChange(e, key)}
on:change={e => onChange(e, key)}
value={inputData[key]}
/>
{:else if value.customType === "email"}
@ -98,7 +98,7 @@
value={inputData[key]}
panel={AutomationBindingPanel}
type="email"
on:change={e => debouncedOnChange(e, key)}
on:change={e => onChange(e, key)}
{bindings}
/>
{:else}
@ -107,51 +107,45 @@
panel={AutomationBindingPanel}
type="email"
value={inputData[key]}
on:change={e => debouncedOnChange(e, key)}
on:change={e => onChange(e, key)}
{bindings}
/>
{/if}
{:else if value.customType === "query"}
<QuerySelector
on:change={e => debouncedOnChange(e, key)}
on:change={e => onChange(e, key)}
value={inputData[key]}
/>
{:else if value.customType === "cron"}
<CronBuilder
on:change={e => debouncedOnChange(e, key)}
value={inputData[key]}
/>
<CronBuilder on:change={e => onChange(e, key)} value={inputData[key]} />
{:else if value.customType === "queryParams"}
<QueryParamSelector
on:change={e => debouncedOnChange(e, key)}
on:change={e => onChange(e, key)}
value={inputData[key]}
{bindings}
/>
{:else if value.customType === "table"}
<TableSelector
value={inputData[key]}
on:change={e => debouncedOnChange(e, key)}
on:change={e => onChange(e, key)}
/>
{:else if value.customType === "row"}
<RowSelector
value={inputData[key]}
on:change={e => debouncedOnChange(e, key)}
on:change={debounce(e => onChange(e, key), 800)}
{bindings}
/>
{:else if value.customType === "webhookUrl"}
<WebhookDisplay value={inputData[key]} />
{:else if value.customType === "triggerSchema"}
<SchemaSetup
on:change={e => debouncedOnChange(e, key)}
value={value[key]}
/>
<SchemaSetup on:change={e => onChange(e, key)} value={value[key]} />
{:else if value.customType === "code"}
<CodeEditorModal>
<pre>{JSON.stringify(bindings, null, 2)}</pre>
<Editor
mode="javascript"
on:change={e => {
debouncedOnChange(e, key)
onChange(e, key)
inputData[key] = e.detail.value
}}
value={inputData[key]}
@ -164,7 +158,7 @@
value={inputData[key]}
panel={AutomationBindingPanel}
type={value.customType}
on:change={e => debouncedOnChange(e, key)}
on:change={e => onChange(e, key)}
{bindings}
/>
{:else}
@ -173,7 +167,7 @@
panel={AutomationBindingPanel}
type={value.customType}
value={inputData[key]}
on:change={e => debouncedOnChange(e, key)}
on:change={e => onChange(e, key)}
{bindings}
/>
{/if}

View File

@ -10,9 +10,6 @@
$: instanceId = $database._id
$: automation = $automationStore.selectedAutomation?.automation
$: automationLive = automation?.live
$: console.log(
$automationStore.selectedBlock.definition.trigger.schema.outputs.properties
)
function setAutomationLive(live) {
if (automationLive === live) {
return

View File

@ -7,7 +7,6 @@
m => m._id === $params.automation
)
if (automation) {
console.log(automation)
automationStore.actions.select(automation)
}
}

View File

@ -7,7 +7,6 @@
$: automation = $automationStore.automations[0]
let modal
let webhookModal
$: console.log(automation)
</script>
<!-- routify:options index=3 -->