Files
claude-mem/src/ui/viewer/utils/data.ts
T
GigiTiti-Kai b88566dcdd fix(ui): include SSE live data when project filter is active (#1315)
When a project filter was selected in the Web UI, all SSE live data
(observations, summaries, prompts) was completely discarded. Only
paginated API data was shown, meaning new real-time events were
invisible until the user refreshed the page.

Fix: filter SSE data by project before merging with paginated data,
instead of discarding it entirely.

Fixes #1313

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 20:01:48 -07:00

26 lines
787 B
TypeScript

/**
* Data manipulation utility functions
* Used for merging and deduplicating real-time and paginated data
*/
/**
* Merge real-time SSE items with paginated items, removing duplicates by ID
* Callers should pre-filter liveItems by project when a filter is active.
*
* @param liveItems - Items from SSE stream (pre-filtered if needed)
* @param paginatedItems - Items from pagination API
* @returns Merged and deduplicated array
*/
export function mergeAndDeduplicateByProject<T extends { id: number; project?: string }>(
liveItems: T[],
paginatedItems: T[]
): T[] {
// Deduplicate by ID
const seen = new Set<number>();
return [...liveItems, ...paginatedItems].filter(item => {
if (seen.has(item.id)) return false;
seen.add(item.id);
return true;
});
}