diff --git a/packages/builder/src/components/automation/SetupPanel/CronBuilder.svelte b/packages/builder/src/components/automation/SetupPanel/CronBuilder.svelte index ee9eed51e9..c731b0afb0 100644 --- a/packages/builder/src/components/automation/SetupPanel/CronBuilder.svelte +++ b/packages/builder/src/components/automation/SetupPanel/CronBuilder.svelte @@ -2,15 +2,34 @@ import { Button, Select, Input, Label } from "@budibase/bbui" import { onMount, createEventDispatcher } from "svelte" import { flags } from "stores/backend" + import { helpers, REBOOT_CRON } 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) { + if (value !== REBOOT_CRON) { + error = helpers.cron.validate(e.detail).err + } + if (e.detail === value || error) { return } + value = e.detail dispatch("change", e.detail) } @@ -41,7 +60,7 @@ if (!$flags.cloud) { CRON_EXPRESSIONS.push({ label: "Every Budibase Reboot", - value: "@reboot", + value: REBOOT_CRON, }) } }) @@ -49,6 +68,7 @@
(touched = true)} @@ -64,7 +84,7 @@ {#if presets}