fix(ui): move default muted filter from middleware to client-side hook (#10034)

This commit is contained in:
Alejandro Bailo
2026-02-11 20:58:58 +01:00
committed by GitHub
parent 3aefde14aa
commit 592c7bac81
3 changed files with 13 additions and 15 deletions

View File

@@ -19,7 +19,7 @@ All notable changes to the **Prowler UI** are documented in this file.
- Filter navigations not coordinating with Suspense boundaries due to missing startTransition in ProviderTypeSelector, AccountsSelector, and muted findings checkbox [(#10013)](https://github.com/prowler-cloud/prowler/pull/10013)
- Scans page pagination not updating table data because ScansTableWithPolling kept stale state from initial mount [(#10013)](https://github.com/prowler-cloud/prowler/pull/10013)
- Duplicate `filter[search]` parameter in findings and scans API calls [(#10013)](https://github.com/prowler-cloud/prowler/pull/10013)
- All filters on `/findings` silently reverting on first click in production [(#10025)](https://github.com/prowler-cloud/prowler/pull/10025)
- All filters on `/findings` silently reverting on first click in production [(#10034)](https://github.com/prowler-cloud/prowler/pull/10034)
---

View File

@@ -2,6 +2,9 @@
import { usePathname, useRouter, useSearchParams } from "next/navigation";
const FINDINGS_PATH = "/findings";
const DEFAULT_MUTED_FILTER = "false";
/**
* Custom hook to handle URL filters and automatically reset
* pagination when filters change.
@@ -15,7 +18,16 @@ export const useUrlFilters = () => {
const pathname = usePathname();
const isPending = false;
const ensureFindingsDefaultMuted = (params: URLSearchParams) => {
// Findings defaults to excluding muted findings unless user sets it explicitly.
if (pathname === FINDINGS_PATH && !params.has("filter[muted]")) {
params.set("filter[muted]", DEFAULT_MUTED_FILTER);
}
};
const navigate = (params: URLSearchParams) => {
ensureFindingsDefaultMuted(params);
const queryString = params.toString();
const targetUrl = queryString ? `${pathname}?${queryString}` : pathname;
router.push(targetUrl, { scroll: false });

View File

@@ -50,20 +50,6 @@ export default auth((req: NextRequest & { auth: any }) => {
}
}
// Redirect /findings to include default muted filter if not present
if (
pathname === "/findings" &&
!req.nextUrl.searchParams.has("filter[muted]")
) {
const findingsUrl = new URL("/findings", req.url);
// Preserve existing search params
req.nextUrl.searchParams.forEach((value, key) => {
findingsUrl.searchParams.set(key, value);
});
findingsUrl.searchParams.set("filter[muted]", "false");
return NextResponse.redirect(findingsUrl);
}
return NextResponse.next();
});