mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-03-22 03:08:23 +00:00
fix(ui): remove useTransition and shared context from useUrlFilters (#10025)
This commit is contained in:
@@ -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 [(#10021)](https://github.com/prowler-cloud/prowler/pull/10021)
|
||||
- All filters on `/findings` silently reverting on first click in production [(#10025)](https://github.com/prowler-cloud/prowler/pull/10025)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -1,30 +1,25 @@
|
||||
"use client";
|
||||
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
||||
import { useTransition } from "react";
|
||||
|
||||
import { useFilterTransitionOptional } from "@/contexts";
|
||||
|
||||
/**
|
||||
* Custom hook to handle URL filters and automatically reset
|
||||
* pagination when filters change.
|
||||
*
|
||||
* Uses useTransition to prevent full page reloads when filters change,
|
||||
* keeping the current UI visible while the new data loads.
|
||||
*
|
||||
* When used within a FilterTransitionProvider, the transition state is shared
|
||||
* across all components using this hook, enabling coordinated loading indicators.
|
||||
* Uses client-side router navigation to update query params without
|
||||
* full page reloads when filters change.
|
||||
*/
|
||||
export const useUrlFilters = () => {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const pathname = usePathname();
|
||||
const isPending = false;
|
||||
|
||||
// Signal shared pending state for DataTable loading indicator
|
||||
const filterTransition = useFilterTransitionOptional();
|
||||
const [localIsPending, startTransition] = useTransition();
|
||||
|
||||
const isPending = filterTransition?.isPending ?? localIsPending;
|
||||
const navigate = (params: URLSearchParams) => {
|
||||
const queryString = params.toString();
|
||||
const targetUrl = queryString ? `${pathname}?${queryString}` : pathname;
|
||||
router.push(targetUrl, { scroll: false });
|
||||
};
|
||||
|
||||
const updateFilter = (key: string, value: string | string[] | null) => {
|
||||
const params = new URLSearchParams(searchParams.toString());
|
||||
@@ -54,10 +49,7 @@ export const useUrlFilters = () => {
|
||||
params.set(filterKey, nextValue);
|
||||
}
|
||||
|
||||
filterTransition?.signalFilterChange();
|
||||
startTransition(() => {
|
||||
router.push(`${pathname}?${params.toString()}`, { scroll: false });
|
||||
});
|
||||
navigate(params);
|
||||
};
|
||||
|
||||
const clearFilter = (key: string) => {
|
||||
@@ -71,10 +63,7 @@ export const useUrlFilters = () => {
|
||||
params.set("page", "1");
|
||||
}
|
||||
|
||||
filterTransition?.signalFilterChange();
|
||||
startTransition(() => {
|
||||
router.push(`${pathname}?${params.toString()}`, { scroll: false });
|
||||
});
|
||||
navigate(params);
|
||||
};
|
||||
|
||||
const clearAllFilters = () => {
|
||||
@@ -87,10 +76,7 @@ export const useUrlFilters = () => {
|
||||
|
||||
params.delete("page");
|
||||
|
||||
filterTransition?.signalFilterChange();
|
||||
startTransition(() => {
|
||||
router.push(`${pathname}?${params.toString()}`, { scroll: false });
|
||||
});
|
||||
navigate(params);
|
||||
};
|
||||
|
||||
const hasFilters = () => {
|
||||
@@ -115,10 +101,7 @@ export const useUrlFilters = () => {
|
||||
params.set("page", "1");
|
||||
}
|
||||
|
||||
filterTransition?.signalFilterChange();
|
||||
startTransition(() => {
|
||||
router.push(`${pathname}?${params.toString()}`, { scroll: false });
|
||||
});
|
||||
navigate(params);
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user