From 9080be85a2793a08db39eb7c27bafdea7d6a43b8 Mon Sep 17 00:00:00 2001 From: Aman Awasthi Date: Fri, 25 Sep 2026 07:39:41 +0000 Subject: [PATCH] fix(web): show tag-filtered count in the header total When a tag filter is active, the Web UI header still showed the global /api/stats total even though the list below was filtered. Treat an active tag filter like search in getDisplayedMemoryCount so the header matches the visible memories (#305). --- tests/memory-count.test.ts | 13 +++++++++++++ web/src/App.tsx | 3 ++- web/src/lib/memory-count.ts | 5 +++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/tests/memory-count.test.ts b/tests/memory-count.test.ts index 67e8a953..622dcfbf 100644 --- a/tests/memory-count.test.ts +++ b/tests/memory-count.test.ts @@ -10,4 +10,17 @@ describe("getDisplayedMemoryCount", () => { test("restores the store total when search is cleared", () => { expect(getDisplayedMemoryCount(false, 3, 120)).toBe(120); }); + + test("shows the filtered total when a tag filter is active", () => { + expect(getDisplayedMemoryCount(false, 3, 120, true)).toBe(3); + expect(getDisplayedMemoryCount(false, 0, 120, true)).toBe(0); + }); + + test("prefers search total when both search and tag filter are active", () => { + expect(getDisplayedMemoryCount(true, 2, 120, true)).toBe(2); + }); + + test("keeps the store total when no search and no tag filter", () => { + expect(getDisplayedMemoryCount(false, 3, 120, false)).toBe(120); + }); }); diff --git a/web/src/App.tsx b/web/src/App.tsx index 0cf37a3b..908e4189 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -148,7 +148,8 @@ export default function App() { count: getDisplayedMemoryCount( explorer.isSearching, explorer.totalItems, - explorer.statsTotal + explorer.statsTotal, + Boolean(explorer.selectedTag) ), })} diff --git a/web/src/lib/memory-count.ts b/web/src/lib/memory-count.ts index 0cd15f2a..b3dad2d3 100644 --- a/web/src/lib/memory-count.ts +++ b/web/src/lib/memory-count.ts @@ -1,7 +1,8 @@ export function getDisplayedMemoryCount( isSearching: boolean, searchTotal: number, - storeTotal: number + storeTotal: number, + tagFilterActive = false ): number { - return isSearching ? searchTotal : storeTotal; + return isSearching || tagFilterActive ? searchTotal : storeTotal; }