From d3ce5e2d61952a0deec20662c526b937537bc1e6 Mon Sep 17 00:00:00 2001 From: Taylor Ho Date: Fri, 14 Aug 2026 16:04:30 -0700 Subject: [PATCH] Open the first workflow condition by default Signed-off-by: Taylor Ho --- .../workflows/ui/WorkflowConditionBuilder.tsx | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/desktop/src/features/workflows/ui/WorkflowConditionBuilder.tsx b/desktop/src/features/workflows/ui/WorkflowConditionBuilder.tsx index 66990df49..426f2db49 100644 --- a/desktop/src/features/workflows/ui/WorkflowConditionBuilder.tsx +++ b/desktop/src/features/workflows/ui/WorkflowConditionBuilder.tsx @@ -104,6 +104,28 @@ function initialEditorState( return { custom: value.trim().length > 0, editors: [] }; } +function initialActiveEditor( + editorState: ConditionEditorState, + triggerType: TriggerType, +): ActiveConditionEditor | null { + if (editorState.custom) return null; + + const firstField = conditionFieldsForTrigger(triggerType)[0]; + if (!firstField) return null; + + return { + kind: "field", + draft: editorState.editors.find( + (editor) => editor.field === firstField.value, + ) ?? { + field: firstField.value, + operator: defaultConditionOperatorForField(firstField.value), + value: "", + webhookField: "", + }, + }; +} + function valueLabel(field: string): string { switch (field) { case "trigger_author": @@ -508,7 +530,10 @@ export function WorkflowConditionBuilder({ ); const [advancedDraft, setAdvancedDraft] = React.useState(value); const [activeEditor, setActiveEditor] = - React.useState(null); + React.useState(() => { + const initialState = initialEditorState(value, triggerType); + return initialActiveEditor(initialState, triggerType); + }); const [pendingBasicField, setPendingBasicField] = React.useState< (typeof fields)[number] | null >(null); @@ -549,7 +574,7 @@ export function WorkflowConditionBuilder({ setEditorState(nextEditorState); setEditorMode(nextEditorState.custom ? "advanced" : "basic"); setAdvancedDraft(value); - setActiveEditor(null); + setActiveEditor(initialActiveEditor(nextEditorState, triggerType)); setPendingBasicField(null); }, [triggerType, value]);