fix(web): reset stream filters and exclude warning rows from counts

Reset the stream panel's filter and request state when the exchange changes.
Keep recording-limit warnings visible while reporting only actual messages
in the header, including first-page and warning-only counts.

Add message_total to the stream page without changing raw pagination totals
or existing Go paging signatures. Cover the count and pagination boundaries
in the stream and HTTP route tests.
This commit is contained in:
APZN
2026-11-23 10:26:56 +09:00
parent 51fe31a653
commit 7e555e86d7
10 changed files with 225 additions and 50 deletions
@@ -107,10 +107,19 @@ function StreamMessageRow({ message }: { message: TrafficStreamMessage }) {
// StreamMessagesPanel lists the messages of one WebSocket or SSE exchange, a
// page at a time. It does not poll: Refresh reloads from the start.
export function StreamMessagesPanel({ exchangeId, kind }: { exchangeId: string; kind: "websocket" | "sse" }) {
type StreamMessagesProps = { exchangeId: string; kind: "websocket" | "sse" };
export function StreamMessagesPanel(props: StreamMessagesProps) {
// A different exchange starts with All directions and its own request state.
return <StreamMessages key={props.exchangeId} {...props} />;
}
function StreamMessages({ exchangeId, kind }: StreamMessagesProps) {
const [direction, setDirection] = React.useState<TrafficStreamDirection>("");
const [{ items, total, loading, loadingMore, error }, setPage] = React.useState(emptyTrafficStreamState);
const [{ items, total, messageTotal, loading, loadingMore, error }, setPage] =
React.useState(emptyTrafficStreamState);
const pager = React.useMemo(() => createTrafficStreamPager(api.trafficStream, setPage), []);
const messageCount = items.filter((message) => message.type !== "meta").length;
React.useEffect(() => {
pager.select(exchangeId, direction);
@@ -123,8 +132,8 @@ export function StreamMessagesPanel({ exchangeId, kind }: { exchangeId: string;
<span>
{t("{kind} · {count} of {total} messages", {
kind: kind === "websocket" ? "WebSocket" : "Server-Sent Events",
count: items.length,
total,
count: messageCount,
total: messageTotal,
})}
</span>
<Select
@@ -168,20 +177,20 @@ export function StreamMessagesPanel({ exchangeId, kind }: { exchangeId: string;
if (error) {
return <div className="p-5 text-destructive text-xs">{t("Failed to load messages: {error}", { error })}</div>;
}
if (items.length === 0) {
return (
<div className="p-5 text-muted-foreground text-xs">
{direction ? t("No messages recorded in this direction.") : t("No messages recorded for this stream.")}
</div>
);
}
return (
<>
<div className="border-t">
{items.map((m) => (
<StreamMessageRow key={`${exchangeId}:${m.seq}`} message={m} />
))}
</div>
{messageTotal === 0 && (
<div className="p-5 text-muted-foreground text-xs">
{direction ? t("No messages recorded in this direction.") : t("No messages recorded for this stream.")}
</div>
)}
{items.length > 0 && (
<div className="border-t">
{items.map((m) => (
<StreamMessageRow key={`${exchangeId}:${m.seq}`} message={m} />
))}
</div>
)}
{items.length < total && (
<div className="flex justify-center p-4">
<Button variant="outline" size="sm" disabled={loadingMore} onClick={pager.loadMore}>
+5 -1
View File
@@ -2256,7 +2256,11 @@ function route(m: string, path: string, seg: string[], q: URLSearchParams, b: Re
const offset = Math.max(0, Number(q.get("offset")) || 0);
const requestedLimit = Number(q.get("limit"));
const limit = requestedLimit > 0 ? Math.min(200, requestedLimit) : 50;
return { items: items.slice(offset, offset + limit), total: items.length };
return {
items: items.slice(offset, offset + limit),
total: items.length,
message_total: items.filter((message) => message.direction !== "meta").length,
};
}
if (path === "/settings" && m === "GET") return D.settings;
if (path === "/settings" && m === "PUT") return { ...D.settings, ...b };
+4 -2
View File
@@ -3,13 +3,14 @@ import type { TrafficStreamDirection, TrafficStreamMessage, TrafficStreamPage }
export interface TrafficStreamState {
items: TrafficStreamMessage[];
total: number;
messageTotal: number;
loading: boolean;
loadingMore: boolean;
error: string | null;
}
export function emptyTrafficStreamState(): TrafficStreamState {
return { items: [], total: 0, loading: true, loadingMore: false, error: null };
return { items: [], total: 0, messageTotal: 0, loading: true, loadingMore: false, error: null };
}
type FetchPage = (
@@ -35,7 +36,7 @@ export function createTrafficStreamPager(fetchPage: FetchPage, onChange: (state:
async function load(offset: number) {
const gen = ++generation;
update({
...(offset === 0 ? { items: [], total: 0 } : {}),
...(offset === 0 ? { items: [], total: 0, messageTotal: 0 } : {}),
loading: offset === 0,
loadingMore: offset > 0,
error: null,
@@ -46,6 +47,7 @@ export function createTrafficStreamPager(fetchPage: FetchPage, onChange: (state:
update({
items: offset === 0 ? (page.items ?? []) : [...state.items, ...(page.items ?? [])],
total: page.total ?? 0,
messageTotal: page.message_total,
loading: false,
loadingMore: false,
});
+2
View File
@@ -982,7 +982,9 @@ export type TrafficStreamDirection = "" | "c2s" | "s2c";
export interface TrafficStreamPage {
items: TrafficStreamMessage[];
// Pagination includes recording-limit rows; the message count does not.
total: number;
message_total: number;
}
export interface TrafficReplayHeader {