From 99288ff8add3d149120e37911e9d927627db4cd0 Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Mon, 24 Aug 2026 21:25:22 +0100 Subject: [PATCH] fix: keep applied search filters in the order they were added --- .../components/search-spotlight-filters.tsx | 159 ++++++++++-------- 1 file changed, 92 insertions(+), 67 deletions(-) diff --git a/apps/client/src/features/search/components/search-spotlight-filters.tsx b/apps/client/src/features/search/components/search-spotlight-filters.tsx index c171e23e2..6814248e9 100644 --- a/apps/client/src/features/search/components/search-spotlight-filters.tsx +++ b/apps/client/src/features/search/components/search-spotlight-filters.tsx @@ -54,6 +54,7 @@ export function SearchSpotlightFilters({ ); const [selectedLabelIds, setSelectedLabelIds] = useState([]); const [openedFilter, setOpenedFilter] = useState(null); + const [visibleFilters, setVisibleFilters] = useState([]); const [workspace] = useAtom(workspaceAtom); const { data: spacesData } = useGetSpacesQuery({ limit: 100 }); @@ -106,23 +107,33 @@ export function SearchSpotlightFilters({ } }; - const showCreatorFilter = !!selectedCreatorId || openedFilter === "creator"; - const showLabelFilter = - contentType !== "attachment" && - (selectedLabelIds.length > 0 || openedFilter === "labels"); + const onDemandFilters = [ + { key: "creator", label: t("Created by"), icon: IconUser, available: true }, + { + key: "labels", + label: t("Labels"), + icon: IconTag, + available: contentType !== "attachment", + }, + ]; - const addableFilters: { key: string; label: string; icon: typeof IconUser }[] = - []; - if (!showCreatorFilter) { - addableFilters.push({ - key: "creator", - label: t("Created by"), - icon: IconUser, - }); - } - if (contentType !== "attachment" && !showLabelFilter) { - addableFilters.push({ key: "labels", label: t("Labels"), icon: IconTag }); - } + const isFilterVisible = (key: string) => { + if (openedFilter === key) return true; + if (key === "creator") return !!selectedCreatorId; + if (key === "labels") + return contentType !== "attachment" && selectedLabelIds.length > 0; + return false; + }; + + const orderedVisibleFilters = visibleFilters.filter(isFilterVisible); + const addableFilters = onDemandFilters.filter( + (filter) => filter.available && !isFilterVisible(filter.key), + ); + + const revealFilter = (key: string) => { + setVisibleFilters((prev) => [...prev.filter((k) => k !== key), key]); + setOpenedFilter(key); + }; return (
@@ -239,57 +250,71 @@ export function SearchSpotlightFilters({ - {showCreatorFilter && ( - setOpenedFilter(opened ? "creator" : null)} - > - - - )} + {orderedVisibleFilters.map((filterKey) => { + if (filterKey === "creator") { + return ( + + setOpenedFilter(opened ? "creator" : null) + } + > + + + ); + } - {showLabelFilter && ( - setOpenedFilter(opened ? "labels" : null)} - > - - - )} + if (filterKey === "labels") { + return ( + + setOpenedFilter(opened ? "labels" : null) + } + > + + + ); + } + + return null; + })} {addableFilters.length > 0 && ( } - onClick={() => setOpenedFilter(filter.key)} + onClick={() => revealFilter(filter.key)} > {filter.label}