feat(webui): make attempts a pager above the tabs

The attempt selector becomes an icon-ended pager from the registry
pagination primitive: chevrons walk run history, numbers land on an
attempt, and the active page is the attempt on screen. It sits top-right
above the tab card, and the meta line loses the attempt text fact since
the control now carries it.
This commit is contained in:
sam committed 2026-09-21 00:25:54 +10:00
1 parent cf11f63271
commit 450a2d785a
14 files changed
+348 -49

No files matched your search

+55 -38
View File
@@ -1,57 +1,74 @@
<script setup lang="ts">
import { computed } from "vue";
import { Badge } from "@/components/ui/badge";
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
import {
Pagination,
PaginationContent,
PaginationEllipsis,
PaginationItem,
PaginationNext,
PaginationPrevious,
} from "@/components/ui/pagination";
import { stageStatusMeta } from "./stage-rail";
import { useTaskRun } from "./use-task-run";
/**
* The attempts of this task, each a pill carrying its own status and stage
* count. Selection is the page's, and the stage rail reads the same response,
* so the two views of the same task's attempts can never disagree about which
* one is on screen.
* The attempts of this task as a pager, sitting above the tab card: chevrons
* walk run history, the numbers land on an attempt directly, and the attempt
* on screen reads as the active page. Selection is the page's, and the stage
* rail reads the same response, so the two views of the same task's attempts
* can never disagree about which one is on screen.
*
* One attempt renders the rail anyway, disabled: the control states "there is
* exactly one run" by being inert rather than by disappearing, which is what
* the old text fact ("attempt 1 of 1") said without saying it as navigation.
*/
const run = useTaskRun();
const attempts = computed(() => run.attempts?.attempts ?? []);
const selected = computed(() => (run.attemptNumber == null ? "" : String(run.attemptNumber)));
const selected = computed(() =>
attempts.value.findIndex((a) => Number(a.attempt) === Number(run.attemptNumber)),
);
function select(value: unknown): void {
// Re-pressing the selected attempt deselects it (a single-typed group answers
// ""), which is not an attempt: keep the selection rather than moving to
// none.
const n = Number(value);
if (Number.isInteger(n) && n > 0) run.selectAttempt(n);
}
// reka's pagination counts pages over items; one attempt per page makes the
// page number an index into the run history. The controlled page keeps the
// URL (`?attempt=N`) the single source of truth.
const page = computed(() => (selected.value >= 0 ? selected.value + 1 : undefined));
function stageCount(attempt: { stages?: unknown[] }): string {
const n = (attempt.stages || []).length;
return `${n} stage${n === 1 ? "" : "s"}`;
function select(p: number): void {
const attempt = attempts.value[p - 1];
if (attempt) run.selectAttempt(Number(attempt.attempt));
}
</script>
<template>
<ToggleGroup
v-if="attempts.length"
type="single"
variant="outline"
:spacing="2"
:model-value="selected"
<Pagination
v-if="attempts.length && selected >= 0"
:items-per-page="1"
:total="attempts.length"
:page="page"
:sibling-count="1"
aria-label="Attempts of this task"
class="mb-4 flex-wrap"
@update:model-value="select"
class="mx-0"
@update:page="select"
>
<ToggleGroupItem
v-for="attempt in attempts"
:key="attempt.attempt"
:value="String(attempt.attempt)"
class="gap-2 rounded-full px-3"
>
<span class="font-medium">Attempt {{ attempt.attempt }}</span>
<Badge :variant="stageStatusMeta(attempt.status).kind">{{ stageStatusMeta(attempt.status).label }}</Badge>
<span class="text-xs text-fg-muted">{{ stageCount(attempt) }}</span>
</ToggleGroupItem>
</ToggleGroup>
</template>
<PaginationContent>
<PaginationPrevious size="icon-sm" class="border-transparent" />
<PaginationList v-slot="{ items }">
<template v-for="(item, i) in items" :key="i">
<PaginationEllipsis v-if="item.type === 'ellipsis'" :index="i" />
<PaginationItem
v-else
:value="item.value"
:is-active="item.value === page"
size="icon-sm"
:title="`Attempt ${attempts[item.value - 1]?.attempt}`"
>
{{ item.value }}
</PaginationItem>
</template>
</PaginationList>
<PaginationNext size="icon-sm" class="border-transparent" />
</PaginationContent>
</Pagination>
</template>
+3
View File
@@ -49,6 +49,9 @@ const run = provideTaskRun(taskId);
<Card>
<CardContent>
<div class="mb-2 flex justify-end">
<AttemptSelector />
</div>
<Tabs class="gap-4" :model-value="run.tab" @update:model-value="run.setTab">
<TabBar />
<TaskRunPanels :id="rawId" />
-8
View File
@@ -22,13 +22,6 @@ const run = useTaskRun();
// the Badge draws, which is what makes the cast honest rather than a guess.
const taskKind = computed<StatusKind>(() => statusKind(run.task?.status ?? "") as StatusKind);
const taskStatusLabel = computed(() => statusLabel(run.task?.status ?? ""));
const attemptText = computed(() => {
if (run.attempts === null) return "";
if (run.attempts === undefined) return "";
if (run.attemptNumber == null) return "";
return `attempt ${run.attemptNumber} of ${run.currentAttempt ?? run.attemptNumber}`;
});
</script>
<template>
@@ -37,7 +30,6 @@ const attemptText = computed(() => {
<template v-else-if="run.task">
<Badge :variant="taskKind">{{ taskStatusLabel }}</Badge>
</template>
<span v-if="attemptText" class="text-fg-muted">{{ attemptText }}</span>
<a
v-if="run.task?.repo_url"
class="text-link hover:underline"