deploy / plan (push) Successful in 6s
deploy / archied-image (push) Canceled after 0s
deploy / agent-image (push) Canceled after 0s
deploy / dist-zip (push) Canceled after 0s
deploy / gate (push) Canceled after 5m37s
ci/woodpecker/push/deploy Pipeline was canceled
244 lines
11 KiB
Vue
244 lines
11 KiB
Vue
<script setup lang="ts">
|
||
import { storeToRefs } from "pinia";
|
||
import { computed, reactive, ref } from "vue";
|
||
import { useRouter } from "vue-router";
|
||
|
||
import { ChevronDown, ChevronRight } from "@lucide/vue";
|
||
import { Badge } from "@/components/ui/badge";
|
||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||
import { Section } from "@/components/ui/section";
|
||
import { StatusDot } from "@/components/ui/status-dot";
|
||
import { Timestamp } from "@/components/ui/timestamp";
|
||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
|
||
import {
|
||
Table,
|
||
TableBody,
|
||
TableCell,
|
||
TableHead,
|
||
TableHeader,
|
||
TableRow,
|
||
} from "@/components/ui/table";
|
||
import { useSessionStore } from "@/stores/session";
|
||
import { useTasksStore } from "@/stores/tasks";
|
||
import { useAlerts } from "@/alerts/use-alerts";
|
||
import ActivityRow from "./ActivityRow.vue";
|
||
import { useOrgStore } from "@/stores/org";
|
||
import { activityDetail } from "./activity-detail";
|
||
import {
|
||
ACTIVITY_FILTERS,
|
||
activityEmptyTitle,
|
||
filterActivity,
|
||
type ActivityFilter,
|
||
} from "./activity-filter";
|
||
import { groupActivity, type ActivityGroup } from "./activity-group";
|
||
import { describeTimelineEvent } from "@/tasks/timeline-event";
|
||
|
||
const identities = useOrgStore();
|
||
identities.watchIdentities();
|
||
|
||
/**
|
||
* The last 50 events, newest first, with the stream's own state on the card and
|
||
* the All / Tasks / System filter over it. The filter and the grouping rules
|
||
* live in activity-filter.ts and activity-group.ts and are tested there; this
|
||
* card only renders their result.
|
||
*/
|
||
|
||
const router = useRouter();
|
||
const { summary } = storeToRefs(useTasksStore());
|
||
const running = computed(() => summary.value?.statuses?.running || 0);
|
||
|
||
// Open alerts lead the feed until resolved: a stream event scrolls away, the
|
||
// condition it reported does not.
|
||
const { alerts } = useAlerts();
|
||
|
||
const { activity } = storeToRefs(
|
||
useSessionStore(),
|
||
);
|
||
|
||
/** Which view of the feed is showing: everything, task runs, or the daemon's
|
||
* own background work. */
|
||
const filter = ref<ActivityFilter>("tasks");
|
||
const shown = computed(() => filterActivity(activity.value, filter.value));
|
||
// A blocked task already leads the page under Needs attention.
|
||
const pinned = computed(() =>
|
||
filter.value === "tasks"
|
||
? []
|
||
: alerts.value.filter((alert) => alert.kind !== "task.needs_decision"),
|
||
);
|
||
const emptyTitle = computed(() =>
|
||
activityEmptyTitle(shown.value.length, filter.value),
|
||
);
|
||
|
||
// Expansion is keyed on label:taskID, so a live run stays open as its events
|
||
// arrive, and a collapsed group re-collapses only when the run breaks.
|
||
const expanded = reactive(new Set<string>());
|
||
const groups = computed(() => groupActivity(shown.value));
|
||
|
||
function toggle(key: string) {
|
||
if (expanded.has(key)) expanded.delete(key);
|
||
else expanded.add(key);
|
||
}
|
||
|
||
function isOpen(group: ActivityGroup): boolean {
|
||
return expanded.has(group.key);
|
||
}
|
||
|
||
// The collapsed group row shows what its newest event would have shown, so
|
||
// expanding and collapsing moves no information.
|
||
function groupDetail(group: ActivityGroup) {
|
||
return activityDetail(group.representative, identities.identityName);
|
||
}
|
||
|
||
function openTask(taskID: number) {
|
||
void router.push(`/tasks?task=${encodeURIComponent(taskID)}`);
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<Section :title="running ? `Activity · ${running} running` : 'Activity'" class="mb-0">
|
||
<template #action>
|
||
<ToggleGroup type="single" variant="outline" size="sm" :model-value="filter" aria-label="Filter activity" @update:model-value="(value) => { if (value) filter = value as typeof filter; }">
|
||
<ToggleGroupItem v-for="option in ACTIVITY_FILTERS" :key="option.value" :value="option.value">{{ option.label }}</ToggleGroupItem>
|
||
</ToggleGroup>
|
||
</template>
|
||
<!--
|
||
role="region" names the table for landmark navigation; aria-live is
|
||
polite, not assertive, because rows arrive constantly while the stream
|
||
is live and an assertive region would talk over the operator. The live
|
||
region is the table's wrapper, so new rows are announced as they
|
||
appear without a second hidden summary to keep in sync.
|
||
-->
|
||
<div role="region" aria-label="Activity" aria-live="polite">
|
||
<!--
|
||
The feed's height is bounded to the card, not the page: group rows
|
||
multiply with the number of interleaved tasks, so an unbounded table
|
||
would push the rest of the dashboard off screen. The newest events
|
||
stay visible at the top; the rest scroll inside the card. The header
|
||
stays put via sticky so the columns keep their labels while scrolling.
|
||
-->
|
||
<div class="max-h-[28rem] overflow-y-auto">
|
||
<Table>
|
||
<TableHeader class="sticky top-0 z-10 bg-card">
|
||
<TableRow>
|
||
<TableHead>Event</TableHead>
|
||
<TableHead>Task</TableHead>
|
||
<TableHead>Detail</TableHead>
|
||
<TableHead>When</TableHead>
|
||
</TableRow>
|
||
</TableHeader>
|
||
<TableBody>
|
||
<TableRow v-for="alert in pinned" :key="`alert:${alert.id}`">
|
||
<TableCell class="font-medium">
|
||
<span class="inline-flex items-center gap-1.5">
|
||
<StatusDot tone="warn" />Alert
|
||
<Badge v-if="alert.count > 1" variant="idle">×{{ alert.count }}</Badge>
|
||
</span>
|
||
</TableCell>
|
||
<TableCell class="font-mono">–</TableCell>
|
||
<TableCell class="w-[55%] max-w-0">
|
||
<span class="flex items-center gap-3">
|
||
<Tooltip>
|
||
<TooltipTrigger as-child>
|
||
<span tabindex="0" class="min-w-0 flex-1 truncate">{{ alert.title }}</span>
|
||
</TooltipTrigger>
|
||
<TooltipContent v-if="alert.body">{{ alert.body }}</TooltipContent>
|
||
</Tooltip>
|
||
<RouterLink v-if="alert.link" :to="alert.link" class="shrink-0 text-warn hover:underline">Fix →</RouterLink>
|
||
</span>
|
||
</TableCell>
|
||
<TableCell><Timestamp :at="alert.last_seen" /></TableCell>
|
||
</TableRow>
|
||
<TableRow v-if="!shown.length && !pinned.length">
|
||
<TableCell colspan="4">
|
||
<Empty>
|
||
<EmptyHeader>
|
||
<EmptyTitle>{{ emptyTitle }}</EmptyTitle>
|
||
</EmptyHeader>
|
||
</Empty>
|
||
</TableCell>
|
||
</TableRow>
|
||
<template v-if="shown.length">
|
||
<template v-for="group in groups" :key="group.key">
|
||
<!-- A singleton is exactly the row the raw feed would show. -->
|
||
<ActivityRow
|
||
v-if="group.count === 1"
|
||
:event="group.representative"
|
||
@open="openTask"
|
||
/>
|
||
<template v-else>
|
||
<!--
|
||
The row stays a row: mouse clicks open the task via the
|
||
row handler, and the first cell holds the two real focus
|
||
targets -- the disclosure button and, when the group
|
||
resolves to a task, an open button carrying its title.
|
||
-->
|
||
<TableRow
|
||
:class="group.taskID > 0 ? 'cursor-pointer' : ''"
|
||
@click="group.taskID > 0 && openTask(group.taskID)"
|
||
>
|
||
<TableCell class="font-medium">
|
||
<div class="flex items-center gap-1">
|
||
<button
|
||
type="button"
|
||
class="inline-flex items-center rounded hover:opacity-80 focus-visible:outline-2 focus-visible:outline-ring"
|
||
:aria-expanded="isOpen(group)"
|
||
:aria-label="`${isOpen(group) ? 'Hide' : 'Show'} ${group.count} ${group.label} events`"
|
||
@click.stop="toggle(group.key)"
|
||
>
|
||
<ChevronDown
|
||
v-if="isOpen(group)"
|
||
class="size-3.5 shrink-0 text-fg-subtle"
|
||
/>
|
||
<ChevronRight
|
||
v-else
|
||
class="size-3.5 shrink-0 text-fg-subtle"
|
||
/>
|
||
</button>
|
||
<button
|
||
v-if="group.taskID > 0"
|
||
type="button"
|
||
class="inline-flex items-center gap-1 rounded hover:opacity-80 focus-visible:outline-2 focus-visible:outline-ring"
|
||
aria-label="Open task details"
|
||
@click.stop="openTask(group.taskID)"
|
||
>
|
||
{{ describeTimelineEvent({ ...group.representative, at: undefined, detail: undefined }).title }}
|
||
<Badge variant="idle">×{{ group.count }}</Badge>
|
||
</button>
|
||
<template v-else>
|
||
{{ describeTimelineEvent({ ...group.representative, at: undefined, detail: undefined }).title }}
|
||
<Badge variant="idle">×{{ group.count }}</Badge>
|
||
</template>
|
||
</div>
|
||
</TableCell>
|
||
<TableCell class="font-mono">{{
|
||
group.taskID > 0 ? `#${group.taskID}` : "–"
|
||
}}</TableCell>
|
||
<TableCell class="w-[55%] max-w-0">
|
||
<Tooltip>
|
||
<TooltipTrigger as-child>
|
||
<span tabindex="0" class="block truncate">{{ groupDetail(group).text }}</span>
|
||
</TooltipTrigger>
|
||
<TooltipContent v-if="groupDetail(group).truncated">{{ groupDetail(group).full }}</TooltipContent>
|
||
</Tooltip>
|
||
</TableCell>
|
||
<TableCell><Timestamp :at="group.representative.at" /></TableCell>
|
||
</TableRow>
|
||
<template v-if="isOpen(group)">
|
||
<ActivityRow
|
||
v-for="(event, i) in group.events"
|
||
:key="`${group.key}:${i}`"
|
||
:event="event"
|
||
@open="openTask"
|
||
/>
|
||
</template>
|
||
</template>
|
||
</template>
|
||
</template>
|
||
</TableBody>
|
||
</Table>
|
||
</div>
|
||
</div>
|
||
</Section>
|
||
</template>
|