feat(ui): lanes for parallel and switch steps on the workflow canvas
This commit is contained in:
1 parent
79d7f2fa68
commit
522ced45ff
14 files changed
+264
-138
No files matched your search
@@ -9,7 +9,7 @@ import { Input } from "@/components/ui/input";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { stepIcon } from "./step-icons";
|
||||
import { addBranch, deleteBranch, renameBranch, earlierStepIDs, replaceStep, stepAt, workflowField, type StepPath, type StepRecord } from "./workflow-edit";
|
||||
import { addBranch, branchingOf, deleteBranch, renameBranch, earlierStepIDs, replaceStep, stepAt, workflowField, type StepPath, type StepRecord } from "./workflow-edit";
|
||||
import type { WorkflowDefinitionEntry } from "@/stores/control-plane";
|
||||
import type { InputSpec } from "./bind-event";
|
||||
import { inputValue } from "./work-request";
|
||||
@@ -21,8 +21,13 @@ const props = defineProps<{ yaml: string; path: StepPath; vocabulary: StepTypeIn
|
||||
const emit = defineEmits<{ "update:yaml": [string]; close: []; remove: [] }>();
|
||||
|
||||
const step = computed<StepRecord>(() => stepAt(props.yaml, props.path) ?? {});
|
||||
const type = computed(() => step.value.parallel ? "parallel" : typeof step.value.type === "string" ? step.value.type : "");
|
||||
const branches = computed(() => Object.keys((step.value.parallel ?? {}) as Record<string, unknown>));
|
||||
const branching = computed(() => branchingOf(step.value));
|
||||
const type = computed(() => branching.value?.kind ?? (typeof step.value.type === "string" ? step.value.type : ""));
|
||||
const branches = computed(() => branching.value?.branches.map(([name]) => name) ?? []);
|
||||
const minBranches = computed(() => (type.value === "parallel" ? 2 : 1));
|
||||
function setOn(on: string): void {
|
||||
emit("update:yaml", replaceStep(props.yaml, props.path, { ...step.value, switch: { ...(step.value.switch as StepRecord), on } }));
|
||||
}
|
||||
const newBranch = ref("");
|
||||
const branchError = ref("");
|
||||
function changeBranch(action: "add" | "rename" | "delete", name: string, next = ""): void {
|
||||
@@ -160,15 +165,22 @@ const text = (key: string) => (typeof settings.value[key] === "string" ? (settin
|
||||
<div class="flex-1 space-y-5 overflow-y-auto px-4 py-4">
|
||||
<p v-if="problem" class="rounded-md bg-danger/10 px-2.5 py-1.5 text-xs text-danger" role="alert">{{ problem }}</p>
|
||||
|
||||
<section v-if="type === 'parallel'" class="space-y-3">
|
||||
<div class="text-xs font-medium text-muted-foreground">Branches</div>
|
||||
<section v-if="branching" class="space-y-3">
|
||||
<template v-if="type === 'switch'">
|
||||
<label class="block space-y-1.5">
|
||||
<span class="text-xs font-medium text-muted-foreground" title="The value whose case runs; a case named default runs when none matches">Switch on</span>
|
||||
<Input :model-value="branching.on" class="font-mono" placeholder="steps.assess.result.fit" list="switch-on" @change="setOn(($event.target as HTMLInputElement).value.trim())" />
|
||||
<datalist id="switch-on"><option v-for="id in earlier" :key="id" :value="`steps.${id}.result.`" /></datalist>
|
||||
</label>
|
||||
</template>
|
||||
<div class="text-xs font-medium text-muted-foreground">{{ type === "switch" ? "Cases" : "Branches" }}</div>
|
||||
<div v-for="name in branches" :key="name" class="flex items-center gap-2">
|
||||
<Input :model-value="name" :aria-label="`Branch ${name}`" @change="changeBranch('rename', name, ($event.target as HTMLInputElement).value.trim())" />
|
||||
<Button type="button" variant="ghost" size="icon-sm" :aria-label="`Remove branch ${name}`" :disabled="branches.length <= 2" title="Parallel needs at least two branches" @click="changeBranch('delete', name)"><Trash2 /></Button>
|
||||
<Input :model-value="name" :class="type === 'switch' && 'font-mono'" :aria-label="`${type === 'switch' ? 'Case' : 'Branch'} ${name}`" @change="changeBranch('rename', name, ($event.target as HTMLInputElement).value.trim())" />
|
||||
<Button type="button" variant="ghost" size="icon-sm" :aria-label="`Remove ${name}`" :disabled="branches.length <= minBranches" @click="changeBranch('delete', name)"><Trash2 /></Button>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<Input v-model="newBranch" aria-label="New branch name" placeholder="Branch name" @keydown.enter.prevent="changeBranch('add', newBranch.trim())" />
|
||||
<Button type="button" size="icon-sm" variant="outline" aria-label="Add branch" :disabled="!newBranch.trim()" @click="changeBranch('add', newBranch.trim())"><Plus /></Button>
|
||||
<Input v-model="newBranch" :aria-label="type === 'switch' ? 'New case value' : 'New branch name'" :placeholder="type === 'switch' ? 'Value, or default' : 'Branch name'" @keydown.enter.prevent="changeBranch('add', newBranch.trim())" />
|
||||
<Button type="button" size="icon-sm" variant="outline" :aria-label="type === 'switch' ? 'Add case' : 'Add branch'" :disabled="!newBranch.trim()" @click="changeBranch('add', newBranch.trim())"><Plus /></Button>
|
||||
</div>
|
||||
<p v-if="branchError" role="alert" class="text-xs text-danger">{{ branchError }}</p>
|
||||
</section>
|
||||
|
||||
Reference in new issue
Block a user