From a30c6520d4fbbb732f107e838d354bbf5c0a665e Mon Sep 17 00:00:00 2001 From: Pablo Lara Date: Fri, 6 Sep 2024 11:25:09 +0200 Subject: [PATCH] feat: clear all button only appears if there is changes on search params --- app/(prowler)/page.tsx | 2 +- components/filters/FilterControls.tsx | 31 ++++++++++++++++++--------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/app/(prowler)/page.tsx b/app/(prowler)/page.tsx index b352170bd1..1fdd78d351 100644 --- a/app/(prowler)/page.tsx +++ b/app/(prowler)/page.tsx @@ -11,7 +11,7 @@ export default function Home() { <>
- +
= ({ }) => { const router = useRouter(); const searchParams = useSearchParams(); + const [showClearButton, setShowClearButton] = useState(false); + + useEffect(() => { + const hasFilters = Array.from(searchParams.keys()).some( + (key) => key.startsWith("filter[") || key === "sort", + ); + setShowClearButton(hasFilters); + }, [searchParams]); const clearAllFilters = useCallback(() => { const params = new URLSearchParams(searchParams.toString()); @@ -49,15 +57,18 @@ export const FilterControls: React.FC = ({ {regions && } {accounts && } {mutedFindings && } - + + {showClearButton && ( + + )}
); };