refactor(ui): build the task list on DataTable with sortable columns and row links
This commit is contained in:
1 parent
ffafc3a989
commit
793569f6e1
15 files changed
+349
-518
No files matched your search
@@ -1,7 +1,8 @@
|
||||
<script setup lang="ts" generic="Row">
|
||||
import { computed } from "vue";
|
||||
import { computed, ref } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import { useLocalStorage } from "@vueuse/core";
|
||||
import { Columns3 } from "@lucide/vue";
|
||||
import { ArrowDown, ArrowUp, ArrowUpDown, Columns3 } from "@lucide/vue";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
@@ -11,71 +12,116 @@ import {
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
|
||||
export interface DataTableColumn {
|
||||
id: string;
|
||||
label: string;
|
||||
/** Always shown and not offered in the column picker. */
|
||||
fixed?: boolean;
|
||||
/** Hidden until the operator turns it on. */
|
||||
hidden?: boolean;
|
||||
class?: string;
|
||||
}
|
||||
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.
|
||||
* under `storageKey`. Cells render through `#cell-<id>` slots, given the row;
|
||||
* `#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.
|
||||
*/
|
||||
const props = defineProps<{
|
||||
columns: DataTableColumn[];
|
||||
columns: DataTableColumn<Row>[];
|
||||
rows: Row[];
|
||||
rowKey: (row: Row) => string;
|
||||
storageKey: string;
|
||||
rowLink?: (row: Row) => string;
|
||||
rowLabel?: (row: Row) => string;
|
||||
}>();
|
||||
const slots = defineSlots<Record<string, (props: { row: Row }) => unknown> & { empty?: () => unknown; actions?: (props: { row: Row }) => unknown }>();
|
||||
|
||||
const router = useRouter();
|
||||
const chosen = useLocalStorage<string[]>(
|
||||
`archie.columns.${props.storageKey}`,
|
||||
props.columns.filter((c) => !c.fixed && !c.hidden).map((c) => c.id),
|
||||
);
|
||||
const shown = computed(() => props.columns.filter((c) => c.fixed || chosen.value.includes(c.id)));
|
||||
const optional = computed(() => props.columns.filter((c) => !c.fixed));
|
||||
const trailing = computed(() => optional.value.length > 0 || !!slots.actions);
|
||||
function toggle(id: string, on: boolean): void {
|
||||
chosen.value = on ? [...chosen.value, id] : chosen.value.filter((c) => c !== id);
|
||||
}
|
||||
|
||||
// Sorting covers the loaded rows only.
|
||||
const sortBy = ref<{ id: string; desc: boolean } | null>(null);
|
||||
function cycleSort(id: string): void {
|
||||
const current = sortBy.value;
|
||||
sortBy.value = current?.id !== id ? { id, desc: false } : current.desc ? null : { id, desc: true };
|
||||
}
|
||||
const sorted = computed(() => {
|
||||
const key = sortBy.value && props.columns.find((c) => c.id === sortBy.value?.id)?.sort;
|
||||
if (!key) return props.rows;
|
||||
const sign = sortBy.value?.desc ? -1 : 1;
|
||||
return [...props.rows].sort((a, b) => {
|
||||
const x = key(a);
|
||||
const y = key(b);
|
||||
return sign * (typeof x === "number" && typeof y === "number" ? x - y : String(x).localeCompare(String(y)));
|
||||
});
|
||||
});
|
||||
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);
|
||||
|
||||
function open(row: Row): void {
|
||||
if (props.rowLink) void router.push(props.rowLink(row));
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead v-for="column in shown" :key="column.id" :class="column.class">{{ column.label }}</TableHead>
|
||||
<TableHead v-if="optional.length" class="w-0 text-right">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger as-child>
|
||||
<Button variant="ghost" size="icon-sm" aria-label="Columns" title="Columns"><Columns3 /></Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuCheckboxItem
|
||||
v-for="column in optional"
|
||||
:key="column.id"
|
||||
:model-value="chosen.includes(column.id)"
|
||||
@update:model-value="toggle(column.id, $event)"
|
||||
@select.prevent
|
||||
>{{ column.label }}</DropdownMenuCheckboxItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<TableRow v-for="row in rows" :key="rowKey(row)" class="align-top">
|
||||
<TableCell v-for="column in shown" :key="column.id" :class="column.class">
|
||||
<slot :name="`cell-${column.id}`" :row="row" />
|
||||
</TableCell>
|
||||
<TableCell v-if="optional.length" />
|
||||
</TableRow>
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead
|
||||
v-for="column in shown"
|
||||
:key="column.id"
|
||||
:class="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)">
|
||||
{{ column.label }}<component :is="sortIcon(column.id)" data-icon="inline-end" />
|
||||
</Button>
|
||||
<template v-else>{{ column.label }}</template>
|
||||
</TableHead>
|
||||
<TableHead v-if="trailing" class="w-0 text-right">
|
||||
<DropdownMenu v-if="optional.length">
|
||||
<DropdownMenuTrigger as-child>
|
||||
<Button variant="ghost" size="icon-sm" aria-label="Columns" title="Columns"><Columns3 /></Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuCheckboxItem
|
||||
v-for="column in optional"
|
||||
:key="column.id"
|
||||
:model-value="chosen.includes(column.id)"
|
||||
@update:model-value="toggle(column.id, $event)"
|
||||
@select.prevent
|
||||
>{{ column.label }}</DropdownMenuCheckboxItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<span v-else class="sr-only">Actions</span>
|
||||
</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<TableRow v-if="!rows.length && slots.empty">
|
||||
<TableCell :colspan="shown.length + (trailing ? 1 : 0)"><slot name="empty" /></TableCell>
|
||||
</TableRow>
|
||||
<TableRow
|
||||
v-for="row in sorted"
|
||||
:key="rowKey(row)"
|
||||
:data-row-key="rowKey(row)"
|
||||
:tabindex="rowLink ? 0 : undefined"
|
||||
:role="rowLink ? 'link' : undefined"
|
||||
:aria-label="rowLink && rowLabel ? rowLabel(row) : undefined"
|
||||
:class="['align-top', rowLink && 'cursor-pointer']"
|
||||
@click="open(row)"
|
||||
@keydown.enter.self.prevent="open(row)"
|
||||
@keydown.space.self.prevent="open(row)"
|
||||
>
|
||||
<TableCell v-for="column in shown" :key="column.id" :class="column.class">
|
||||
<slot :name="`cell-${column.id}`" :row="row" />
|
||||
</TableCell>
|
||||
<TableCell v-if="trailing"><slot name="actions" :row="row" /></TableCell>
|
||||
</TableRow>
|
||||
</TableBody>
|
||||
</Table>
|
||||
</template>
|
||||
@@ -1,2 +1,2 @@
|
||||
export { default as DataTable } from "./DataTable.vue";
|
||||
export type { DataTableColumn } from "./DataTable.vue";
|
||||
export type { DataTableColumn } from "./types";
|
||||
@@ -0,0 +1,11 @@
|
||||
export interface DataTableColumn<Row = never> {
|
||||
id: string;
|
||||
label: string;
|
||||
/** Always shown and not offered in the column picker. */
|
||||
fixed?: boolean;
|
||||
/** Hidden until the operator turns it on. */
|
||||
hidden?: boolean;
|
||||
class?: string;
|
||||
/** Makes the header sort the loaded rows by this value. */
|
||||
sort?: (row: Row) => string | number;
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import { Badge } from "@/components/ui/badge";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { attentionStatusIds, statusLabel } from "@/lib/task-meta";
|
||||
import TaskRowActions from "@/tasks/TaskRowActions.vue";
|
||||
import type { Task } from "@/tasks/TaskRow.vue";
|
||||
import type { Task } from "@/tasks/task";
|
||||
import { useTasksStore } from "@/stores/tasks";
|
||||
|
||||
const { tasks } = storeToRefs(useTasksStore());
|
||||
|
||||
@@ -35,7 +35,7 @@ let timer: ReturnType<typeof setInterval> | undefined;
|
||||
|
||||
const tone = { up: "ok", degraded: "warn", down: "danger", unknown: "idle" } as const;
|
||||
|
||||
const columns = (agent: boolean): DataTableColumn[] => [
|
||||
const columns = (agent: boolean): DataTableColumn<Service>[] => [
|
||||
{ id: "name", label: agent ? "Task" : "Service", fixed: true },
|
||||
{ id: "version", label: "Version" },
|
||||
{ id: "install", label: "Runs as", hidden: true },
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Badge } from "@/components/ui/badge";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import TaskRowActions from "./TaskRowActions.vue";
|
||||
import type { Task } from "./TaskRow.vue";
|
||||
import type { Task } from "./task";
|
||||
import { reviewGateOffer } from "./review-gate";
|
||||
|
||||
const props = defineProps<{ task: Task }>();
|
||||
|
||||
@@ -1,201 +0,0 @@
|
||||
<script lang="ts">
|
||||
/**
|
||||
* The task fields this folder reads. One shape for the list, its table, its
|
||||
* filters and the row itself, declared on the component that renders it.
|
||||
*/
|
||||
export interface Task {
|
||||
id: number | string;
|
||||
title?: string;
|
||||
owner?: string;
|
||||
repo?: string;
|
||||
repo_url?: string;
|
||||
issue_number?: number;
|
||||
issue_url?: string;
|
||||
pr_number?: number;
|
||||
pr_url?: string;
|
||||
source?: string;
|
||||
status?: string;
|
||||
park_class?: string;
|
||||
park_reason?: string;
|
||||
tokens_used?: number;
|
||||
workflow?: string;
|
||||
/** The exact definition the run pinned. */
|
||||
workflow_definition_yaml?: string;
|
||||
attempt?: number;
|
||||
/** The branch this task pushed, if any. A retry that continues pushed work
|
||||
* resumes it; the retry dialog disables that mode when it is empty. */
|
||||
branch?: string;
|
||||
/** The operator's persisted worktree choice for the next retry dispatch
|
||||
* ("refresh_onto_base" or "continue_pushed_work"). The retry dialog opens
|
||||
* on this value so the choice survives a reload. */
|
||||
retry_mode?: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
actions?: string[];
|
||||
/** The operator-approval gate's document, as JSON. The rereview dialog
|
||||
* reads its round count; a task without one never answers a gate. */
|
||||
review_gate?: string;
|
||||
/** How many re-reviews this gate has granted, against the server's cap. */
|
||||
rereview_rounds?: number;
|
||||
}
|
||||
</script>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
import { RouterLink, useRouter } from "vue-router";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { TableCell, TableRow } from "@/components/ui/table";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
import { ago } from "@/lib/format";
|
||||
import { statusKind, statusLabel } from "@/lib/task-meta";
|
||||
import TaskRowActions from "./TaskRowActions.vue";
|
||||
|
||||
/**
|
||||
* One task. The whole row opens the task's run detail, which is why it carries
|
||||
* link semantics and a keyboard path of its own: every control inside it has to
|
||||
* stop the event on its way out, or activating a button would also navigate.
|
||||
*/
|
||||
const props = withDefaults(defineProps<{ task: Task; showRepo?: boolean; showIssue?: boolean }>(), {
|
||||
showRepo: true,
|
||||
showIssue: true,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{ done: [taskId: Task["id"]] }>();
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
// Lifecycle vocabulary is the served catalog, never a hand-synced copy: the
|
||||
// label and the severity both come from task-meta, so a status the backend
|
||||
// knows renders with the right words and the right colour.
|
||||
const label = computed(() => statusLabel(props.task.status ?? ""));
|
||||
const kind = computed(() => statusKind(props.task.status ?? ""));
|
||||
|
||||
const parkClassLabels: Record<string, string> = {
|
||||
needs_human: "needs attention",
|
||||
transient: "transient",
|
||||
terminal: "terminal",
|
||||
};
|
||||
const parkClassLabel = computed(
|
||||
() => parkClassLabels[props.task.park_class ?? ""] ?? "",
|
||||
);
|
||||
const parkClassTitle = computed(() => {
|
||||
switch (props.task.park_class) {
|
||||
case "transient":
|
||||
return "Environmental failure: a requeue can succeed";
|
||||
case "terminal":
|
||||
return "Retry cannot succeed: archive or re-create the work";
|
||||
default:
|
||||
return "An operator decision is needed";
|
||||
}
|
||||
});
|
||||
const title = computed(() => props.task.title || "untitled task");
|
||||
|
||||
// Chat-sourced work has no forge issue behind it, so there is no page to open
|
||||
// and the number stands on its own.
|
||||
const issueHref = computed(() => {
|
||||
if (props.task.source === "chat" || props.task.source === "test") return "";
|
||||
if (!props.task.issue_url || !props.task.issue_number) return "";
|
||||
return props.task.issue_url;
|
||||
});
|
||||
|
||||
function open() {
|
||||
void router.push(`/tasks/${props.task.id}`);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<TableRow
|
||||
:id="`task-row-${props.task.id}`"
|
||||
tabindex="0"
|
||||
role="link"
|
||||
:aria-label="`Open the run detail for ${title}`"
|
||||
class="cursor-pointer"
|
||||
@click="open"
|
||||
@keydown.enter.prevent="open"
|
||||
@keydown.space.prevent="open"
|
||||
>
|
||||
<!--
|
||||
The repo column is dropped when every visible row shares it, so the width
|
||||
it would repeat goes to the title instead. Truncated rather than wrapped:
|
||||
an owner/name is one token and breaking it mid-word reads as two.
|
||||
-->
|
||||
<TableCell v-if="props.showRepo" class="text-fg-muted max-w-40 truncate">
|
||||
<a
|
||||
v-if="props.task.repo_url"
|
||||
class="hover:text-foreground hover:underline"
|
||||
:href="props.task.repo_url"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
:title="`Open ${props.task.owner}/${props.task.repo} on the forge`"
|
||||
@click.stop
|
||||
@keydown.stop
|
||||
>
|
||||
{{ props.task.owner }}/{{ props.task.repo }}
|
||||
</a>
|
||||
<template v-else>{{ props.task.owner }}/{{ props.task.repo }}</template>
|
||||
</TableCell>
|
||||
<TableCell v-if="props.showIssue" class="text-fg-muted">
|
||||
<a
|
||||
v-if="issueHref"
|
||||
class="hover:text-foreground hover:underline"
|
||||
:href="issueHref"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
:title="`Open issue #${props.task.issue_number} on the forge`"
|
||||
@click.stop
|
||||
@keydown.stop
|
||||
>#{{ props.task.issue_number }}</a
|
||||
>
|
||||
<template v-else-if="props.task.source !== 'chat' && props.task.source !== 'test'">#{{ props.task.issue_number }}</template>
|
||||
</TableCell>
|
||||
<!--
|
||||
The floor belongs on the link, not the cell: a table cell ignores
|
||||
min-width, so a floor there is dropped and the title wraps to one word a
|
||||
line as soon as the table is narrower than its columns.
|
||||
-->
|
||||
<TableCell class="w-full whitespace-normal">
|
||||
<RouterLink
|
||||
class="inline-block min-w-40 hover:underline"
|
||||
:to="`/tasks/${props.task.id}`"
|
||||
@click.stop
|
||||
@keydown.stop
|
||||
>
|
||||
{{ title }}
|
||||
</RouterLink>
|
||||
<Badge v-if="props.task.source === 'test'" variant="outline" class="ml-2" title="Ran an unsaved draft; forge writes were skipped">Test</Badge>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<span class="inline-flex items-center gap-1">
|
||||
<Badge :variant="kind">{{ label }}</Badge>
|
||||
<!--
|
||||
The park's class (taskstate.ParkClass), recorded at the park site:
|
||||
it answers what kind of intervention this park needs, which the
|
||||
bare Parked badge never could. A chip only when parked; a queued
|
||||
or running task carries no class worth showing.
|
||||
-->
|
||||
<Badge
|
||||
v-if="props.task.status === 'parked' && parkClassLabel"
|
||||
variant="outline"
|
||||
:title="parkClassTitle"
|
||||
>
|
||||
{{ parkClassLabel }}
|
||||
</Badge>
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell class="text-fg-muted">{{
|
||||
props.task.workflow || "—"
|
||||
}}</TableCell>
|
||||
<TableCell
|
||||
class="text-fg-muted"
|
||||
:title="
|
||||
props.task.created_at ? `Created ${ago(props.task.created_at)}` : ''
|
||||
"
|
||||
>
|
||||
<Timestamp :at="props.task.updated_at" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<TaskRowActions :task="props.task" @done="emit('done', $event)" />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</template>
|
||||
@@ -29,7 +29,7 @@ import { Label } from "@/components/ui/label";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { api, classifyActionError, type ActionErrorKind } from "@/lib/api";
|
||||
import { actionFor, retryModes, type ActionMeta } from "@/lib/task-meta";
|
||||
import type { Task } from "./TaskRow.vue";
|
||||
import type { Task } from "./task";
|
||||
import { shownActionIds } from "./task-actions";
|
||||
import { reviewGateOffer } from "./review-gate";
|
||||
import {
|
||||
|
||||
+98
-114
@@ -1,26 +1,14 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
import { ArrowDown, ArrowUp, ArrowUpDown } from "@lucide/vue";
|
||||
import {
|
||||
createColumnHelper,
|
||||
createSortedRowModel,
|
||||
rowSortingFeature,
|
||||
sortFn_basic,
|
||||
sortFn_text,
|
||||
tableFeatures,
|
||||
useTable,
|
||||
} from "@tanstack/vue-table";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { RouterLink } from "vue-router";
|
||||
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import TaskRow, { type Task } from "./TaskRow.vue";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
import { ago } from "@/lib/format";
|
||||
import { statusKind, statusLabel } from "@/lib/task-meta";
|
||||
import type { Task } from "./task";
|
||||
import TaskRowActions from "./TaskRowActions.vue";
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{ tasks: Task[]; showRepo?: boolean; showIssue?: boolean }>(),
|
||||
@@ -29,101 +17,97 @@ const props = withDefaults(
|
||||
|
||||
const emit = defineEmits<{ done: [taskId: Task["id"]] }>();
|
||||
|
||||
const features = tableFeatures({
|
||||
rowSortingFeature,
|
||||
sortedRowModel: createSortedRowModel(),
|
||||
sortFns: { text: sortFn_text, basic: sortFn_basic },
|
||||
});
|
||||
const columnHelper = createColumnHelper<typeof features, Task>();
|
||||
const table = useTable({
|
||||
features,
|
||||
get data() {
|
||||
return props.tasks;
|
||||
},
|
||||
getRowId: (task: Task) => String(task.id),
|
||||
columns: columnHelper.columns([
|
||||
columnHelper.accessor((task) => `${task.owner ?? ""}/${task.repo ?? ""}`, {
|
||||
id: "repo",
|
||||
header: "Repo",
|
||||
sortFn: "text",
|
||||
}),
|
||||
columnHelper.accessor((task) => task.issue_number ?? 0, {
|
||||
id: "issue",
|
||||
header: "Issue",
|
||||
sortFn: "basic",
|
||||
}),
|
||||
columnHelper.accessor((task) => task.title ?? "untitled task", {
|
||||
id: "title",
|
||||
header: "Title",
|
||||
sortFn: "text",
|
||||
}),
|
||||
columnHelper.accessor((task) => task.status ?? "", {
|
||||
id: "status",
|
||||
header: "Status",
|
||||
sortFn: "text",
|
||||
}),
|
||||
columnHelper.accessor((task) => task.workflow ?? "", {
|
||||
id: "workflow",
|
||||
header: "Workflow",
|
||||
sortFn: "text",
|
||||
}),
|
||||
columnHelper.accessor((task) => Date.parse(task.updated_at ?? "") || 0, {
|
||||
id: "activity",
|
||||
header: "Last activity",
|
||||
sortFn: "basic",
|
||||
}),
|
||||
]),
|
||||
});
|
||||
const headers = computed(() =>
|
||||
table
|
||||
.getAllColumns()
|
||||
.filter((column) => (props.showRepo || column.id !== "repo") && (props.showIssue || column.id !== "issue")),
|
||||
);
|
||||
// shortcut: sorting covers loaded rows; use server sorting if all pages must be ordered.
|
||||
const rows = computed(() => table.getRowModel().rows);
|
||||
const columns = computed(() => headers.value.length + 1);
|
||||
const title = (task: Task) => task.title || "untitled task";
|
||||
|
||||
// The repo and issue columns are dropped when every visible row shares them,
|
||||
// so the width they would repeat goes to the title.
|
||||
const columns = computed<DataTableColumn<Task>[]>(() => [
|
||||
...(props.showRepo
|
||||
? [{ id: "repo", label: "Repo", class: "max-w-40 truncate 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 },
|
||||
{ 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 },
|
||||
]);
|
||||
|
||||
const parkClassLabels: Record<string, string> = {
|
||||
needs_human: "needs attention",
|
||||
transient: "transient",
|
||||
terminal: "terminal",
|
||||
};
|
||||
function parkClassTitle(task: Task): string {
|
||||
switch (task.park_class) {
|
||||
case "transient":
|
||||
return "Environmental failure: a requeue can succeed";
|
||||
case "terminal":
|
||||
return "Retry cannot succeed: archive or re-create the work";
|
||||
default:
|
||||
return "An operator decision is needed";
|
||||
}
|
||||
}
|
||||
|
||||
// Chat-sourced work has no forge issue behind it, so there is no number.
|
||||
const forgeIssue = (task: Task) => task.source !== "chat" && task.source !== "test";
|
||||
const issueHref = (task: Task) => (forgeIssue(task) && task.issue_url && task.issue_number ? task.issue_url : "");
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead
|
||||
v-for="column in headers"
|
||||
:key="column.id"
|
||||
:class="column.id === 'title' ? 'w-full' : undefined"
|
||||
:aria-sort="
|
||||
column.getIsSorted() === 'asc' ? 'ascending' :
|
||||
column.getIsSorted() === 'desc' ? 'descending' : 'none'
|
||||
"
|
||||
>
|
||||
<Button variant="ghost" size="sm" class="-ml-2.5" @click="column.toggleSorting()">
|
||||
{{ column.columnDef.header }}
|
||||
<component
|
||||
:is="column.getIsSorted() === 'asc' ? ArrowUp : column.getIsSorted() === 'desc' ? ArrowDown : ArrowUpDown"
|
||||
data-icon="inline-end"
|
||||
/>
|
||||
</Button>
|
||||
</TableHead>
|
||||
<TableHead><span class="sr-only">Actions</span></TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<TableRow v-if="!props.tasks.length">
|
||||
<TableCell :colspan="columns">
|
||||
<slot name="state" />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
<template v-else>
|
||||
<TaskRow
|
||||
v-for="row in rows"
|
||||
:key="row.id"
|
||||
:task="row.original"
|
||||
:show-repo="props.showRepo"
|
||||
:show-issue="props.showIssue"
|
||||
@done="emit('done', $event)"
|
||||
/>
|
||||
</template>
|
||||
</TableBody>
|
||||
</Table>
|
||||
<DataTable
|
||||
:columns="columns"
|
||||
:rows="props.tasks"
|
||||
:row-key="(task) => String(task.id)"
|
||||
:row-link="(task) => `/tasks/${task.id}`"
|
||||
:row-label="(task) => `Open the run detail for ${title(task)}`"
|
||||
storage-key="tasks"
|
||||
>
|
||||
<template #empty><slot name="state" /></template>
|
||||
<template #cell-repo="{ row }">
|
||||
<a
|
||||
v-if="row.repo_url"
|
||||
class="hover:text-foreground hover:underline"
|
||||
:href="row.repo_url"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
@click.stop
|
||||
@keydown.stop
|
||||
>{{ row.owner }}/{{ row.repo }}</a
|
||||
>
|
||||
<template v-else>{{ row.owner }}/{{ row.repo }}</template>
|
||||
</template>
|
||||
<template #cell-issue="{ row }">
|
||||
<a
|
||||
v-if="issueHref(row)"
|
||||
class="hover:text-foreground hover:underline"
|
||||
:href="issueHref(row)"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
@click.stop
|
||||
@keydown.stop
|
||||
>#{{ row.issue_number }}</a
|
||||
>
|
||||
<template v-else-if="forgeIssue(row) && row.issue_number">#{{ row.issue_number }}</template>
|
||||
</template>
|
||||
<!-- The floor belongs on the link: a table cell ignores min-width. -->
|
||||
<template #cell-title="{ row }">
|
||||
<RouterLink class="inline-block min-w-40 hover:underline" :to="`/tasks/${row.id}`" @click.stop @keydown.stop>{{ title(row) }}</RouterLink>
|
||||
<Badge v-if="row.source === 'test'" variant="outline" class="ml-2" title="Ran an unsaved draft; forge writes were skipped">Test</Badge>
|
||||
</template>
|
||||
<template #cell-status="{ row }">
|
||||
<span class="inline-flex items-center gap-1">
|
||||
<Badge :variant="statusKind(row.status ?? '')">{{ statusLabel(row.status ?? "") }}</Badge>
|
||||
<Badge v-if="row.status === 'parked' && parkClassLabels[row.park_class ?? '']" variant="outline" :title="parkClassTitle(row)">
|
||||
{{ parkClassLabels[row.park_class ?? ""] }}
|
||||
</Badge>
|
||||
</span>
|
||||
</template>
|
||||
<template #cell-workflow="{ row }">{{ row.workflow || "—" }}</template>
|
||||
<template #cell-activity="{ row }">
|
||||
<Timestamp :at="row.updated_at" :title="row.created_at ? `Created ${ago(row.created_at)}` : undefined" />
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TaskRowActions :task="row" @done="emit('done', $event)" />
|
||||
</template>
|
||||
</DataTable>
|
||||
</template>
|
||||
@@ -28,7 +28,7 @@ import { statusList } from "@/lib/task-meta";
|
||||
import { useLiveResource } from "@/stores/session";
|
||||
import TaskFilters from "./TaskFilters.vue";
|
||||
import { boardStatus, initialTaskFilter } from "./task-filter";
|
||||
import type { Task } from "./TaskRow.vue";
|
||||
import type { Task } from "./task";
|
||||
import TaskTable from "./TaskTable.vue";
|
||||
import TasksState from "./TasksState.vue";
|
||||
|
||||
@@ -174,7 +174,7 @@ async function reveal(id: number) {
|
||||
// The row has to be in the DOM before it can be found or scrolled to.
|
||||
await nextTick();
|
||||
requestAnimationFrame(() => {
|
||||
const row = document.getElementById(`task-row-${id}`);
|
||||
const row = document.querySelector<HTMLElement>(`[data-row-key="${id}"]`);
|
||||
if (!row) return;
|
||||
row.focus({ preventScroll: true });
|
||||
// Optional call: focusing a deep-linked row is a nicety, and not every
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* The task fields this folder reads. One shape for the list, its table, its
|
||||
* filters and the row itself, declared on the component that renders it.
|
||||
*/
|
||||
export interface Task {
|
||||
id: number | string;
|
||||
title?: string;
|
||||
owner?: string;
|
||||
repo?: string;
|
||||
repo_url?: string;
|
||||
issue_number?: number;
|
||||
issue_url?: string;
|
||||
pr_number?: number;
|
||||
pr_url?: string;
|
||||
source?: string;
|
||||
status?: string;
|
||||
park_class?: string;
|
||||
park_reason?: string;
|
||||
tokens_used?: number;
|
||||
workflow?: string;
|
||||
/** The exact definition the run pinned. */
|
||||
workflow_definition_yaml?: string;
|
||||
attempt?: number;
|
||||
/** The branch this task pushed, if any. A retry that continues pushed work
|
||||
* resumes it; the retry dialog disables that mode when it is empty. */
|
||||
branch?: string;
|
||||
/** The operator's persisted worktree choice for the next retry dispatch
|
||||
* ("refresh_onto_base" or "continue_pushed_work"). The retry dialog opens
|
||||
* on this value so the choice survives a reload. */
|
||||
retry_mode?: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
actions?: string[];
|
||||
/** The operator-approval gate's document, as JSON. The rereview dialog
|
||||
* reads its round count; a task without one never answers a gate. */
|
||||
review_gate?: string;
|
||||
/** How many re-reviews this gate has granted, against the server's cap. */
|
||||
rereview_rounds?: number;
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import { api } from "@/lib/api";
|
||||
import { useLiveResource } from "@/stores/session";
|
||||
import type { StageRun } from "./workflow-graph";
|
||||
|
||||
import type { Task } from "@/tasks/TaskRow.vue";
|
||||
import type { Task } from "@/tasks/task";
|
||||
|
||||
export type WorkflowRun = Task & { workflow?: string };
|
||||
|
||||
|
||||
Reference in new issue
Block a user