fix(ui): fix findings filter silent reverts by replacing useRelatedFilters effect with pure derivation (#10021)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Alejandro Bailo
2026-02-11 17:57:38 +01:00
committed by GitHub
parent fce1e4f3d2
commit 86946f3a84
6 changed files with 122 additions and 254 deletions

View File

@@ -1,10 +1,9 @@
"use client";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
import { useTransition } from "react";
import { useSearchParams } from "next/navigation";
import { Checkbox } from "@/components/shadcn";
import { useFilterTransitionOptional } from "@/contexts";
import { useUrlFilters } from "@/hooks/use-url-filters";
// Constants for muted filter URL values
const MUTED_FILTER_VALUES = {
@@ -13,16 +12,10 @@ const MUTED_FILTER_VALUES = {
} as const;
export const CustomCheckboxMutedFindings = () => {
const router = useRouter();
const pathname = usePathname();
const searchParams = useSearchParams();
// Signal shared pending state for DataTable loading indicator
const filterTransition = useFilterTransitionOptional();
const [, startTransition] = useTransition();
const { navigateWithParams } = useUrlFilters();
// Get the current muted filter value from URL
// Middleware ensures filter[muted] is always present when navigating to /findings
const mutedFilterValue = searchParams.get("filter[muted]");
// URL states:
@@ -32,24 +25,15 @@ export const CustomCheckboxMutedFindings = () => {
const handleMutedChange = (checked: boolean | "indeterminate") => {
const isChecked = checked === true;
const params = new URLSearchParams(searchParams.toString());
if (isChecked) {
// Include muted: set special value (API will ignore invalid value and show all)
params.set("filter[muted]", MUTED_FILTER_VALUES.INCLUDE);
} else {
// Exclude muted: apply filter to show only non-muted
params.set("filter[muted]", MUTED_FILTER_VALUES.EXCLUDE);
}
// Reset to page 1 when changing filter
if (params.has("page")) {
params.set("page", "1");
}
filterTransition?.signalFilterChange();
startTransition(() => {
router.push(`${pathname}?${params.toString()}`, { scroll: false });
navigateWithParams((params) => {
if (isChecked) {
// Include muted: set special value (API will ignore invalid value and show all)
params.set("filter[muted]", MUTED_FILTER_VALUES.INCLUDE);
} else {
// Exclude muted: apply filter to show only non-muted
params.set("filter[muted]", MUTED_FILTER_VALUES.EXCLUDE);
}
});
};