feat(workflow): serve step type titles with the step vocabulary (#1961)
Each step type declares its title beside its factory and settings; the control plane serves it in x-step-types, and the dashboard reads it instead of a hand-written TYPE_TITLES table. Parallel and switch are YAML shapes, not registered types, so their titles stay with the graph.
This commit is contained in:
19 files changed
+72
-75
No files matched your search
@@ -7,6 +7,7 @@ import { CircleAlert, CircleCheck, CircleMinus, CircleX, EllipsisVertical, Flag,
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { duration } from "@/lib/format";
|
||||
import { useWorkflowsStore } from "@/stores/workflows";
|
||||
import { stepIcon } from "./step-icons";
|
||||
import { stepTitle, type StepNodeData } from "./workflow-graph";
|
||||
|
||||
@@ -72,10 +73,11 @@ const status = computed(() => {
|
||||
return null;
|
||||
});
|
||||
|
||||
const workflows = useWorkflowsStore();
|
||||
const badge = computed(() => {
|
||||
if (props.data.kind === "start") return { icon: Play, label: "Trigger" };
|
||||
if (props.data.kind === "workflow") return { icon: Settings2, label: "Workflow" };
|
||||
return { icon: stepIcon(props.data.type), label: stepTitle(props.data.type) };
|
||||
return { icon: stepIcon(props.data.type), label: stepTitle(props.data.type, workflows.stepTypes) };
|
||||
});
|
||||
const number = computed(() => (props.data.step ? `${Number(props.data.step)}.` : ""));
|
||||
|
||||
@@ -150,7 +152,7 @@ function commitRename(event: Event): void {
|
||||
:model-value="data.name ?? ''"
|
||||
class="nodrag nopan h-6 px-1 text-label"
|
||||
aria-label="Step id"
|
||||
:placeholder="stepTitle(data.type)"
|
||||
:placeholder="stepTitle(data.type, workflows.stepTypes)"
|
||||
@click.stop
|
||||
@keydown.enter.prevent="commitRename"
|
||||
@keydown.esc="renaming = false; data.onRenameDone?.()"
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
DropdownMenuSubContent,
|
||||
DropdownMenuSubTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { useWorkflowsStore } from "@/stores/workflows";
|
||||
import { stepGroups } from "./step-icons";
|
||||
import { stepTitle } from "./workflow-graph";
|
||||
|
||||
@@ -15,6 +16,8 @@ const props = defineProps<{ types: string[] }>();
|
||||
const emit = defineEmits<{ pick: [string] }>();
|
||||
|
||||
const groups = computed(() => stepGroups(props.types));
|
||||
const workflows = useWorkflowsStore();
|
||||
const titleOf = (type: string) => stepTitle(type, workflows.stepTypes);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -24,7 +27,7 @@ const groups = computed(() => stepGroups(props.types));
|
||||
<!-- A group of one is its step: no submenu to open for a single choice. -->
|
||||
<DropdownMenuItem v-if="group.types.length === 1" @select="emit('pick', group.types[0])">
|
||||
<component :is="group.icon" />
|
||||
{{ stepTitle(group.types[0]) }}
|
||||
{{ titleOf(group.types[0]) }}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSub v-else>
|
||||
<DropdownMenuSubTrigger>
|
||||
@@ -33,7 +36,7 @@ const groups = computed(() => stepGroups(props.types));
|
||||
</DropdownMenuSubTrigger>
|
||||
<DropdownMenuSubContent class="w-52">
|
||||
<DropdownMenuItem v-for="type in group.types" :key="type" @select="emit('pick', type)">
|
||||
{{ stepTitle(type) }}
|
||||
{{ titleOf(type) }}
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuSubContent>
|
||||
</DropdownMenuSub>
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip
|
||||
import { computed, nextTick, ref, watch } from "vue";
|
||||
import { Handle, Position, VueFlow, type NodeMouseEvent, type VueFlowStore } from "@vue-flow/core";
|
||||
import { Background } from "@vue-flow/background";
|
||||
import { useWorkflowsStore } from "@/stores/workflows";
|
||||
import { useMediaQuery, usePreferredReducedMotion, useResizeObserver, useTransition } from "@vueuse/core";
|
||||
import { ArrowDown, ArrowUp, Copy, GitBranch, Maximize, Minus, Pencil, Plus, RotateCcw, Split, Trash2 } from "@lucide/vue";
|
||||
import "@vue-flow/core/dist/style.css";
|
||||
@@ -69,8 +70,9 @@ const keyOf = (data: StepNodeData) => (data.kind === "step" ? JSON.stringify(dat
|
||||
const container = ref<HTMLElement | null>(null);
|
||||
const viewport = ref<HTMLElement | null>(null);
|
||||
const phone = useMediaQuery("(max-width: 767px)");
|
||||
const workflows = useWorkflowsStore();
|
||||
const graph = computed(() => {
|
||||
const laid = withRuns(workflowGraph(props.yaml), props.stages ?? []);
|
||||
const laid = withRuns(workflowGraph(props.yaml, workflows.stepTypes), props.stages ?? []);
|
||||
if (!props.types?.length) return laid;
|
||||
// Workflow-wide settings sit on a card above the trigger.
|
||||
const workflow: GraphNode = { id: "workflow", type: "step", position: { x: 0, y: TOP }, data: { kind: "workflow", key: "workflow", title: "Settings", type: "", detail: props.summary ?? "" } };
|
||||
@@ -382,7 +384,7 @@ const beforePath = computed(() => menuPath.value ? [...menuPath.value.slice(0, -
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent class="w-56" align="start">
|
||||
<template v-if="menu.step?.kind === 'step' && menuPath">
|
||||
<DropdownMenuLabel class="truncate">{{ menu.step.title || stepTitle(menu.step.type) }}</DropdownMenuLabel>
|
||||
<DropdownMenuLabel class="truncate">{{ menu.step.title || stepTitle(menu.step.type, workflows.stepTypes) }}</DropdownMenuLabel>
|
||||
<template v-if="restart">
|
||||
<DropdownMenuItem :disabled="restart.blocked" @select="emit('restart', restart.from)"><RotateCcw />{{ restart.label }}</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
|
||||
@@ -91,7 +91,7 @@ const unpinned = computed(() => Boolean(watchedRun.value && !watchedRun.value.wo
|
||||
const drawnStages = computed(() => unpinned.value ? [] : stages.value);
|
||||
const pinnedYaml = computed(() => watchedRun.value?.workflow_definition_yaml);
|
||||
const canvasYaml = computed(() => pinnedYaml.value || yaml.value);
|
||||
const graph = computed(() => withRuns(workflowGraph(canvasYaml.value), drawnStages.value));
|
||||
const graph = computed(() => withRuns(workflowGraph(canvasYaml.value, workflows.stepTypes), drawnStages.value));
|
||||
function toggle(key: string): void {
|
||||
open.value = open.value === key ? null : key;
|
||||
const run = graph.value.nodes.find((node) => JSON.stringify(node.data.path ?? null) === open.value)?.data.run;
|
||||
|
||||
@@ -2,6 +2,7 @@ import { parseDocument } from "yaml";
|
||||
|
||||
import { branchingOf } from "./workflow-edit.ts";
|
||||
import type { WorkflowTrigger } from "./workflow-triggers";
|
||||
import type { StepTypeInfo } from "./workflow-yaml.ts";
|
||||
|
||||
/**
|
||||
* A workflow definition laid out as a graph: a start node, each step as a
|
||||
@@ -146,30 +147,15 @@ export interface WorkflowGraph {
|
||||
const ROW = 140;
|
||||
const COLUMN = 280;
|
||||
|
||||
const TYPE_TITLES: Record<string, string> = {
|
||||
parallel: "Parallel",
|
||||
switch: "Switch",
|
||||
"agent.run": "Agent",
|
||||
"command.run": "Run commands",
|
||||
"repo.prepare": "Prepare worktree",
|
||||
"repo.commit": "Commit",
|
||||
"repo.open-pr": "Open pull request",
|
||||
"gate.repository": "Repository",
|
||||
"gate.diff-rules": "Diff rules",
|
||||
"forge.comment": "Comment",
|
||||
"forge.close-issue": "Close issue",
|
||||
"workflow.approve": "Approval",
|
||||
"workflow.call": "Call workflow",
|
||||
"workflow.handoff": "Hand off",
|
||||
"workflow.finish": "Finish",
|
||||
"review.pr": "Review pull request",
|
||||
"review.start-round": "Start review round",
|
||||
"review.reply": "Reply to review",
|
||||
};
|
||||
// Parallel and switch are YAML shapes, not registered step types, so the server
|
||||
// does not title them.
|
||||
const BRANCH_TITLES: Record<"parallel" | "switch", string> = { parallel: "Parallel", switch: "Switch" };
|
||||
|
||||
/** A step type's display name: a known one's title, else the type itself. */
|
||||
export function stepTitle(type: string): string {
|
||||
return TYPE_TITLES[type] ?? type;
|
||||
/** A step type's display name: the title the server serves for it, else the type
|
||||
* itself, so a vocabulary that has not loaded shows the raw name. */
|
||||
export function stepTitle(type: string, vocabulary: readonly StepTypeInfo[]): string {
|
||||
if (type === "parallel" || type === "switch") return BRANCH_TITLES[type];
|
||||
return vocabulary.find((step) => step.name === type)?.title ?? type;
|
||||
}
|
||||
|
||||
const REFERENCE = /\{\{\s*steps\.([A-Za-z0-9_-]+)\.[^}]*\}\}/g;
|
||||
@@ -224,7 +210,7 @@ function referencedSteps(settings: unknown, when: unknown): string[] {
|
||||
return [...new Set([...text.matchAll(REFERENCE)].map((match) => match[1]))];
|
||||
}
|
||||
|
||||
export function workflowGraph(source: string): WorkflowGraph {
|
||||
export function workflowGraph(source: string, vocabulary: readonly StepTypeInfo[] = []): WorkflowGraph {
|
||||
const value: unknown = parseDocument(source).toJS();
|
||||
const steps = isMapping(value) && Array.isArray(value.steps) ? value.steps : [];
|
||||
const nodes: GraphNode[] = [];
|
||||
@@ -276,7 +262,7 @@ export function workflowGraph(source: string): WorkflowGraph {
|
||||
kind: "step",
|
||||
key: stepID || key,
|
||||
name: stepID || undefined,
|
||||
title: stepID || stepTitle(type),
|
||||
title: stepID || stepTitle(type, vocabulary),
|
||||
type,
|
||||
step: path?.length === 2 ? String(Number(path[1]) + 1).padStart(2, "0") : undefined,
|
||||
detail: branching?.on ? `on ${branching.on.replace(/^steps\./, "")}` : stepDetail(type, settings),
|
||||
|
||||
@@ -28,6 +28,8 @@ export interface SettingsSchema {
|
||||
/** One registered step type, as the control-plane catalog serves it. */
|
||||
export interface StepTypeInfo {
|
||||
name: string;
|
||||
/** The name editors show for the step type. */
|
||||
title: string;
|
||||
needs_repository: boolean;
|
||||
/** Absent for a step that takes no settings. */
|
||||
settings?: SettingsSchema;
|
||||
|
||||
Reference in new issue
Block a user