feat(ui): workflow canvas cards expand in place instead of side panels

This commit is contained in:
sam committed 2026-10-18 01:59:09 +11:00
1 parent e3add11a1d
commit 7fc4f4f9d7
21 files changed
+691 -610

No files matched your search

+124 -59
View File
@@ -1,12 +1,27 @@
<script setup lang="ts">
import { computed } from "vue";
import { computed, nextTick, onBeforeUnmount, onMounted, ref } from "vue";
import { Handle, Position } from "@vue-flow/core";
import { Flag, Play, Repeat, SkipForward, Webhook, CircleDot, BookOpen, Workflow } from "@lucide/vue";
import { CircleAlert, CircleCheck, CircleMinus, CircleX, Copy, EllipsisVertical, Flag, LoaderCircle, Pencil, Play, Repeat, Settings2, SkipForward, Trash2 } from "@lucide/vue";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
import { Input } from "@/components/ui/input";
import { stepIcon } from "./step-icons";
import { stepTitle, type StepNodeData } from "./workflow-graph";
const props = defineProps<{ data: StepNodeData }>();
export interface StepCardData extends StepNodeData {
expanded?: boolean;
editable?: boolean;
problem?: string;
onToggle?: () => void;
onResize?: (height: number) => void;
onRename?: (name: string) => void;
onDuplicate?: () => void;
onRemove?: () => void;
}
const props = defineProps<{ data: StepCardData }>();
const STATE_CLASSES: Record<string, string> = {
ok: "border-ok/70",
@@ -23,26 +38,31 @@ const MARK_CLASSES: Record<string, string> = {
};
const stateClass = computed(() => {
if (props.data.kind === "start") return "border-primary/60";
if (props.data.mark) return MARK_CLASSES[props.data.mark];
return STATE_CLASSES[props.data.run?.status ?? ""] ?? "border-border";
});
const ROLE_CLASSES: Record<string, string> = {
decision: "border-l-4 border-l-warn",
waiting: "border-l-4 border-l-info",
exit: "border-l-4 border-l-primary",
};
const STATUS = {
ok: { icon: CircleCheck, class: "text-ok", label: "Done" },
failed: { icon: CircleX, class: "text-danger", label: "Failed" },
interrupted: { icon: CircleAlert, class: "text-warn", label: "Interrupted" },
running: { icon: LoaderCircle, class: "text-info animate-spin", label: "Running" },
skipped: { icon: CircleMinus, class: "text-fg-subtle", label: "Skipped" },
} as const;
const status = computed(() => {
const run = props.data.run?.status;
if (run) return STATUS[run as keyof typeof STATUS] ?? null;
if (props.data.problem) return { icon: CircleAlert, class: "text-warn", label: props.data.problem };
if (props.data.editable && props.data.kind === "step") return { icon: CircleCheck, class: "text-ok/70", label: "Ready" };
return null;
});
const TRIGGER_ICONS = { issue: CircleDot, event: Webhook, playbook: BookOpen, workflow: Workflow };
const STATE_LABELS: Record<string, string> = {
ok: "Done",
failed: "Failed",
interrupted: "Interrupted",
running: "Running",
skipped: "Skipped",
};
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) };
});
const number = computed(() => (props.data.step ? `${Number(props.data.step)}.` : ""));
function duration(ms?: number): string {
if (ms === undefined) return "";
@@ -50,54 +70,99 @@ function duration(ms?: number): string {
const seconds = Math.round(ms / 1000);
return seconds < 60 ? `${seconds}s` : `${Math.floor(seconds / 60)}m ${seconds % 60}s`;
}
const card = ref<HTMLElement | null>(null);
let observer: ResizeObserver | undefined;
onMounted(() => {
observer = new ResizeObserver(() => props.data.onResize?.(card.value?.offsetHeight ?? 0));
if (card.value) observer.observe(card.value);
});
onBeforeUnmount(() => observer?.disconnect());
const renaming = ref(false);
const nameInput = ref<InstanceType<typeof Input> | null>(null);
async function rename(): Promise<void> {
renaming.value = true;
await nextTick();
((nameInput.value?.$el as HTMLInputElement | undefined) ?? null)?.select();
}
function commitRename(event: Event): void {
if (!renaming.value) return;
renaming.value = false;
const name = (event.target as HTMLInputElement).value.trim();
if (name !== (props.data.name ?? "")) props.data.onRename?.(name);
}
</script>
<template>
<div
class="w-60 rounded-lg border bg-card px-3 py-2 text-left shadow-sm"
:class="[stateClass, ROLE_CLASSES[data.role ?? ''], data.selected && 'ring-2 ring-ring', 'cursor-pointer transition-colors hover:border-muted-foreground']"
ref="card"
class="rounded-lg border bg-card text-left shadow-sm transition-[width,box-shadow] duration-200"
:class="[stateClass, data.expanded ? 'w-[26rem] shadow-lg ring-2 ring-ring/60' : 'w-60 hover:border-muted-foreground', data.onToggle && 'cursor-pointer']"
>
<Handle v-if="data.kind !== 'start'" type="target" :position="Position.Top" />
<Handle v-if="data.kind !== 'workflow'" type="target" :position="Position.Top" />
<Handle id="data-in" type="target" :position="Position.Right" class="!opacity-0" />
<div class="flex items-center gap-1.5">
<Play v-if="data.kind === 'start'" class="size-3.5 text-primary" aria-hidden="true" />
<component :is="stepIcon(data.type)" v-else class="size-3.5 shrink-0 text-muted-foreground" aria-hidden="true" />
<span v-if="data.step" class="font-mono text-[11px] text-fg-subtle">{{ data.step }}</span>
<span class="truncate text-sm font-medium" :title="data.title">{{ data.title }}</span>
</div>
<div v-if="data.mark" class="text-[11px] font-medium" :class="{ 'text-ok': data.mark === 'added', 'text-danger': data.mark === 'removed', 'text-warn': data.mark === 'changed' }">{{ data.mark === "added" ? "Added" : data.mark === "removed" ? "Removed" : "Changed" }}</div>
<div v-if="data.type && data.title !== stepTitle(data.type)" class="truncate font-mono text-[11px] text-fg-subtle">{{ data.type }}</div>
<ul v-if="data.kind === 'start' && data.triggers?.length" class="mt-1 space-y-0.5">
<li v-for="trigger in data.triggers" :key="trigger.kind + trigger.label" class="flex items-center gap-1.5 text-xs" :title="trigger.detail">
<component :is="TRIGGER_ICONS[trigger.kind]" class="size-3 shrink-0 text-primary" aria-hidden="true" />
<span class="truncate">{{ trigger.label }}</span>
<span v-if="trigger.detail" class="truncate text-fg-subtle">{{ trigger.detail }}</span>
</li>
</ul>
<div v-else-if="data.kind === 'start'" class="mt-0.5 text-xs text-muted-foreground">Nothing starts it yet.</div>
<div v-else-if="data.detail" class="mt-0.5 truncate text-xs text-muted-foreground" :title="data.detail">{{ data.detail }}</div>
<p v-if="data.summary" class="mt-1 line-clamp-2 text-xs leading-snug text-foreground/80" :title="data.summary">{{ data.summary }}</p>
<div v-if="data.when || data.retry || data.continues" class="mt-1 flex flex-wrap gap-1 text-[11px]">
<span v-if="data.when" class="flex max-w-full min-w-0 items-center gap-0.5 rounded bg-secondary px-1 font-mono" :title="`Runs only when ${data.when}`">
<Flag class="size-3 shrink-0" aria-hidden="true" /><span class="truncate">{{ data.when }}</span>
</span>
<span v-if="data.retry" class="flex items-center gap-0.5 rounded bg-secondary px-1" :title="`Up to ${data.retry} attempts`">
<Repeat class="size-3" aria-hidden="true" />×{{ data.retry }}
</span>
<span v-if="data.continues" class="flex items-center gap-0.5 rounded bg-secondary px-1" title="A failure does not stop the run">
<SkipForward class="size-3" aria-hidden="true" />continues</span>
</div>
<div
v-if="data.run"
class="mt-1 flex items-center gap-1.5 text-[11px]"
:class="{ 'text-ok': data.run.status === 'ok', 'text-danger': data.run.status === 'failed', 'text-info': data.run.status === 'running', 'text-warn': data.run.status === 'interrupted', 'text-fg-subtle': data.run.status === 'skipped' }"
:title="data.run.error || undefined"
>
<span class="size-1.5 rounded-full bg-current" aria-hidden="true" />
{{ STATE_LABELS[data.run.status] ?? data.run.status }}
<span v-if="data.run.duration_ms !== undefined" class="text-fg-subtle">{{ duration(data.run.duration_ms) }}</span>
<span v-if="data.run.error" class="truncate text-danger">{{ data.run.error }}</span>
<div class="px-3 py-2.5" @click="data.onToggle?.()">
<div class="flex items-center gap-1.5">
<Badge variant="outline" class="max-w-40 gap-1 bg-background">
<component :is="badge.icon" class="text-primary" aria-hidden="true" /><span class="truncate">{{ badge.label }}</span>
</Badge>
<span v-if="data.run?.duration_ms !== undefined" class="ml-auto font-mono text-[11px] text-fg-subtle">{{ duration(data.run.duration_ms) }}</span>
<component :is="status.icon" v-if="status" class="size-4 shrink-0" :class="[status.class, data.run?.duration_ms === undefined && 'ml-auto']" :aria-label="status.label" :title="data.run?.error || status.label" />
<span v-else class="ml-auto" />
<DropdownMenu v-if="data.editable && data.kind === 'step'">
<DropdownMenuTrigger as-child>
<Button variant="ghost" size="icon-xs" class="nodrag nopan -mr-1.5" aria-label="Step actions" @click.stop><EllipsisVertical /></Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" class="w-40">
<DropdownMenuItem @select="rename"><Pencil />Rename</DropdownMenuItem>
<DropdownMenuItem v-if="!['parallel', 'switch'].includes(data.type)" @select="data.onDuplicate?.()"><Copy />Duplicate</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem variant="destructive" @select="data.onRemove?.()"><Trash2 />Delete</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
<div class="mt-1.5 flex min-w-0 items-baseline gap-1 text-sm font-medium">
<span v-if="number" class="shrink-0">{{ number }}</span>
<Input
v-if="renaming"
ref="nameInput"
:model-value="data.name ?? ''"
class="nodrag nopan h-6 px-1 text-sm"
aria-label="Step id"
:placeholder="stepTitle(data.type)"
@click.stop
@keydown.enter.prevent="commitRename"
@keydown.esc="renaming = false"
@blur="commitRename"
/>
<span v-else class="truncate" :title="data.title">{{ data.title }}</span>
</div>
<div v-if="data.mark" class="text-[11px] font-medium" :class="{ 'text-ok': data.mark === 'added', 'text-danger': data.mark === 'removed', 'text-warn': data.mark === 'changed' }">{{ data.mark === "added" ? "Added" : data.mark === "removed" ? "Removed" : "Changed" }}</div>
<template v-if="!data.expanded">
<ul v-if="data.kind === 'start' && data.triggers?.length" class="mt-1 space-y-0.5">
<li v-for="trigger in data.triggers" :key="trigger.kind + trigger.label" class="truncate text-xs text-muted-foreground" :title="trigger.detail">{{ trigger.label }}</li>
</ul>
<div v-else-if="data.kind === 'start'" class="mt-0.5 text-xs text-muted-foreground">Manual runs only</div>
<div v-else-if="data.summary || data.detail" class="mt-0.5 truncate text-xs text-muted-foreground" :title="[data.detail, data.summary].filter(Boolean).join('\n')">{{ data.summary || data.detail }}</div>
<div v-if="data.when || data.retry || data.continues" class="mt-1 flex flex-wrap gap-1 text-[11px]">
<span v-if="data.when" class="flex max-w-full min-w-0 items-center gap-0.5 rounded bg-secondary px-1 font-mono" :title="`Runs only when ${data.when}`">
<Flag class="size-3 shrink-0" aria-hidden="true" /><span class="truncate">{{ data.when }}</span>
</span>
<span v-if="data.retry" class="flex items-center gap-0.5 rounded bg-secondary px-1" :title="`Up to ${data.retry} attempts`">
<Repeat class="size-3" aria-hidden="true" />×{{ data.retry }}
</span>
<span v-if="data.continues" class="flex items-center gap-0.5 rounded bg-secondary px-1" title="A failure does not stop the run">
<SkipForward class="size-3" aria-hidden="true" />continues</span>
</div>
<p v-if="data.run?.error" class="mt-1 line-clamp-2 text-[11px] text-danger" :title="data.run.error">{{ data.run.error }}</p>
</template>
</div>
<Transition enter-from-class="opacity-0 -translate-y-1" enter-active-class="transition duration-200" leave-to-class="opacity-0" leave-active-class="transition duration-100">
<div v-if="data.expanded" class="nodrag nopan nowheel cursor-auto border-t border-border" @click.stop>
<slot />
</div>
</Transition>
<Handle type="source" :position="Position.Bottom" />
<Handle id="data-out" type="source" :position="Position.Right" class="!opacity-0" />
<Handle v-if="data.type === 'switch'" id="otherwise" type="source" :position="Position.Right" class="!opacity-0" />