From 17bca674a9730767c1a71812f7250cd430a84c04 Mon Sep 17 00:00:00 2001 From: Farhan Yahaya Date: Tue, 18 Nov 2025 23:34:13 +0000 Subject: [PATCH 1/3] fix: show expression form errors on switch --- .../components/inspector/EdgeForm.tsx | 14 ++++++++-- assets/js/collaborative-editor/types/edge.ts | 28 +++++++++---------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/assets/js/collaborative-editor/components/inspector/EdgeForm.tsx b/assets/js/collaborative-editor/components/inspector/EdgeForm.tsx index 9eb980b7fe..1cb1b9bb6b 100644 --- a/assets/js/collaborative-editor/components/inspector/EdgeForm.tsx +++ b/assets/js/collaborative-editor/components/inspector/EdgeForm.tsx @@ -1,5 +1,5 @@ import { useStore } from '@tanstack/react-form'; -import { useMemo } from 'react'; +import { useEffect, useMemo } from 'react'; import { useWorkflowActions, @@ -30,7 +30,10 @@ export function EdgeForm({ edge }: EdgeFormProps) { // Initialize form const form = useAppForm( { - defaultValues: edge, + defaultValues: { + ...edge, + condition_expression: edge.condition_expression || '', + }, listeners: { onChange: ({ formApi }) => { if (edge.id) { @@ -97,6 +100,13 @@ export function EdgeForm({ edge }: EdgeFormProps) { conditionExpression ); + // Trigger validation when switching to js_expression + useEffect(() => { + if (conditionType === 'js_expression') { + form.validateField('condition_expression', 'change'); + } + }, [conditionType, form]); + return (
{/* Label Field */} diff --git a/assets/js/collaborative-editor/types/edge.ts b/assets/js/collaborative-editor/types/edge.ts index 8bd7fca0a1..0e736d0f18 100644 --- a/assets/js/collaborative-editor/types/edge.ts +++ b/assets/js/collaborative-editor/types/edge.ts @@ -1,12 +1,12 @@ -import { z } from "zod"; +import { z } from 'zod'; -import { uuidSchema } from "./common"; +import { uuidSchema } from './common'; export const EdgeConditionType = z.enum([ - "on_job_success", - "on_job_failure", - "always", - "js_expression", + 'on_job_success', + 'on_job_failure', + 'always', + 'js_expression', ]); export const EdgeSchema = z @@ -23,15 +23,15 @@ export const EdgeSchema = z target_job_id: uuidSchema, // Condition configuration - condition_type: EdgeConditionType.default("on_job_success"), + condition_type: EdgeConditionType.default('on_job_success'), condition_expression: z .string() - .max(255, "should be at most 255 character(s)") - .nullable() - .optional(), + .trim() + .min(1, "can't be blank") + .max(255, 'should be at most 255 character(s)'), condition_label: z .string() - .max(255, "should be at most 255 character(s)") + .max(255, 'should be at most 255 character(s)') .nullable() .optional(), @@ -48,14 +48,14 @@ export const EdgeSchema = z .refine( data => { // Require expression when type is js_expression - if (data.condition_type === "js_expression") { - return !!data.condition_expression; + if (data.condition_type === 'js_expression') { + return !!data.condition_expression.trim(); } return true; }, { message: "can't be blank", - path: ["condition_expression"], + path: ['condition_expression'], } ); From 6f187f7a56426a87e7b93f32690edec333221ddd Mon Sep 17 00:00:00 2001 From: Farhan Yahaya Date: Tue, 18 Nov 2025 23:43:25 +0000 Subject: [PATCH 2/3] feat: update wording --- assets/js/collaborative-editor/types/edge.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/js/collaborative-editor/types/edge.ts b/assets/js/collaborative-editor/types/edge.ts index 0e736d0f18..e6217fbf29 100644 --- a/assets/js/collaborative-editor/types/edge.ts +++ b/assets/js/collaborative-editor/types/edge.ts @@ -27,7 +27,7 @@ export const EdgeSchema = z condition_expression: z .string() .trim() - .min(1, "can't be blank") + .min(1, "This field can't be blank") .max(255, 'should be at most 255 character(s)'), condition_label: z .string() @@ -54,7 +54,7 @@ export const EdgeSchema = z return true; }, { - message: "can't be blank", + message: "This field can't be blank", path: ['condition_expression'], } ); From c6c681c9d58e251b3db9e2eb6aad0fe04e50dfda Mon Sep 17 00:00:00 2001 From: Farhan Yahaya Date: Wed, 19 Nov 2025 02:57:59 +0000 Subject: [PATCH 3/3] chore: update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96dbeb34c4..914cac2be2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,9 @@ and this project adheres to ### Added +- Add validation for edge expressions + [#3704](https://github.com/OpenFn/lightning/issues/3704) + ### Changed - Default failure notifications for project users are now disabled to minimize