114 lines
4.6 KiB
Vue
114 lines
4.6 KiB
Vue
<script setup lang="ts">
|
|
import { computed } from "vue";
|
|
import { RouterLink } from "vue-router";
|
|
|
|
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 }>(),
|
|
{ showRepo: true, showIssue: true },
|
|
);
|
|
|
|
const emit = defineEmits<{ done: [taskId: Task["id"]] }>();
|
|
|
|
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>
|
|
<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>
|