From 8e734b2d7245ce286af739720c6b96d90afde108 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Mon, 12 Feb 2024 15:25:00 +0000 Subject: [PATCH] frontend valiation for crons and fix preset null issue --- .../automation/SetupPanel/CronBuilder.svelte | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/builder/src/components/automation/SetupPanel/CronBuilder.svelte b/packages/builder/src/components/automation/SetupPanel/CronBuilder.svelte index ee9eed51e9..97b5e3cfd4 100644 --- a/packages/builder/src/components/automation/SetupPanel/CronBuilder.svelte +++ b/packages/builder/src/components/automation/SetupPanel/CronBuilder.svelte @@ -2,15 +2,31 @@ import { Button, Select, Input, Label } from "@budibase/bbui" import { onMount, createEventDispatcher } from "svelte" import { flags } from "stores/backend" - + import { helpers } from "@budibase/shared-core" const dispatch = createEventDispatcher() export let value + let error + + $: { + const exists = CRON_EXPRESSIONS.some(cron => cron.value === value) + const customIndex = CRON_EXPRESSIONS.findIndex( + cron => cron.label === "Custom" + ) + + if (!exists && customIndex === -1) { + CRON_EXPRESSIONS[0] = { label: "Custom", value: value } + } else if (exists && customIndex !== -1) { + CRON_EXPRESSIONS.splice(customIndex, 1) + } + } const onChange = e => { - if (e.detail === value) { + error = helpers.cron.validate(e.detail).err + if (e.detail === value || error) { return } + value = e.detail dispatch("change", e.detail) } @@ -49,6 +65,7 @@
(touched = true)} @@ -64,7 +81,7 @@ {#if presets}