feat(ui): workflow row actions, throttled live reloads, toolbar and layout fixes (#1833)
This commit is contained in:
24 files changed
+540
-32
No files matched your search
@@ -311,7 +311,7 @@ const changes = computed(() => (dirty.value ? workflowChanges(stored.value ?? ""
|
||||
// Disabled buttons swallow hover, so the reason sits on a wrapper's title.
|
||||
const publishBlocked = computed(() =>
|
||||
archieWorking.value ? "Archie is editing" : !parsed.value.ok ? validationLabel(parsed.value) : !changes.value.length ? "No changes" : undefined);
|
||||
const view = ref("canvas");
|
||||
const view = defineModel<string>("view", { default: "canvas" });
|
||||
// What each step lacks, read the way its editor reads it.
|
||||
const problems = computed(() =>
|
||||
Object.fromEntries(
|
||||
@@ -397,11 +397,11 @@ onBeforeUnmount(() => yamlObserver?.disconnect());
|
||||
<TabsList class="shrink-0 justify-start">
|
||||
<TabsTrigger value="canvas">Canvas</TabsTrigger>
|
||||
<TabsTrigger value="yaml">YAML</TabsTrigger>
|
||||
<TabsTrigger v-if="stored !== undefined" value="history" class="max-xl:hidden">History</TabsTrigger>
|
||||
<TabsTrigger v-if="$slots.performance" value="performance" class="max-xl:hidden">Performance</TabsTrigger>
|
||||
<TabsTrigger v-if="$slots.runs && stored !== undefined" value="runs" class="max-xl:hidden">Runs <span class="ml-1 font-mono text-caption text-fg-subtle">{{ runsCount ?? 0 }}</span></TabsTrigger>
|
||||
<TabsTrigger v-if="stored !== undefined" value="history" class="max-2xl:hidden">History</TabsTrigger>
|
||||
<TabsTrigger v-if="$slots.performance" value="performance" class="max-2xl:hidden">Performance</TabsTrigger>
|
||||
<TabsTrigger v-if="$slots.runs && stored !== undefined" value="runs" class="max-2xl:hidden">Runs <span class="ml-1 font-mono text-caption text-fg-subtle">{{ runsCount ?? 0 }}</span></TabsTrigger>
|
||||
</TabsList>
|
||||
<span v-if="SECTIONS[view]" class="shrink-0 text-caption font-medium text-fg-muted xl:hidden">{{ SECTIONS[view] }}</span>
|
||||
<span v-if="SECTIONS[view]" class="shrink-0 text-caption font-medium text-fg-muted 2xl:hidden">{{ SECTIONS[view] }}</span>
|
||||
<div role="group" aria-label="Runs" class="workflow-run-actions ml-auto flex min-w-0 items-center gap-1 max-sm:col-span-2 max-sm:row-start-2 max-sm:ml-0">
|
||||
<div v-if="stored !== undefined && (view === 'canvas' || view === 'yaml')" class="shrink-0">
|
||||
<RunWorkflowButton
|
||||
@@ -442,16 +442,16 @@ onBeforeUnmount(() => yamlObserver?.disconnect());
|
||||
<Spinner v-if="state.saving" data-icon="inline-start" />Publish</Button>
|
||||
</span>
|
||||
<MoreMenu>
|
||||
<DropdownMenuItem v-if="stored !== undefined" class="xl:hidden" @select="view = 'history'">History</DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="$slots.performance" class="xl:hidden" @select="view = 'performance'">Performance</DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="$slots.runs && stored !== undefined" class="xl:hidden" @select="view = 'runs'">Runs <span class="ml-auto font-mono text-caption text-fg-subtle">{{ runsCount ?? 0 }}</span></DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="stored !== undefined" class="2xl:hidden" @select="view = 'history'">History</DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="$slots.performance" class="2xl:hidden" @select="view = 'performance'">Performance</DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="$slots.runs && stored !== undefined" class="2xl:hidden" @select="view = 'runs'">Runs <span class="ml-auto font-mono text-caption text-fg-subtle">{{ runsCount ?? 0 }}</span></DropdownMenuItem>
|
||||
<!-- The run's page and the version it pinned are menu items, not
|
||||
row controls: the row keeps the width for the picked run. -->
|
||||
<DropdownMenuItem v-if="watchedRun" as-child><RouterLink :to="`/tasks/${watchedRun.id}`">Open run</RouterLink></DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="watchedRevision" @select="openRevision(watchedRevision.version)">Version {{ watchedRevision.version }}</DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="changes.length" @select="draftOpen = true">Draft changes <span class="ml-auto font-mono text-caption text-fg-subtle">{{ changes.length }}</span></DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="dirty" :disabled="archieWorking" @select="restorePublished"><RotateCcw />Restore</DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="view === 'canvas' || view === 'yaml'" variant="destructive" @select="confirmDelete = true"><Trash2 />Delete workflow</DropdownMenuItem>
|
||||
<DropdownMenuItem variant="destructive" @select="confirmDelete = true"><Trash2 />Delete workflow</DropdownMenuItem>
|
||||
</MoreMenu>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2,9 +2,8 @@
|
||||
import { toast } from "vue-sonner";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { computed, onMounted, ref, shallowRef, watch } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
import { Plus } from "@lucide/vue";
|
||||
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { Copy, ListChecks, Play, Plus, Power } from "@lucide/vue";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -15,6 +14,11 @@ import {
|
||||
} from "@/components/ui/empty";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from "@/components/ui/context-menu";
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
||||
import { MoreMenu } from "@/components/ui/more-menu";
|
||||
import NewTaskForm from "@/tasks/NewTaskForm.vue";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { StatusDot } from "@/components/ui/status-dot";
|
||||
import { Table, TableBody, TableCell, TableRow } from "@/components/ui/table";
|
||||
@@ -25,7 +29,7 @@ import { delivered } from "@/lib/delivered";
|
||||
import { compact } from "@/lib/format";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { statusKind, statusLabel } from "@/lib/task-meta";
|
||||
import { useWorkflowsStore } from "@/stores/workflows";
|
||||
import { upsertWorkflowDefinition, useWorkflowsStore } from "@/stores/workflows";
|
||||
import { useLiveResource } from "@/stores/session";
|
||||
import ApplyStatusRows from "@/settings/ApplyStatusRows.vue";
|
||||
import SlowestStagesCard from "./SlowestStagesCard.vue";
|
||||
@@ -33,6 +37,7 @@ import StageFailuresCard from "./StageFailuresCard.vue";
|
||||
import type { StageStats } from "./stages";
|
||||
import WorkflowEditor from "./WorkflowEditor.vue";
|
||||
import WorkflowPicker from "./WorkflowPicker.vue";
|
||||
import { setWorkflowField } from "./workflow-edit";
|
||||
import { workflowRows, type WorkflowDefinition, type WorkflowStats } from "./workflow-rows";
|
||||
|
||||
interface WorkflowsResponse {
|
||||
@@ -56,21 +61,25 @@ const data = shallowRef<WorkflowsResponse>({});
|
||||
const error = ref<string | null>(null);
|
||||
const loading = ref(true);
|
||||
|
||||
const statsOf = (id: string) => JSON.stringify(data.value.workflows?.find((w) => w.workflow === id) ?? null);
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
// The sidebar's running count and last status come from the per-workflow
|
||||
// statistics: a page of the newest tasks across every workflow would show
|
||||
// nothing for a workflow whose runs are older than that page.
|
||||
const before = statsOf(selected.value);
|
||||
data.value = keepValue(data.value, (await api.workflows<WorkflowsResponse>()) ?? {});
|
||||
error.value = null;
|
||||
void loadWorkflowRuns();
|
||||
// The runs page only changes when the workflow's own statistics do.
|
||||
if (runsFor !== selected.value || statsOf(selected.value) !== before) void loadWorkflowRuns();
|
||||
} catch (err) {
|
||||
error.value = String((err as Error).message || err);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
useLiveResource("tasks", () => void load(), 500);
|
||||
useLiveResource("tasks", () => void load(), 5000);
|
||||
onMounted(() => Promise.all([load(), store.load()]));
|
||||
|
||||
// Stored definitions are the source of truth for the list; statistics join
|
||||
@@ -113,15 +122,65 @@ const provenance = computed(() => {
|
||||
// A workflow the server does not list yet (a new, unsaved one) has no
|
||||
// enabled state to show.
|
||||
const enabled = computed(() => data.value.definitions?.find((d) => d.id === selected.value)?.enabled);
|
||||
async function setEnabled(value: boolean) {
|
||||
async function setEnabled(id: string, value: boolean) {
|
||||
try {
|
||||
await api.workflowEnabled(selected.value, value);
|
||||
toast.success(`${selected.value} ${value ? "enabled" : "disabled"}`);
|
||||
await api.workflowEnabled(id, value);
|
||||
toast.success(`${id} ${value ? "enabled" : "disabled"}`);
|
||||
await load();
|
||||
} catch (err) {
|
||||
toast.error(`${selected.value} not ${value ? "enabled" : "disabled"}: ${(err as Error).message || err}`);
|
||||
toast.error(`${id} not ${value ? "enabled" : "disabled"}: ${(err as Error).message || err}`);
|
||||
}
|
||||
}
|
||||
const enabledOf = (id: string) => data.value.definitions?.find((d) => d.id === id)?.enabled;
|
||||
|
||||
// The editor's tab, so a row can open straight onto its runs.
|
||||
const view = ref("canvas");
|
||||
const router = useRouter();
|
||||
const runTarget = ref("");
|
||||
const runOpen = computed({
|
||||
get: () => runTarget.value !== "",
|
||||
set: (open) => {
|
||||
if (!open) runTarget.value = "";
|
||||
},
|
||||
});
|
||||
|
||||
async function duplicate(id: string) {
|
||||
const source = stored.value.find((d) => d.id === id);
|
||||
if (!source) return;
|
||||
let copy = `${id}-copy`;
|
||||
for (let n = 2; stored.value.some((d) => d.id === copy); n++) copy = `${id}-copy-${n}`;
|
||||
if (await store.save(upsertWorkflowDefinition(store.collection, { id: copy, yaml: setWorkflowField(source.yaml, "id", copy) }))) {
|
||||
selected.value = copy;
|
||||
toast.success(`${copy} created`);
|
||||
} else toast.error(`${id} not duplicated: ${store.error || "save failed"}`);
|
||||
}
|
||||
|
||||
interface RowAction {
|
||||
label: string;
|
||||
icon: typeof Play;
|
||||
run: () => void;
|
||||
}
|
||||
function rowActions(id: string): RowAction[] {
|
||||
const saved = stored.value.some((d) => d.id === id);
|
||||
const enabled = enabledOf(id);
|
||||
const actions: RowAction[] = [];
|
||||
if (enabled !== undefined) actions.push({ label: enabled ? "Disable" : "Enable", icon: Power, run: () => void setEnabled(id, !enabled) });
|
||||
if (saved) {
|
||||
actions.push(
|
||||
{ label: "Run", icon: Play, run: () => (runTarget.value = id) },
|
||||
{
|
||||
label: "Open runs",
|
||||
icon: ListChecks,
|
||||
run: () => {
|
||||
selected.value = id;
|
||||
view.value = "runs";
|
||||
},
|
||||
},
|
||||
{ label: "Duplicate", icon: Copy, run: () => void duplicate(id) },
|
||||
);
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
const stages = computed(() => (data.value.stages ?? []).filter((s) => s.workflow === selected.value));
|
||||
// The selected workflow's runs come from a workflow-filtered page: the global
|
||||
// list above holds only the newest tasks of every workflow.
|
||||
@@ -178,7 +237,9 @@ const rate = (deliveredRuns = 0, total = 0) => (total ? deliveredRuns / total :
|
||||
<div class="grid items-start gap-6 lg:grid-cols-[24rem_minmax(0,1fr)] max-md:min-h-0 max-md:flex-1 max-md:grid-rows-[minmax(0,1fr)]">
|
||||
<div class="hidden min-w-0 flex-col gap-1 lg:flex">
|
||||
<ul class="hidden max-h-[calc(100dvh-10rem)] flex-col gap-0.5 overflow-y-auto lg:flex" aria-label="Workflows">
|
||||
<li v-for="row in rows" :key="row.id" class="min-w-0">
|
||||
<li v-for="row in rows" :key="row.id" class="relative min-w-0">
|
||||
<ContextMenu>
|
||||
<ContextMenuTrigger as-child>
|
||||
<button
|
||||
type="button"
|
||||
:aria-current="row.id === selected ? 'true' : undefined"
|
||||
@@ -202,6 +263,14 @@ const rate = (deliveredRuns = 0, total = 0) => (total ? deliveredRuns / total :
|
||||
<span v-if="row.runs" class="w-16 shrink-0 text-right font-mono" aria-hidden="true">{{ delivered(row) }}/{{ row.runs }}</span>
|
||||
</span>
|
||||
</button>
|
||||
</ContextMenuTrigger>
|
||||
<ContextMenuContent v-if="rowActions(row.id).length" class="min-w-40">
|
||||
<ContextMenuItem v-for="action in rowActions(row.id)" :key="action.label" @select="action.run"><component :is="action.icon" />{{ action.label }}</ContextMenuItem>
|
||||
</ContextMenuContent>
|
||||
</ContextMenu>
|
||||
<MoreMenu v-if="rowActions(row.id).length" :label="`${row.id} actions`" class="absolute top-1.5 right-1.5">
|
||||
<DropdownMenuItem v-for="action in rowActions(row.id)" :key="action.label" @select="action.run"><component :is="action.icon" />{{ action.label }}</DropdownMenuItem>
|
||||
</MoreMenu>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -220,14 +289,14 @@ const rate = (deliveredRuns = 0, total = 0) => (total ? deliveredRuns / total :
|
||||
<Badge v-if="provenance" variant="outline" class="shrink-0">{{ provenance }}</Badge>
|
||||
<ApplyStatusRows kind="workflow-definitions" compact />
|
||||
</header>
|
||||
<WorkflowEditor v-model:selected="selected" :runs-count="workflowRuns.length">
|
||||
<WorkflowEditor v-model:selected="selected" v-model:view="view" :runs-count="workflowRuns.length">
|
||||
<template #title>
|
||||
<h2 class="min-w-0 truncate text-title font-medium">{{ selected }}</h2>
|
||||
<Badge v-if="provenance" variant="outline" class="shrink-0">{{ provenance }}</Badge>
|
||||
<ApplyStatusRows kind="workflow-definitions" compact />
|
||||
</template>
|
||||
<template v-if="enabled !== undefined" #toolbar>
|
||||
<Switch :model-value="enabled" :title="enabled ? 'Published version runs on events' : 'Published version ignores events'" aria-label="Published version enabled" @update:model-value="setEnabled" />
|
||||
<Switch :model-value="enabled" :title="enabled ? 'Published version runs on events' : 'Published version ignores events'" aria-label="Published version enabled" @update:model-value="setEnabled(selected, $event)" />
|
||||
</template>
|
||||
<template #performance>
|
||||
<Empty v-if="!stages.length">
|
||||
@@ -264,5 +333,13 @@ const rate = (deliveredRuns = 0, total = 0) => (total ? deliveredRuns / total :
|
||||
</WorkflowEditor>
|
||||
</Card>
|
||||
</div>
|
||||
<Dialog v-model:open="runOpen">
|
||||
<DialogContent class="sm:max-w-[640px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Run {{ runTarget }}</DialogTitle>
|
||||
</DialogHeader>
|
||||
<NewTaskForm v-if="runTarget" :workflow="runTarget" @started="(taskId) => { runTarget = ''; void router.push(`/tasks/${taskId}`); }" @cancel="runTarget = ''" />
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
</template>
|
||||
@@ -109,7 +109,7 @@ export function useWorkflowRuns(workflow: Ref<string>) {
|
||||
pinned.value = undefined;
|
||||
void loadStages();
|
||||
});
|
||||
useLiveResource("tasks", () => void refresh(), 300);
|
||||
useLiveResource("tasks", () => void refresh(), 2000);
|
||||
|
||||
const watchedRun = computed(() => {
|
||||
const run = runs.value.find((run) => String(run.id) === watched.value);
|
||||
|
||||
Reference in new issue
Block a user