fix(webui): read a capture beside the list, not over it

The capture detail was the app's only sheet: it covered the list it was
opened from, had to be dismissed between rows, and held no address. It is
now a pane that sits with the list -- sticky and internally scrolling on the
wide layout, stacked under the list below 1100px, where selecting scrolls it
into view. The selection rides in the URL (?capture=N) with replace, so a
capture survives a reload and can be linked, and a page opened without a
selection shows the newest event rather than an empty box.
This commit is contained in:
sam committed 2026-09-21 01:17:04 +10:00
1 parent 7f1da81d52
commit ddb9c88f4f
7 files changed
+130 -83

No files matched your search

+55
View File
@@ -0,0 +1,55 @@
<script setup lang="ts">
import { computed, ref, watch } from "vue";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { ago } from "@/lib/format";
import CapturePayload from "./CapturePayload.vue";
import { selected } from "./state";
/**
* The selected capture's payload and headers, beside the list.
*
* A pane rather than a sheet: a sheet covers the list it was opened from and
* has to be dismissed between rows, while an inspector is read by moving down
* the list with the payload in view. On the wide layout it sticks beside the
* list and scrolls internally, so a long payload cannot take the page with it;
* stacked under the list, a selection brings it into view, because a tap that
* changes something off-screen reads as a tap that did nothing.
*
* Nothing here goes stale: a stored capture is never rewritten.
*/
const pane = ref<HTMLElement | null>(null);
const meta = computed(() => {
const capture = selected.value;
if (!capture) return "";
return [ago(capture.received_at), capture.content_type || "no content type", capture.remote_addr]
.filter(Boolean)
.join(" · ");
});
// Below the split's breakpoint the pane sits after the list, so a row click has
// to bring it into view. Same breakpoint as the grid in CapturesPage: one
// layout decision, expressed twice because CSS cannot hand it to script.
const STACKED = "(max-width: 1099px)";
watch(selected, () => {
if (!window.matchMedia(STACKED).matches) return;
pane.value?.scrollIntoView({ block: "start", behavior: "smooth" });
});
</script>
<template>
<div v-if="selected" ref="pane" class="min-w-0 min-[1100px]:sticky min-[1100px]:top-4">
<Card class="min-[1100px]:max-h-[calc(100vh-3rem)] min-[1100px]:overflow-y-auto">
<CardHeader>
<CardTitle class="font-mono">{{ selected.source || "Unknown source" }}</CardTitle>
<CardDescription>{{ meta }}</CardDescription>
</CardHeader>
<CardContent class="flex flex-col gap-5">
<CapturePayload label="Payload" :raw="selected.body" />
<CapturePayload label="Headers" :raw="selected.headers" />
</CardContent>
</Card>
</div>
</template>
-52
View File
@@ -1,52 +0,0 @@
<script setup lang="ts">
import { computed, ref, watch } from "vue";
import { ScrollArea } from "@/components/ui/scroll-area";
import { Separator } from "@/components/ui/separator";
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from "@/components/ui/sheet";
import { ago } from "@/lib/format";
import CapturePayload from "./CapturePayload.vue";
import { selected, type Capture } from "./state";
/**
* One capture's payload and headers, opened from its row. A side panel rather
* than a taller row: a payload runs to thousands of characters, and the list
* has to stay a list while it is read.
*/
const open = computed({
get: () => selected.value !== null,
set: (value: boolean) => {
if (!value) selected.value = null;
},
});
// What the panel renders. The list drops the selection as soon as this sheet
// reports closed, and the panel stays mounted through the close animation, so
// reading the shared ref would blank it halfway out. Nothing goes stale here:
// a stored capture is never rewritten.
const shown = ref<Capture | null>(null);
watch(selected, (next) => {
if (next) shown.value = next;
});
</script>
<template>
<Sheet v-model:open="open">
<SheetContent class="w-full gap-0 sm:max-w-2xl">
<SheetHeader>
<SheetTitle>{{ shown?.source || "Unknown source" }}</SheetTitle>
<SheetDescription>
{{ ago(shown?.received_at) }} · {{ shown?.content_type || "no content type" }}
</SheetDescription>
</SheetHeader>
<Separator />
<ScrollArea class="min-h-0 flex-1">
<div class="flex flex-col gap-5 p-4">
<CapturePayload label="Payload" :raw="shown?.body" />
<CapturePayload label="Headers" :raw="shown?.headers" />
</div>
</ScrollArea>
</SheetContent>
</Sheet>
</template>
+5 -5
View File
@@ -9,9 +9,9 @@ import { selected, type Capture } from "./state";
/**
* One captured event. The row is the control, not a button sitting in one
* cell: opening the payload is the row's whole job, and a keyboard user has to
* reach what a mouse user clicks -- which is why it is focusable and both
* Enter and Space open it.
* cell: selecting is the row's whole job, and a keyboard user has to reach what
* a mouse user clicks -- which is why it is focusable and both Enter and Space
* select it.
*/
const props = defineProps<{ capture: Capture }>();
@@ -19,7 +19,7 @@ const isSelected = computed(() => selected.value?.id === props.capture.id);
// The name is set here because role="button" makes the cells presentational:
// what a screen reader reads is this, not five unrelated columns.
const label = computed(() => `View the payload received from ${props.capture.source || "an unknown source"}`);
const label = computed(() => `Show the payload received from ${props.capture.source || "an unknown source"}`);
function open(): void {
selected.value = props.capture;
@@ -31,7 +31,7 @@ function open(): void {
:data-state="isSelected ? 'selected' : undefined"
role="button"
tabindex="0"
aria-haspopup="dialog"
:aria-current="isSelected ? 'true' : undefined"
:aria-label="label"
class="cursor-pointer focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring"
@click="open"
+37 -9
View File
@@ -1,21 +1,49 @@
<script setup lang="ts">
import CaptureDetailSheet from "./CaptureDetailSheet.vue";
import { onMounted, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import CaptureDetail from "./CaptureDetail.vue";
import CapturesCard from "./CapturesCard.vue";
import CapturesHeader from "./CapturesHeader.vue";
import { useCaptures } from "./state";
import { load, selectById, selectNewest, selected, useCaptures } from "./state";
/**
* Event inspector (t2db.2): the operator-facing half of capture. Recent
* inbound events, newest first, with the full redacted payload explorable from
* each row -- see docs/prds/event-capture-storage.md for what the backend
* guarantees (retention, redaction, disk bounds). Composes the page; it holds
* no state of its own.
* Event inspector: recent inbound events, newest first, with the selected
* event's payload read beside the list rather than over it -- see
* docs/prds/event-capture-storage.md for what the backend guarantees
* (retention, redaction, disk bounds).
*
* The selection lives in the address bar (`?capture=7`): a row an operator is
* reading survives a reload and can be linked to. Selecting is a `replace`, not
* a push, so walking the list adds no history entries to back out through.
* Narrow screens stack the pane under the list.
*/
useCaptures();
const route = useRoute();
const router = useRouter();
onMounted(async () => {
await load();
// The URL names a selection before the window is read, so the restore waits
// for the list; an id it no longer holds falls back to the newest capture,
// which is what a page opened with nothing named starts on too.
const named = Number(route.query.capture);
if (!Number.isInteger(named) || !selectById(named)) selectNewest();
});
watch(selected, (capture) => {
const query = { ...route.query };
if (capture) query.capture = String(capture.id);
else delete query.capture;
void router.replace({ query });
});
</script>
<template>
<CapturesHeader />
<CapturesCard />
<CaptureDetailSheet />
<div class="grid min-w-0 items-start gap-4 min-[1100px]:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]">
<CapturesCard class="min-w-0" />
<CaptureDetail />
</div>
</template>
+24 -8
View File
@@ -1,4 +1,4 @@
import { onMounted, ref } from "vue";
import { ref } from "vue";
import { api } from "@/lib/api";
import { useLiveResource } from "@/stores/live-updates";
@@ -6,7 +6,7 @@ import { useLiveResource } from "@/stores/live-updates";
/**
* The event inspector's shared state.
*
* The list, the stream's state beside it and the sheet that shows one
* The list, the stream's state beside it and the detail pane that shows one
* capture's payload all read it, so it lives in a module rather than being
* threaded down through a chain of props.
*/
@@ -44,9 +44,9 @@ export const error = ref<string | null>(null);
export const loading = ref(true);
/**
* The open row's capture, or null. Held by value rather than by id: the list
* is re-read on every capture event, so resolving an id again would close the
* sheet under an operator reading a capture that has just aged out of the
* The selected capture, or null. Held by value rather than by id: the list is
* re-read on every capture event, so resolving an id again would blank the
* pane under an operator reading a capture that has just aged out of the
* window.
*/
export const selected = ref<Capture | null>(null);
@@ -72,9 +72,25 @@ export async function load(): Promise<void> {
}
}
/** Owns the initial read and the live stream that invalidates it, for the
* page's lifetime. */
/** selectById restores the selection the URL names, if the window still holds
* it. A capture that has aged out cannot be resolved: the list is the only
* read of a capture's body, so an id it no longer carries has nothing to show.
* Reports whether it found one. */
export function selectById(id: number): boolean {
const found = captures.value.find((capture) => capture.id === id);
if (found) selected.value = found;
return Boolean(found);
}
/** selectNewest fills a page opened without a selection, so the pane is useful
* on arrival rather than an empty box beside the list. */
export function selectNewest(): void {
if (captures.value.length) selected.value = captures.value[0];
}
/** Owns the live stream that invalidates the list, for the page's lifetime.
* The initial read belongs to the page, which has to await it before it can
* restore a selection from the address bar. */
export function useCaptures(): void {
useLiveResource("captures", () => void load());
onMounted(load);
}