56 lines
3.0 KiB
Vue
56 lines
3.0 KiB
Vue
<script setup lang="ts">
|
|
import { ExternalLink, Workflow } from "@lucide/vue";
|
|
import { useRouter } from "vue-router";
|
|
|
|
import { Badge } from "@/components/ui/badge";
|
|
import { ContextMenuItem } from "@/components/ui/context-menu";
|
|
import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
|
|
import { Timestamp } from "@/components/ui/timestamp";
|
|
import { duration } from "@/lib/format";
|
|
import type { Run } from "@/lib/api";
|
|
import { stateLabel, stateTone } from "./state";
|
|
|
|
/** Workflow runs as a table. A workflow's own page leaves its name column out. */
|
|
const props = defineProps<{ rows: Run[]; storageKey: string; withWorkflow?: boolean }>();
|
|
const router = useRouter();
|
|
|
|
const time = (at?: string) => (at ? Date.parse(at) : 0);
|
|
const took = (run: Run) => (run.finished_at ? time(run.finished_at) - time(run.created_at) : -1);
|
|
const columns: DataTableColumn<Run>[] = [
|
|
...(props.withWorkflow ? [{ id: "workflow", label: "Workflow", fixed: true, width: "auto", sort: (r: Run) => r.workflow }] : []),
|
|
{ id: "state", label: "State", fixed: true, width: "9.5rem", sort: (r) => r.state },
|
|
{ id: "created", label: "Started", hide: "sm", width: "8rem", sort: (r) => time(r.created_at) },
|
|
{ id: "duration", label: "Took", hide: "sm", width: "6rem", sort: took },
|
|
{ id: "error", label: "Error", width: "24rem", hide: "md" },
|
|
{ id: "attempts", label: "Attempts", hidden: true, width: "7rem", sort: (r) => r.attempts },
|
|
{ id: "id", label: "Run", hidden: true, width: "14rem" },
|
|
];
|
|
</script>
|
|
|
|
<template>
|
|
<DataTable
|
|
:columns="columns"
|
|
:rows="rows"
|
|
:row-key="(r) => r.id"
|
|
:row-link="(r) => `/runs/${r.id}`"
|
|
:row-label="(r) => `${r.workflow} run`"
|
|
:storage-key="storageKey"
|
|
:initial-sort="{ id: 'created', desc: true }"
|
|
>
|
|
<template #cell-workflow="{ row }">
|
|
<span class="font-medium">{{ row.workflow }}</span> <span class="text-caption text-fg-subtle">v{{ row.workflow_version }}</span>
|
|
</template>
|
|
<template #cell-state="{ row }"><Badge :variant="stateTone(row.state)" :title="row.error || undefined">{{ stateLabel(row.state) }}</Badge></template>
|
|
<template #cell-created="{ row }"><Timestamp :at="row.created_at" /></template>
|
|
<template #cell-duration="{ row }"><span class="text-caption text-fg-muted">{{ took(row) >= 0 ? duration(took(row)) : "" }}</span></template>
|
|
<template #cell-error="{ row }"><span class="text-caption text-danger" :title="row.error">{{ row.error }}</span></template>
|
|
<template #cell-attempts="{ row }">{{ row.attempts }}</template>
|
|
<template #cell-id="{ row }"><span class="font-mono text-caption text-fg-muted">{{ row.id.slice(0, 8) }}</span></template>
|
|
<template #menu="{ row }">
|
|
<ContextMenuItem @select="router.push(`/runs/${row.id}`)"><ExternalLink />Open run</ContextMenuItem>
|
|
<ContextMenuItem v-if="row.workflow_id" @select="router.push(`/workflows/${row.workflow_id}`)"><Workflow />Open workflow</ContextMenuItem>
|
|
</template>
|
|
<template #empty><slot name="empty" /></template>
|
|
</DataTable>
|
|
</template>
|