From 925365b24558eab9b826d6c6f1e422332c49825a Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Fri, 13 Nov 2026 14:42:10 +1100 Subject: [PATCH] refactor(ui): one input spec type and parser for workflow inputs and outputs (#1958) --- ui/src/workflows/BindEvent.vue | 5 ++--- ui/src/workflows/ScheduleTrigger.vue | 5 ++--- ui/src/workflows/SpecList.vue | 6 +++--- ui/src/workflows/StepEditor.vue | 11 +++++------ ui/src/workflows/bind-event.ts | 5 +---- ui/src/workflows/workflow-edit.ts | 11 +++++++++++ 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/ui/src/workflows/BindEvent.vue b/ui/src/workflows/BindEvent.vue index 0e80515d5..ce0df1855 100644 --- a/ui/src/workflows/BindEvent.vue +++ b/ui/src/workflows/BindEvent.vue @@ -33,10 +33,9 @@ import { rowsFromBinding, shortValue, type InputRow, - type InputSpec, } from "./bind-event"; import OptionSelect from "@/components/OptionSelect.vue"; -import { workflowField } from "./workflow-edit"; +import { declaredSpecs, workflowField } from "./workflow-edit"; const props = defineProps<{ yaml: string; binding: Binding | null }>(); const emit = defineEmits<{ back: []; saved: [] }>(); @@ -44,7 +43,7 @@ const emit = defineEmits<{ back: []; saved: [] }>(); const NEW_SOURCE = "__new__"; const workflow = computed(() => String(workflowField(props.yaml, "id") ?? "")); const inputs = computed(() => - Object.entries((workflowField(props.yaml, "inputs") as Record | undefined) ?? {}), + declaredSpecs(props.yaml, "inputs"), ); const repository = computed(() => takesRepository({ id: "", name: "", repository: String(workflowField(props.yaml, "repository") ?? "") || undefined })); diff --git a/ui/src/workflows/ScheduleTrigger.vue b/ui/src/workflows/ScheduleTrigger.vue index a8ea8fe56..2f0edb529 100644 --- a/ui/src/workflows/ScheduleTrigger.vue +++ b/ui/src/workflows/ScheduleTrigger.vue @@ -24,9 +24,8 @@ import { errors } from "@/copy/errors"; import { constantValue, statusKind, statusLabel, type Binding, type InputSource } from "@/bindings/binding-draft"; import ScheduleEditor from "@/schedules/ScheduleEditor.vue"; import { blankSchedule, type Schedule } from "@/schedules/schedule"; -import type { InputSpec } from "./bind-event"; import OptionSelect from "@/components/OptionSelect.vue"; -import { workflowField } from "./workflow-edit"; +import { declaredSpecs, workflowField } from "./workflow-edit"; import { SCHEDULE_FIELDS, SCHEDULE_MAPPING, SCHEDULE_SOURCE, scheduleFilter, scheduleOfBinding } from "./workflow-triggers"; /** @@ -40,7 +39,7 @@ const NEW = "__new__"; const FIXED = "__fixed__"; const workflow = computed(() => String(workflowField(props.yaml, "id") ?? "")); const inputs = computed(() => - Object.entries((workflowField(props.yaml, "inputs") as Record | undefined) ?? {}), + declaredSpecs(props.yaml, "inputs"), ); const schedules = ref([]); diff --git a/ui/src/workflows/SpecList.vue b/ui/src/workflows/SpecList.vue index dabad3ed0..8554e634c 100644 --- a/ui/src/workflows/SpecList.vue +++ b/ui/src/workflows/SpecList.vue @@ -7,16 +7,16 @@ import { Input } from "@/components/ui/input"; import { Switch } from "@/components/ui/switch"; import OptionSelect from "@/components/OptionSelect.vue"; import { errors } from "../copy/errors/index.ts"; -import { setWorkflowField, workflowField } from "./workflow-edit"; +import { declaredSpecs, setWorkflowField, type InputSpec } from "./workflow-edit"; // A workflow's declared inputs or outputs: name, type and whether required. const props = defineProps<{ yaml: string; field: "inputs" | "outputs" }>(); const emit = defineEmits<{ "update:yaml": [string] }>(); -type Spec = { type?: string; required?: boolean }; +type Spec = InputSpec; const TYPES = ["string", "number", "bool", "object", "array", "any"].map((value) => ({ value, label: value })); -const list = computed(() => Object.entries((workflowField(props.yaml, props.field) as Record | undefined) ?? {})); +const list = computed(() => declaredSpecs(props.yaml, props.field)); function write(entries: [string, Spec][]): void { emit("update:yaml", setWorkflowField(props.yaml, props.field, Object.fromEntries(entries.filter(([name]) => name)))); } diff --git a/ui/src/workflows/StepEditor.vue b/ui/src/workflows/StepEditor.vue index d3340bb7e..df566f69f 100644 --- a/ui/src/workflows/StepEditor.vue +++ b/ui/src/workflows/StepEditor.vue @@ -13,9 +13,8 @@ import { Input } from "@/components/ui/input"; import { SuggestInput } from "@/components/ui/suggest-input"; import { Switch } from "@/components/ui/switch"; import { Textarea } from "@/components/ui/textarea"; -import { addBranch, branchingOf, deleteBranch, renameBranch, earlierStepIDs, replaceStep, stepAt, workflowField, type StepPath, type StepRecord } from "./workflow-edit"; +import { addBranch, branchingOf, deleteBranch, renameBranch, earlierStepIDs, replaceStep, stepAt, declaredSpecs, type InputSpec, type StepPath, type StepRecord } from "./workflow-edit"; import type { WorkflowDefinitionEntry } from "@/stores/workflows"; -import type { InputSpec } from "./bind-event"; import { inputValue } from "@/tasks/work-request"; import OptionSelect from "@/components/OptionSelect.vue"; import WorkflowPicker from "./WorkflowPicker.vue"; @@ -115,10 +114,10 @@ function setTarget(key: string, value: string): void { write({ ...step.value, settings: next }); } const callee = computed(() => props.workflows.find((entry) => entry.id === settings.value.workflow)); -const callInputs = computed(() => Object.entries((workflowField(callee.value?.yaml ?? "", "inputs") ?? {}) as Record)); -const callOutputs = computed(() => Object.entries((workflowField(callee.value?.yaml ?? "", "outputs") ?? {}) as Record)); -const callerInputs = computed(() => Object.entries((workflowField(props.yaml, "inputs") ?? {}) as Record)); -const callerOutputs = computed(() => Object.entries((workflowField(props.yaml, "outputs") ?? {}) as Record)); +const callInputs = computed(() => declaredSpecs(callee.value?.yaml ?? "", "inputs")); +const callOutputs = computed(() => declaredSpecs(callee.value?.yaml ?? "", "outputs")); +const callerInputs = computed(() => declaredSpecs(props.yaml, "inputs")); +const callerOutputs = computed(() => declaredSpecs(props.yaml, "outputs")); const inputMap = computed(() => (settings.value.inputs ?? {}) as Record); const outputMap = computed(() => (settings.value.outputs ?? {}) as Record); const isReference = (value: unknown) => typeof value === "string" && value.startsWith("inputs."); diff --git a/ui/src/workflows/bind-event.ts b/ui/src/workflows/bind-event.ts index 5a9c8d791..83a3bc9f4 100644 --- a/ui/src/workflows/bind-event.ts +++ b/ui/src/workflows/bind-event.ts @@ -1,6 +1,7 @@ import { constantValue, type Binding, type InputSource } from "../bindings/binding-draft.ts"; import type { Capture } from "@/captures/state"; import { errors } from "../copy/errors/index.ts"; +import type { InputSpec } from "./workflow-edit.ts"; import type { FieldType } from "@/mappings/mapping-fields"; import type { MappingField, Preview } from "@/mappings/state"; @@ -10,10 +11,6 @@ import type { MappingField, Preview } from "@/mappings/state"; * become the binding's mapping. */ -export interface InputSpec { - type?: string; - required?: boolean; -} /** How one input is filled: from a payload path, or a fixed value. */ export interface InputRow { diff --git a/ui/src/workflows/workflow-edit.ts b/ui/src/workflows/workflow-edit.ts index 405e56db8..584a3f0ae 100644 --- a/ui/src/workflows/workflow-edit.ts +++ b/ui/src/workflows/workflow-edit.ts @@ -252,6 +252,17 @@ function prune(value: unknown): unknown { return out; } +/** One declared input or output: its type and whether it is required. */ +export interface InputSpec { + type?: string; + required?: boolean; +} + +/** A workflow's declared inputs or outputs, in the order the YAML gives them. */ +export function declaredSpecs(source: string, field: "inputs" | "outputs"): [string, InputSpec][] { + return Object.entries((workflowField(source, field) as Record | undefined) ?? {}); +} + /** A top-level workflow field (repository, inputs, profile, ...) as plain data. */ export function workflowField(source: string, key: string): unknown { const value = parseDocument(source).get(key, true);