fix(ui/data-table): lay out columns at fixed widths with middle-aligned rows (#2023)
Columns take a width from their definition, the first one takes the rest, and a column can hide below a breakpoint. Rows may carry a right-click menu.
This commit is contained in:
12 files changed
+71
-302
No files matched your search
@@ -82,9 +82,9 @@ const queryKey = computed(() => JSON.stringify(query.value));
|
||||
|
||||
const columns: DataTableColumn<AuditRecord>[] = [
|
||||
{ id: "event", label: "Event", fixed: true, class: "whitespace-normal" },
|
||||
{ id: "target", label: "Target", fixed: true, class: "hidden sm:table-cell" },
|
||||
{ id: "actor", label: "Actor", fixed: true, class: "hidden sm:table-cell" },
|
||||
{ id: "when", label: "When", fixed: true, class: "hidden sm:table-cell" },
|
||||
{ id: "target", label: "Target", fixed: true, hide: "sm", width: "14rem" },
|
||||
{ id: "actor", label: "Actor", fixed: true, hide: "sm", width: "12rem" },
|
||||
{ id: "when", label: "When", fixed: true, hide: "sm", width: "9rem" },
|
||||
];
|
||||
|
||||
const status = ref("");
|
||||
|
||||
@@ -18,13 +18,13 @@ const store = useDenialsStore();
|
||||
const { denials, loading, error } = storeToRefs(store);
|
||||
|
||||
const columns: DataTableColumn<Denial>[] = [
|
||||
{ id: "at", label: "When", fixed: true, sort: (d) => d.at },
|
||||
{ id: "principal", label: "Principal", fixed: true, class: "whitespace-normal" },
|
||||
{ id: "action", label: "Action" },
|
||||
{ id: "resource", label: "Resource", class: "whitespace-normal" },
|
||||
{ id: "level", label: "Level" },
|
||||
{ id: "policies", label: "Deciding policies", class: "hidden md:table-cell whitespace-normal" },
|
||||
{ id: "count", label: "Count", sort: (d) => d.count },
|
||||
{ id: "at", label: "When", fixed: true, width: "9rem", sort: (d) => d.at },
|
||||
{ id: "principal", label: "Principal", fixed: true, width: "auto", class: "whitespace-normal" },
|
||||
{ id: "action", label: "Action", width: "12rem" },
|
||||
{ id: "resource", label: "Resource", width: "14rem", class: "whitespace-normal" },
|
||||
{ id: "level", label: "Level", width: "6rem" },
|
||||
{ id: "policies", label: "Deciding policies", hide: "md", width: "14rem", class: "whitespace-normal" },
|
||||
{ id: "count", label: "Count", width: "6rem", sort: (d) => d.count },
|
||||
];
|
||||
|
||||
onMounted(() => void store.load());
|
||||
|
||||
@@ -35,12 +35,12 @@ const props = withDefaults(
|
||||
const position = computed(() => new Map(props.entries.map((entry, i) => [entry, i])));
|
||||
|
||||
const columns: DataTableColumn<LogEntry>[] = [
|
||||
{ id: "time", label: "Time", fixed: true, class: "w-0 whitespace-nowrap", sort: (e) => position.value.get(e) ?? 0 },
|
||||
{ id: "level", label: "Level", fixed: true, class: "w-0" },
|
||||
{ id: "service", label: "Service", hidden: !props.services, class: "w-0 whitespace-nowrap" },
|
||||
{ id: "component", label: "Component", hidden: !props.services, class: "w-0 whitespace-nowrap" },
|
||||
{ id: "stage", label: "Stage", hidden: props.services, class: "w-0 whitespace-nowrap" },
|
||||
{ id: "message", label: "Message", fixed: true, class: "whitespace-normal" },
|
||||
{ id: "time", label: "Time", fixed: true, width: "9rem", sort: (e) => position.value.get(e) ?? 0 },
|
||||
{ id: "level", label: "Level", fixed: true, width: "6rem" },
|
||||
{ id: "service", label: "Service", hidden: !props.services, width: "8rem" },
|
||||
{ id: "component", label: "Component", hidden: !props.services, width: "9rem" },
|
||||
{ id: "stage", label: "Stage", hidden: props.services, width: "9rem" },
|
||||
{ id: "message", label: "Message", fixed: true, width: "auto", class: "whitespace-normal" },
|
||||
];
|
||||
// received_at restates the time; the rest have columns.
|
||||
const shown = new Set(["received_at", "stage", "service", "component", ...props.omit]);
|
||||
|
||||
@@ -11,13 +11,16 @@ import {
|
||||
DropdownMenuContent,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { ContextMenu, ContextMenuContent, ContextMenuTrigger } from "@/components/ui/context-menu";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import type { DataTableColumn } from "./types";
|
||||
|
||||
/**
|
||||
* A table whose optional columns the operator chooses, remembered per browser
|
||||
* under `storageKey`. Cells render through `#cell-<id>` slots, given the row;
|
||||
* `#actions` fills a trailing cell and `#empty` replaces the body when there
|
||||
* `#menu` fills a right-click menu with ContextMenuItems, `#actions` fills a
|
||||
* trailing cell and `#empty` replaces the body when there
|
||||
* are no rows. With `rowLink`, the whole row opens that route, so controls
|
||||
* inside a cell must stop their click and keydown events. With a `#detail`
|
||||
* slot and no `rowLink`, a row opens in place to show its detail beneath it.
|
||||
@@ -35,7 +38,7 @@ const props = defineProps<{
|
||||
/** The sort the table opens with, on a column that has one. */
|
||||
initialSort?: { id: string; desc: boolean };
|
||||
}>();
|
||||
const slots = defineSlots<Record<string, (props: { row: Row }) => unknown> & { empty?: () => unknown; actions?: (props: { row: Row }) => unknown; detail?: (props: { row: Row }) => unknown }>();
|
||||
const slots = defineSlots<Record<string, (props: { row: Row }) => unknown> & { empty?: () => unknown; actions?: (props: { row: Row }) => unknown; detail?: (props: { row: Row }) => unknown; menu?: (props: { row: Row }) => unknown }>();
|
||||
|
||||
const router = useRouter();
|
||||
const chosen = useLocalStorage<string[]>(
|
||||
@@ -72,6 +75,12 @@ const sorted = computed(() => {
|
||||
const ariaSort = (id: string) => (sortBy.value?.id !== id ? "none" : sortBy.value.desc ? "descending" : "ascending");
|
||||
const sortIcon = (id: string) => (sortBy.value?.id !== id ? ArrowUpDown : sortBy.value.desc ? ArrowDown : ArrowUp);
|
||||
|
||||
// A fixed layout: the first column takes what the others leave.
|
||||
const grows = computed(() => (props.columns.some((c) => c.width === "auto") ? "auto" : props.columns[0]?.id));
|
||||
const width = (column: DataTableColumn<Row>) =>
|
||||
column.width === "auto" || (!column.width && grows.value === column.id) ? undefined : { width: column.width ?? "10rem" };
|
||||
const hidden = (column: DataTableColumn<Row>) => (column.hide ? (column.hide === "sm" ? "max-sm:hidden" : "max-md:hidden") : undefined);
|
||||
|
||||
const expandable = computed(() => !props.rowLink && !!slots.detail);
|
||||
const expanded = ref(new Set<string>());
|
||||
function open(row: Row): void {
|
||||
@@ -90,13 +99,17 @@ function open(row: Row): void {
|
||||
<template>
|
||||
<!-- A sticky header sticks to the page's scrolling frame, so the table
|
||||
must not be a scroll container of its own. -->
|
||||
<Table :container-class="stickyHeader && 'overflow-visible'">
|
||||
<Table class="table-fixed" :container-class="stickyHeader && 'overflow-visible'">
|
||||
<colgroup>
|
||||
<col v-for="column in shown" :key="column.id" :class="hidden(column)" :style="width(column)" />
|
||||
<col v-if="trailing" class="w-12" />
|
||||
</colgroup>
|
||||
<TableHeader :class="stickyHeader && 'sticky top-0 z-10 bg-card shadow-[inset_0_-1px_0_var(--color-border)]'">
|
||||
<TableRow>
|
||||
<TableHead
|
||||
v-for="column in shown"
|
||||
:key="column.id"
|
||||
:class="column.class"
|
||||
:class="cn('truncate', hidden(column), column.class)"
|
||||
:aria-sort="column.sort ? ariaSort(column.id) : undefined"
|
||||
>
|
||||
<Button v-if="column.sort" variant="ghost" size="sm" class="-ml-2.5" @click="cycleSort(column.id)">
|
||||
@@ -104,7 +117,7 @@ function open(row: Row): void {
|
||||
</Button>
|
||||
<template v-else>{{ column.label }}</template>
|
||||
</TableHead>
|
||||
<TableHead v-if="trailing" class="w-0 text-right">
|
||||
<TableHead v-if="trailing" class="text-right">
|
||||
<DropdownMenu v-if="optional.length">
|
||||
<DropdownMenuTrigger as-child>
|
||||
<Button variant="ghost" size="icon-sm" aria-label="Columns" title="Columns"><Columns3 /></Button>
|
||||
@@ -128,21 +141,23 @@ function open(row: Row): void {
|
||||
<TableCell :colspan="shown.length + (trailing ? 1 : 0)"><slot name="empty" /></TableCell>
|
||||
</TableRow>
|
||||
<template v-for="row in sorted" :key="rowKey(row)">
|
||||
<ContextMenu>
|
||||
<ContextMenuTrigger as-child :disabled="!slots.menu">
|
||||
<TableRow
|
||||
:data-row-key="rowKey(row)"
|
||||
:tabindex="expandable ? 0 : undefined"
|
||||
:aria-expanded="expandable ? expanded.has(rowKey(row)) : undefined"
|
||||
:class="['align-top', (rowLink || expandable) && 'cursor-pointer', rowClass?.(row)]"
|
||||
:class="['align-middle', (rowLink || expandable) && 'cursor-pointer', rowClass?.(row)]"
|
||||
@click="open(row)"
|
||||
@keydown.enter.self.prevent="open(row)"
|
||||
@keydown.space.self.prevent="open(row)"
|
||||
>
|
||||
<TableCell v-for="(column, cellIndex) in shown" :key="column.id" :class="column.class">
|
||||
<TableCell v-for="(column, cellIndex) in shown" :key="column.id" :class="cn('overflow-hidden text-ellipsis', hidden(column), column.class)">
|
||||
<RouterLink
|
||||
v-if="cellIndex === 0 && rowLink"
|
||||
:to="rowLink(row)"
|
||||
:aria-label="rowLabel ? rowLabel(row) : undefined"
|
||||
class="rounded-sm focus-visible:outline-2 focus-visible:outline-ring"
|
||||
class="block truncate rounded-sm focus-visible:outline-2 focus-visible:outline-ring"
|
||||
@click.stop
|
||||
><slot :name="`cell-${column.id}`" :row="row"
|
||||
/></RouterLink>
|
||||
@@ -150,6 +165,9 @@ function open(row: Row): void {
|
||||
</TableCell>
|
||||
<TableCell v-if="trailing"><slot name="actions" :row="row" /></TableCell>
|
||||
</TableRow>
|
||||
</ContextMenuTrigger>
|
||||
<ContextMenuContent v-if="slots.menu" class="min-w-40"><slot name="menu" :row="row" /></ContextMenuContent>
|
||||
</ContextMenu>
|
||||
<TableRow v-if="expandable && expanded.has(rowKey(row))" class="hover:bg-transparent">
|
||||
<TableCell :colspan="shown.length + (trailing ? 1 : 0)" class="bg-muted/40 whitespace-normal">
|
||||
<slot name="detail" :row="row" />
|
||||
|
||||
@@ -5,6 +5,12 @@ export interface DataTableColumn<Row = never> {
|
||||
fixed?: boolean;
|
||||
/** Hidden until the operator turns it on. */
|
||||
hidden?: boolean;
|
||||
/** A CSS length, or "auto" for the column that takes the space the others
|
||||
* leave. The table lays columns out at fixed widths: a column without one
|
||||
* is 10rem wide, and the first column grows unless another is "auto". */
|
||||
width?: string;
|
||||
/** Hides the column, header and cells, below this breakpoint. */
|
||||
hide?: "sm" | "md";
|
||||
class?: string;
|
||||
/** Makes the header sort the loaded rows by this value. */
|
||||
sort?: (row: Row) => string | number;
|
||||
|
||||
+15
-15
@@ -154,31 +154,31 @@ const totalRows = computed<TotalRow[]>(() => {
|
||||
|
||||
const dayColumns: DataTableColumn<DayRow>[] = [
|
||||
{ id: "day", label: "Day", fixed: true, class: "whitespace-nowrap" },
|
||||
{ id: "calls", label: "Calls", class: "tabular-nums", sort: (row) => row.calls },
|
||||
{ id: "tokens", label: "Tokens", class: "tabular-nums", sort: tokens },
|
||||
{ id: "cost", label: "Cost", class: "tabular-nums", sort: (row) => row.cost_usd ?? -1 },
|
||||
{ id: "calls", label: "Calls", width: "7rem", class: "tabular-nums", sort: (row) => row.calls },
|
||||
{ id: "tokens", label: "Tokens", width: "7rem", class: "tabular-nums", sort: tokens },
|
||||
{ id: "cost", label: "Cost", width: "7rem", class: "tabular-nums", sort: (row) => row.cost_usd ?? -1 },
|
||||
];
|
||||
|
||||
const modelColumns: DataTableColumn<ModelRow>[] = [
|
||||
{ id: "provider", label: "Provider", fixed: true, class: "text-fg-muted whitespace-nowrap" },
|
||||
{ id: "model", label: "Model", fixed: true, class: "w-full whitespace-normal" },
|
||||
{ id: "calls", label: "Calls", class: "tabular-nums", sort: (row) => row.calls },
|
||||
{ id: "tokens", label: "Tokens", class: "tabular-nums", sort: tokens },
|
||||
{ id: "cost", label: "Cost", class: "tabular-nums", sort: (row) => row.cost_usd ?? -1 },
|
||||
{ id: "provider", label: "Provider", fixed: true, width: "12rem", class: "text-fg-muted" },
|
||||
{ id: "model", label: "Model", fixed: true, width: "auto", class: "whitespace-normal" },
|
||||
{ id: "calls", label: "Calls", width: "7rem", class: "tabular-nums", sort: (row) => row.calls },
|
||||
{ id: "tokens", label: "Tokens", width: "7rem", class: "tabular-nums", sort: tokens },
|
||||
{ id: "cost", label: "Cost", width: "7rem", class: "tabular-nums", sort: (row) => row.cost_usd ?? -1 },
|
||||
];
|
||||
|
||||
const sourceColumns: DataTableColumn<SourceRow>[] = [
|
||||
{ id: "source", label: "Source", fixed: true },
|
||||
{ id: "calls", label: "Calls", class: "tabular-nums", sort: (row) => row.calls },
|
||||
{ id: "tokens", label: "Tokens", class: "tabular-nums", sort: tokens },
|
||||
{ id: "cost", label: "Cost", class: "tabular-nums", sort: (row) => row.cost_usd ?? -1 },
|
||||
{ id: "calls", label: "Calls", width: "7rem", class: "tabular-nums", sort: (row) => row.calls },
|
||||
{ id: "tokens", label: "Tokens", width: "7rem", class: "tabular-nums", sort: tokens },
|
||||
{ id: "cost", label: "Cost", width: "7rem", class: "tabular-nums", sort: (row) => row.cost_usd ?? -1 },
|
||||
];
|
||||
|
||||
const identityColumns: DataTableColumn<IdentityRow>[] = [
|
||||
{ id: "identity", label: "Identity", fixed: true, class: "w-full whitespace-normal" },
|
||||
{ id: "calls", label: "Calls", class: "tabular-nums", sort: (row) => row.calls },
|
||||
{ id: "tokens", label: "Tokens", class: "tabular-nums", sort: tokens },
|
||||
{ id: "cost", label: "Cost", class: "tabular-nums", sort: (row) => row.cost_usd ?? -1 },
|
||||
{ id: "identity", label: "Identity", fixed: true, width: "auto", class: "whitespace-normal" },
|
||||
{ id: "calls", label: "Calls", width: "7rem", class: "tabular-nums", sort: (row) => row.calls },
|
||||
{ id: "tokens", label: "Tokens", width: "7rem", class: "tabular-nums", sort: tokens },
|
||||
{ id: "cost", label: "Cost", width: "7rem", class: "tabular-nums", sort: (row) => row.cost_usd ?? -1 },
|
||||
];
|
||||
</script>
|
||||
|
||||
|
||||
@@ -87,8 +87,8 @@ const when = (schedule: Schedule) => timingWords(schedule.timing, zone.value, in
|
||||
const owner = (schedule: Schedule) => schedule.owner.name || schedule.owner.id || schedule.owner.kind;
|
||||
|
||||
const columns: DataTableColumn<Schedule>[] = [
|
||||
{ id: "enabled", label: "Enabled", fixed: true, class: "w-0" },
|
||||
{ id: "name", label: "Name", fixed: true, sort: (s) => s.name.toLowerCase() },
|
||||
{ id: "enabled", label: "Enabled", fixed: true, width: "6rem" },
|
||||
{ id: "name", label: "Name", fixed: true, width: "auto", sort: (s) => s.name.toLowerCase() },
|
||||
{ id: "owner", label: "Owner", sort: owner },
|
||||
{ id: "interval", label: "Interval" },
|
||||
{ id: "last", label: "Last Run", sort: (s) => s.last_run?.scheduled_for ?? "" },
|
||||
|
||||
@@ -23,10 +23,10 @@ const title = (task: Task) => task.title || "untitled task";
|
||||
// so the width they would repeat goes to the title.
|
||||
const columns = computed<DataTableColumn<Task>[]>(() => [
|
||||
...(props.showRepo
|
||||
? [{ id: "repo", label: "Repo", class: "whitespace-nowrap text-fg-muted", sort: (t: Task) => `${t.owner ?? ""}/${t.repo ?? ""}` }]
|
||||
? [{ id: "repo", label: "Repo", width: "12rem", class: "text-fg-muted", sort: (t: Task) => `${t.owner ?? ""}/${t.repo ?? ""}` }]
|
||||
: []),
|
||||
...(props.showIssue ? [{ id: "issue", label: "Issue", class: "text-fg-muted", sort: (t: Task) => t.issue_number ?? 0 }] : []),
|
||||
{ id: "title", label: "Title", fixed: true, class: "w-full whitespace-normal", sort: title },
|
||||
...(props.showIssue ? [{ id: "issue", label: "Issue", width: "6rem", class: "text-fg-muted", sort: (t: Task) => t.issue_number ?? 0 }] : []),
|
||||
{ id: "title", label: "Title", fixed: true, width: "auto", class: "whitespace-normal", sort: title },
|
||||
{ id: "status", label: "Status", sort: (t) => t.status ?? "" },
|
||||
{ id: "workflow", label: "Workflow", class: "text-fg-muted", sort: (t) => t.workflow ?? "" },
|
||||
{ id: "activity", label: "Last activity", class: "text-fg-muted", sort: (t) => Date.parse(t.updated_at ?? "") || 0 },
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from "vue";
|
||||
import { RouterLink, useRoute, useRouter } from "vue-router";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { api, describeError } from "@/lib/api";
|
||||
import { useRead } from "@/lib/use-read";
|
||||
import TriggerList from "@/events/TriggerList.vue";
|
||||
import WorkflowCanvas from "./WorkflowCanvas.vue";
|
||||
import WorkflowYaml from "./WorkflowYaml.vue";
|
||||
|
||||
/** One workflow: its graph, its document, the versions it has been published
|
||||
* as, and the triggers that start it. */
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const name = String(route.params.id);
|
||||
|
||||
const latest = useRead(() => api.workflow(name));
|
||||
onMounted(latest.reload);
|
||||
|
||||
// ?version= shows a published version read-only, marked against the latest.
|
||||
const versionParam = computed(() => Number(route.query.version) || 0);
|
||||
const shown = useRead(() => api.workflow(name, versionParam.value));
|
||||
watch(versionParam, (v) => v && void shown.reload(), { immediate: true });
|
||||
const viewingOld = computed(() => !!versionParam.value && versionParam.value !== latest.data.value?.version);
|
||||
const versions = computed(() => Array.from({ length: latest.data.value?.version ?? 0 }, (_, i) => String((latest.data.value?.version ?? 0) - i)));
|
||||
function pickVersion(v: unknown): void {
|
||||
const n = Number(v);
|
||||
void router.replace({ query: { ...route.query, version: n === latest.data.value?.version ? undefined : String(n) } });
|
||||
}
|
||||
|
||||
// The document being edited: unpublished until Publish, and lost on leaving.
|
||||
const yaml = ref("");
|
||||
const base = ref(0);
|
||||
watch(
|
||||
() => latest.data.value,
|
||||
(w) => {
|
||||
if (w && (!base.value || yaml.value === "")) {
|
||||
yaml.value = w.body;
|
||||
base.value = w.version;
|
||||
}
|
||||
},
|
||||
);
|
||||
const edited = computed(() => !!latest.data.value && yaml.value !== latest.data.value.body);
|
||||
const busy = ref(false);
|
||||
const publishError = ref("");
|
||||
async function publish(): Promise<void> {
|
||||
busy.value = true;
|
||||
publishError.value = "";
|
||||
try {
|
||||
// Another writer (a person, or Archie publishing a draft) may have
|
||||
// published since this copy was opened; never overwrite their version.
|
||||
const current = await api.workflow(name);
|
||||
if (current.version !== base.value) {
|
||||
publishError.value = `Version ${current.version} was published after you opened version ${base.value}. Copy your changes, then discard them to load it.`;
|
||||
return;
|
||||
}
|
||||
const saved = await api.putWorkflow(name, yaml.value);
|
||||
base.value = saved.version;
|
||||
yaml.value = saved.body;
|
||||
await latest.reload();
|
||||
} catch (cause) {
|
||||
publishError.value = describeError(cause, errors.common.unknown);
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
function discard(): void {
|
||||
base.value = 0;
|
||||
yaml.value = "";
|
||||
publishError.value = "";
|
||||
void latest.reload();
|
||||
}
|
||||
|
||||
const view = computed(() => (["yaml", "triggers"].includes(String(route.query.view)) ? String(route.query.view) : "canvas"));
|
||||
function showView(v: unknown): void {
|
||||
void router.replace({ query: { ...route.query, view: v === "canvas" ? undefined : String(v) } });
|
||||
}
|
||||
const open = ref<string | null>(null);
|
||||
const displayed = computed(() => (viewingOld.value ? (shown.data.value?.body ?? "") : yaml.value));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader :title="name">
|
||||
<Badge v-if="edited" variant="outline">Unpublished changes</Badge>
|
||||
<Select v-if="versions.length > 1" :model-value="String(versionParam || latest.data.value?.version)" @update:model-value="pickVersion">
|
||||
<SelectTrigger size="sm" aria-label="Version"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="v in versions" :key="v" :value="v">Version {{ v }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Badge v-else-if="latest.data.value" variant="outline">Version {{ latest.data.value.version }}</Badge>
|
||||
<Button size="sm" variant="outline" as-child><RouterLink :to="{ path: '/runs', query: { workflow: name } }">Runs</RouterLink></Button>
|
||||
</PageHeader>
|
||||
<ReadError v-if="latest.error.value" :message="latest.error.value" retry-label="Retry" @retry="latest.reload" />
|
||||
<div v-else-if="!latest.data.value" role="status" aria-label="Loading workflow"><Skeleton class="h-96 w-full" /></div>
|
||||
<template v-else>
|
||||
<Tabs :model-value="view" class="mb-3" @update:model-value="showView">
|
||||
<TabsList variant="line" class="w-full justify-start">
|
||||
<TabsTrigger value="canvas" class="flex-none px-3">Canvas</TabsTrigger>
|
||||
<TabsTrigger value="yaml" class="flex-none px-3">YAML</TabsTrigger>
|
||||
<TabsTrigger value="triggers" class="flex-none px-3">Triggers</TabsTrigger>
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
<ReadError v-if="viewingOld && shown.error.value" :message="shown.error.value" retry-label="Retry" @retry="shown.reload" />
|
||||
<div v-if="view === 'canvas'" class="h-[70dvh] min-h-96">
|
||||
<WorkflowCanvas :yaml="displayed" readonly :open="open" @toggle="open = open === $event ? null : $event" />
|
||||
</div>
|
||||
<div v-else-if="view === 'yaml'" class="flex flex-col gap-2">
|
||||
<div v-if="!viewingOld" class="flex flex-wrap items-center justify-end gap-2">
|
||||
<p v-if="publishError" role="alert" class="mr-auto text-caption text-danger">{{ publishError }}</p>
|
||||
<Button size="sm" variant="outline" :disabled="!edited || busy" @click="discard">Discard</Button>
|
||||
<Button size="sm" :disabled="!edited || busy" @click="publish">Publish</Button>
|
||||
</div>
|
||||
<WorkflowYaml v-if="viewingOld" :model-value="displayed" readonly />
|
||||
<WorkflowYaml v-else v-model="yaml" />
|
||||
</div>
|
||||
<TriggerList v-else :workflow="name" />
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
File renamed without changes.
@@ -1,126 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { Plus } from "@lucide/vue";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
|
||||
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { api, describeError, type Run, type Trigger } from "@/lib/api";
|
||||
import { useRead } from "@/lib/use-read";
|
||||
import { stateTone } from "@/runs/state";
|
||||
import WorkflowYaml from "./WorkflowYaml.vue";
|
||||
|
||||
const router = useRouter();
|
||||
const workflows = useRead(() => api.workflowList());
|
||||
const triggers = useRead(() => api.triggers());
|
||||
const runs = useRead(() => api.runs());
|
||||
onMounted(() => {
|
||||
void workflows.reload();
|
||||
void triggers.reload();
|
||||
void runs.reload();
|
||||
});
|
||||
|
||||
interface Row {
|
||||
name: string;
|
||||
version: number;
|
||||
steps: number;
|
||||
updated: string;
|
||||
by?: string;
|
||||
triggers: Trigger[];
|
||||
last?: Run;
|
||||
}
|
||||
const rows = computed<Row[]>(() =>
|
||||
(workflows.data.value ?? []).map((w) => ({
|
||||
name: w.name,
|
||||
version: w.version,
|
||||
steps: w.steps?.length ?? 0,
|
||||
updated: w.created_at,
|
||||
by: w.created_by,
|
||||
triggers: (triggers.data.value ?? []).filter((t) => t.workflow === w.name),
|
||||
last: (runs.data.value ?? []).filter((r) => r.workflow === w.name).sort((a, b) => Date.parse(b.created_at) - Date.parse(a.created_at))[0],
|
||||
})),
|
||||
);
|
||||
const time = (at?: string) => (at ? Date.parse(at) : 0);
|
||||
const columns: DataTableColumn<Row>[] = [
|
||||
{ id: "name", label: "Workflow", fixed: true, sort: (r) => r.name },
|
||||
{ id: "triggers", label: "Started by" },
|
||||
{ id: "last", label: "Last run", sort: (r) => time(r.last?.created_at) },
|
||||
{ id: "steps", label: "Steps", hidden: true, sort: (r) => r.steps },
|
||||
{ id: "updated", label: "Published", sort: (r) => time(r.updated) },
|
||||
];
|
||||
function startedBy(row: Row): string {
|
||||
if (!row.triggers.length) return triggers.error.value ? "" : "Manual";
|
||||
return row.triggers.map((t) => (t.every ? `Every ${t.every}` : `${t.source} ${t.event_type}`)).join(", ");
|
||||
}
|
||||
|
||||
const creating = ref(false);
|
||||
const draft = ref({ name: "", body: "steps:\n - id: first\n type: agent.run\n settings:\n mission: |\n \n" });
|
||||
const busy = ref(false);
|
||||
const createError = ref("");
|
||||
async function create(): Promise<void> {
|
||||
busy.value = true;
|
||||
createError.value = "";
|
||||
const name = draft.value.name.trim();
|
||||
try {
|
||||
await api.putWorkflow(name, draft.value.body);
|
||||
creating.value = false;
|
||||
void router.push(`/workflows/${name}`);
|
||||
} catch (cause) {
|
||||
createError.value = describeError(cause, errors.common.unknown);
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader title="Workflows">
|
||||
<Button size="sm" aria-label="New workflow" title="New workflow" @click="creating = true"><Plus /></Button>
|
||||
</PageHeader>
|
||||
<ReadError v-if="workflows.error.value" :message="workflows.error.value" retry-label="Retry" @retry="workflows.reload" />
|
||||
<div v-else-if="!workflows.data.value" role="status" aria-label="Loading workflows" class="space-y-2"><Skeleton class="h-8 w-full" /><Skeleton class="h-8 w-full" /></div>
|
||||
<template v-else>
|
||||
<p v-if="triggers.error.value || runs.error.value" role="alert" class="mb-2 text-caption text-danger">{{ triggers.error.value || runs.error.value }}</p>
|
||||
<DataTable
|
||||
:columns="columns"
|
||||
:rows="rows"
|
||||
:row-key="(r) => r.name"
|
||||
:row-link="(r) => `/workflows/${r.name}`"
|
||||
:row-label="(r) => r.name"
|
||||
storage-key="workflows"
|
||||
:initial-sort="{ id: 'name', desc: false }"
|
||||
>
|
||||
<template #cell-name="{ row }"><span class="font-medium">{{ row.name }}</span> <span class="text-caption text-fg-subtle">v{{ row.version }}</span></template>
|
||||
<template #cell-triggers="{ row }"><span class="text-caption text-fg-muted">{{ startedBy(row) }}</span></template>
|
||||
<template #cell-last="{ row }">
|
||||
<span v-if="row.last" class="flex items-center gap-2"><Badge :variant="stateTone(row.last.state)">{{ row.last.state }}</Badge><Timestamp class="text-caption text-fg-muted" :at="row.last.created_at" /></span>
|
||||
</template>
|
||||
<template #cell-steps="{ row }">{{ row.steps }}</template>
|
||||
<template #cell-updated="{ row }"><Timestamp :at="row.updated" /><span v-if="row.by" class="text-caption text-fg-muted"> by {{ row.by }}</span></template>
|
||||
<template #empty><Empty><EmptyHeader><EmptyTitle>No workflows</EmptyTitle></EmptyHeader></Empty></template>
|
||||
</DataTable>
|
||||
</template>
|
||||
|
||||
<Dialog v-model:open="creating">
|
||||
<DialogContent class="sm:max-w-2xl">
|
||||
<DialogHeader><DialogTitle>New workflow</DialogTitle></DialogHeader>
|
||||
<form id="new-workflow" class="flex min-h-0 flex-col gap-3" @submit.prevent="create">
|
||||
<Input v-model="draft.name" aria-label="Name" placeholder="Name" pattern="[a-z0-9]+([.\-][a-z0-9]+)*" required />
|
||||
<WorkflowYaml v-model="draft.body" class="max-h-[60dvh]" />
|
||||
<p v-if="createError" role="alert" class="text-caption text-danger">{{ createError }}</p>
|
||||
</form>
|
||||
<DialogFooter><Button type="submit" form="new-workflow" :disabled="busy || !draft.name">Publish</Button></DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
</template>
|
||||
@@ -39,8 +39,8 @@ const props = defineProps<{
|
||||
const emit = defineEmits<{ retry: [] }>();
|
||||
|
||||
const runColumns: DataTableColumn<WorkflowRun>[] = [
|
||||
{ id: "title", label: "Run", fixed: true, class: "w-full max-w-0" },
|
||||
{ id: "source", label: "Source", class: "max-sm:hidden" },
|
||||
{ id: "title", label: "Run", fixed: true, width: "auto" },
|
||||
{ id: "source", label: "Source", hide: "sm" },
|
||||
{ id: "status", label: "Status", sort: (run) => run.status ?? "" },
|
||||
{ id: "created", label: "Started", sort: (run) => run.created_at ?? "" },
|
||||
];
|
||||
@@ -52,7 +52,7 @@ const stageColumns: DataTableColumn<StageStats>[] = [
|
||||
{ id: "stage", label: "Stage", fixed: true },
|
||||
{ id: "runs", label: "Runs", sort: (s) => s.runs },
|
||||
{ id: "errors", label: "Failures", sort: (s) => s.errors },
|
||||
{ id: "avg", label: "Average", sort: (s) => s.avg_ms || 0, class: "sm:w-48" },
|
||||
{ id: "avg", label: "Average", sort: (s) => s.avg_ms || 0, width: "12rem" },
|
||||
];
|
||||
|
||||
function source(run: WorkflowRun): string {
|
||||
|
||||
Reference in new issue
Block a user