diff --git a/frontend/app/new/job/define/page.tsx b/frontend/app/new/job/define/page.tsx index a5e44a0fb7..d319b5e99a 100644 --- a/frontend/app/new/job/define/page.tsx +++ b/frontend/app/new/job/define/page.tsx @@ -14,6 +14,7 @@ import { FormMessage, } from '@/components/ui/form'; import { Input } from '@/components/ui/input'; +import { Switch } from '@/components/ui/switch'; import { yupResolver } from '@hookform/resolvers/yup'; import NeoCron from 'neocron'; import 'neocron/dist/src/globals.css'; @@ -37,17 +38,19 @@ export default function Page({ searchParams }: PageProps): ReactElement { } }, [searchParams?.sessionId]); + const defaultCronString = '0 0 * * *'; //by default runs every day + const sessionPrefix = searchParams?.sessionId ?? ''; const [defaultValues] = useSessionStorage( `${sessionPrefix}-new-job-define`, { jobName: '', - cronSchedule: '* * * * *', + cronSchedule: '', initiateJobRun: false, } ); - const form = useForm({ + const form = useForm({ resolver: yupResolver(DEFINE_FORM_SCHEMA), defaultValues, }); @@ -63,6 +66,9 @@ export default function Page({ searchParams }: PageProps): ReactElement { const newJobType = getNewJobType(getSingleOrUndefined(searchParams?.jobType)); async function onSubmit(_values: DefineFormValues) { + if (disableSchedule) { + form.setValue('cronSchedule', ''); + } if (newJobType === 'generate-table') { router.push( `/new/job/generate/single/connect?sessionId=${sessionPrefix}` @@ -78,6 +84,8 @@ export default function Page({ searchParams }: PageProps): ReactElement { setIsClient(true); }, []); + const [disableSchedule, setDisableSchedule] = useState(true); + return (
)} /> + +
+
+
{isClient && ( ( - Schedule +
+ Schedule + { + disableSchedule + ? setDisableSchedule(false) + : setDisableSchedule(true); + }} + /> +
- Define a schedule to run this job. + Define a schedule to run this job. If disabled, job will + need to be manually triggered. - + {!disableSchedule && ( + + )}
diff --git a/frontend/app/new/job/schema.ts b/frontend/app/new/job/schema.ts index 9dbdecac6c..835d7b19f9 100644 --- a/frontend/app/new/job/schema.ts +++ b/frontend/app/new/job/schema.ts @@ -6,7 +6,6 @@ import { SCHEMA_FORM_SCHEMA, SOURCE_FORM_SCHEMA, } from '@/yup-validations/jobs'; -import cron from 'cron-validate'; import * as Yup from 'yup'; export const DEFINE_FORM_SCHEMA = Yup.object({ @@ -26,14 +25,7 @@ export const DEFINE_FORM_SCHEMA = Yup.object({ const res = await isJobNameAvailable(value, account.id); return res.isAvailable; }), - cronSchedule: Yup.string() - .optional() - .test('isValidCron', 'Not a valid cron schedule', (value) => { - if (!value) { - return true; - } - return !!value && cron(value).isValid(); - }), + cronSchedule: Yup.string().optional(), initiateJobRun: Yup.boolean(), });