feat(webui): collapse runs of background telemetry in live activity
The feed's 50 raw events were dominated by consecutive same-shape background rows (session-memory cycles, runner calls), which buried the milestones the dashboard exists to surface. Consecutive events sharing one label and one task now collapse into a group row with an xN badge; expanding it reveals its events in place. The grouping is consecutive, not global, so interleaved kinds keep their order and a milestone is never merged with an event that merely shares its kind. The projection is a pure view over the store's raw stream (activity-group.ts, table-tested); the store keeps every event. Group rows keep ActivityRow's link contract, and the disclosure button is stop-propagated inside the first cell so it never fights the row-level link.
This commit is contained in:
5 files changed
+205
-5
No files matched your search
@@ -1,19 +1,54 @@
|
||||
<script setup lang="ts">
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed, reactive } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
|
||||
import { ChevronDown, ChevronRight } from "@lucide/vue";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Card, CardAction, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import { ago } from "@/lib/format";
|
||||
import { useLiveUpdatesStore } from "@/stores/live-updates";
|
||||
import ActivityRow from "./ActivityRow.vue";
|
||||
import { activityDetail } from "./activity-detail";
|
||||
import { groupActivity, groupKey, type ActivityGroup } from "./activity-group";
|
||||
|
||||
/** The last 50 events, newest first, with the stream's own state on the card. */
|
||||
/**
|
||||
* The last 50 events, newest first, with the stream's own state on the card.
|
||||
* Runs of consecutive same-kind same-task events (the daemon's background
|
||||
* telemetry) collapse into one group row carrying an ×N badge; expanding one
|
||||
* reveals its events. The grouping lives in activity-group.ts and is tested
|
||||
* there; this card only renders it.
|
||||
*/
|
||||
|
||||
const router = useRouter();
|
||||
const { activity, streamKind, streamState } = storeToRefs(useLiveUpdatesStore());
|
||||
|
||||
// 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(activity.value));
|
||||
|
||||
function toggle(key: string) {
|
||||
if (expanded.has(key)) expanded.delete(key);
|
||||
else expanded.add(key);
|
||||
}
|
||||
|
||||
function isOpen(group: ActivityGroup): boolean {
|
||||
return expanded.has(groupKey(group.label, group.taskID));
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
function groupWhen(group: ActivityGroup) {
|
||||
return group.representative.at ? ago(group.representative.at) : "\u2014";
|
||||
}
|
||||
|
||||
function openTask(taskID: number) {
|
||||
void router.push(`/tasks?task=${encodeURIComponent(taskID)}`);
|
||||
}
|
||||
@@ -56,10 +91,56 @@ function openTask(taskID: number) {
|
||||
</Empty>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
<ActivityRow v-for="(event, i) in activity" v-else :key="i" :event="event" @open="openTask" />
|
||||
<template v-if="activity.length">
|
||||
<template v-for="group in groups" :key="`${group.label}:${group.taskID}`">
|
||||
<!-- 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 group row keeps ActivityRow's link contract: when its
|
||||
events resolve to a task, the row itself opens the task,
|
||||
with the same focusable role="link" behaviour. The
|
||||
disclosure button is a stop-propagated control inside the
|
||||
first cell, so it never fights the row-level link.
|
||||
-->
|
||||
<TableRow
|
||||
:class="group.taskID > 0 ? 'cursor-pointer' : ''"
|
||||
:role="group.taskID > 0 ? 'link' : undefined"
|
||||
:tabindex="group.taskID > 0 ? 0 : undefined"
|
||||
:title="group.taskID > 0 ? 'Open task details' : undefined"
|
||||
@click="group.taskID > 0 && openTask(group.taskID)"
|
||||
@keydown.enter.prevent="group.taskID > 0 && openTask(group.taskID)"
|
||||
@keydown.space.prevent="group.taskID > 0 && openTask(group.taskID)"
|
||||
>
|
||||
<TableCell class="font-medium">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded hover:opacity-80"
|
||||
:aria-expanded="isOpen(group)"
|
||||
:aria-label="`${isOpen(group) ? 'Hide' : 'Show'} ${group.count} ${group.label} events`"
|
||||
@click.stop="toggle(groupKey(group.label, group.taskID))"
|
||||
>
|
||||
<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" />
|
||||
{{ group.label }}
|
||||
<Badge variant="idle">×{{ group.count }}</Badge>
|
||||
</button>
|
||||
</TableCell>
|
||||
<TableCell class="font-mono">{{ group.taskID > 0 ? `#${group.taskID}` : "—" }}</TableCell>
|
||||
<TableCell class="w-[55%] max-w-0">
|
||||
<span class="block truncate" :title="groupDetail(group).truncated ? groupDetail(group).full : undefined">{{ groupDetail(group).text }}</span>
|
||||
</TableCell>
|
||||
<TableCell>{{ groupWhen(group) }}</TableCell>
|
||||
</TableRow>
|
||||
<template v-if="isOpen(group)">
|
||||
<ActivityRow v-for="(event, i) in group.events" :key="`${group.label}:${group.taskID}:${i}`" :event="event" @open="openTask" />
|
||||
</template>
|
||||
</template>
|
||||
</template>
|
||||
</template>
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</template>
|
||||
</template>
|
||||
@@ -0,0 +1,51 @@
|
||||
import type { ActivityEvent } from "./state";
|
||||
|
||||
/**
|
||||
* The live activity feed's grouping projection.
|
||||
*
|
||||
* The daemon emits high-frequency background telemetry (session-memory
|
||||
* cycles, runner calls) that arrives as dozens of same-shape rows an hour.
|
||||
* Printed raw, the table stops being scannable and real milestones drown.
|
||||
* The rule: a *run of consecutive* events sharing one label and one task
|
||||
* collapses into a single group row; anything else stays on its own line, so
|
||||
* a milestone is never merged with a different event that merely shares its
|
||||
* kind. The grouping is consecutive, not global, so interleaved kinds keep
|
||||
* their order and nothing is reordered under the operator.
|
||||
*
|
||||
* This is a pure view projection over the store's raw stream: the store keeps
|
||||
* every event, and this module decides only how the feed presents them.
|
||||
*/
|
||||
|
||||
/** One displayed row: either a single event (count 1) or a collapsed run. */
|
||||
export interface ActivityGroup {
|
||||
/** The resolved label the row shows, matching the Event column's fallback. */
|
||||
label: string;
|
||||
/** The task the group's events resolve to, or 0 for none. */
|
||||
taskID: number;
|
||||
/** How many events the group carries; 1 means an uncollapsed row. */
|
||||
count: number;
|
||||
/** The newest event of the run -- what the row shows while collapsed. */
|
||||
representative: ActivityEvent;
|
||||
/** Every event in the run, newest first. */
|
||||
events: ActivityEvent[];
|
||||
}
|
||||
|
||||
export function groupKey(label: string, taskID: number | undefined): string {
|
||||
return `${label}:${taskID ?? 0}`;
|
||||
}
|
||||
|
||||
export function groupActivity(events: ActivityEvent[]): ActivityGroup[] {
|
||||
const groups: ActivityGroup[] = [];
|
||||
for (const event of events) {
|
||||
const label = event.kind || event.type || "event";
|
||||
const taskID = Number(event.task_id) || 0;
|
||||
const last = groups[groups.length - 1];
|
||||
if (last && last.label === label && last.taskID === taskID) {
|
||||
last.count += 1;
|
||||
last.events.push(event);
|
||||
continue;
|
||||
}
|
||||
groups.push({ label, taskID, count: 1, representative: event, events: [event] });
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
Reference in new issue
Block a user