refactor(ui): one input spec type and parser for workflow inputs and outputs (#1958)
This commit is contained in:
6 files changed
+24
-19
No files matched your search
@@ -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<string, InputSpec> | undefined) ?? {}),
|
||||
declaredSpecs(props.yaml, "inputs"),
|
||||
);
|
||||
const repository = computed(() => takesRepository({ id: "", name: "", repository: String(workflowField(props.yaml, "repository") ?? "") || undefined }));
|
||||
|
||||
|
||||
@@ -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<string, InputSpec> | undefined) ?? {}),
|
||||
declaredSpecs(props.yaml, "inputs"),
|
||||
);
|
||||
|
||||
const schedules = ref<Schedule[]>([]);
|
||||
|
||||
@@ -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<string, Spec> | 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))));
|
||||
}
|
||||
|
||||
@@ -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<string, InputSpec>));
|
||||
const callOutputs = computed(() => Object.entries((workflowField(callee.value?.yaml ?? "", "outputs") ?? {}) as Record<string, InputSpec>));
|
||||
const callerInputs = computed(() => Object.entries((workflowField(props.yaml, "inputs") ?? {}) as Record<string, InputSpec>));
|
||||
const callerOutputs = computed(() => Object.entries((workflowField(props.yaml, "outputs") ?? {}) as Record<string, InputSpec>));
|
||||
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<string, unknown>);
|
||||
const outputMap = computed(() => (settings.value.outputs ?? {}) as Record<string, string>);
|
||||
const isReference = (value: unknown) => typeof value === "string" && value.startsWith("inputs.");
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<string, InputSpec> | 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);
|
||||
|
||||
Reference in new issue
Block a user