Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/memory-count.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
3 changes: 2 additions & 1 deletion web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ export default function App() {
count: getDisplayedMemoryCount(
explorer.isSearching,
explorer.totalItems,
explorer.statsTotal
explorer.statsTotal,
Boolean(explorer.selectedTag)
),
})}
</span>
Expand Down
5 changes: 3 additions & 2 deletions web/src/lib/memory-count.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Loading