fix(web): drop stale category filters when the space changes

Category filter chips are stored in the URL (`?categories=`), so they survive a
space switch. If the newly selected space has no documents in a selected
category, the grid query keeps filtering by it and shows zero results — but the
category chip only renders for facets that exist in the current space, so there
is no visible control to clear and the user hits a dead end.

Prune any selected categories the current space's facets don't contain, mirroring
the existing agent-source reset a few lines above.
This commit is contained in:
abhay-codes07 2026-08-15 15:01:25 +05:30
parent 5ecbc26345
commit 854455c29d
No known key found for this signature in database

View file

@ -395,6 +395,23 @@ export function MemoriesGrid({
}
}, [agentSourceCounts, selectedAgentSource, setSelectedAgentSource])
// Category filters are URL state that survives a space switch. Drop any that
// the current space's facets no longer contain, otherwise the grid stays
// filtered down to zero results with no visible pill to clear (the chip only
// renders for facets that exist here). Mirrors the agent-source reset above.
useEffect(() => {
if (!facetsData || selectedCategories.length === 0) return
const available = new Set<string>(
facetsData.facets.map((facet) => facet.category),
)
const stillValid = selectedCategories.filter((category) =>
available.has(category),
)
if (stillValid.length !== selectedCategories.length) {
void setSelectedCategories(stillValid.length > 0 ? stillValid : null)
}
}, [facetsData, selectedCategories, setSelectedCategories])
const {
data,
error,