From 1c92edce6805cedaf7d4a79e48442e14fa9700de Mon Sep 17 00:00:00 2001 From: arndom Date: Sun, 6 Oct 2024 21:59:15 +0100 Subject: [PATCH 1/3] fix(core): update `useTable` hook - reset filters and sorters used in tables on URL query clear --- packages/core/src/hooks/useTable/index.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/core/src/hooks/useTable/index.ts b/packages/core/src/hooks/useTable/index.ts index 7398aabc13a6..1a522ae72317 100644 --- a/packages/core/src/hooks/useTable/index.ts +++ b/packages/core/src/hooks/useTable/index.ts @@ -439,6 +439,28 @@ export function useTable< return `${pathname ?? ""}?${stringifyParams ?? ""}`; }; + useEffect(() => { + if (!parsedParams?.params?.filters && !parsedParams?.params?.sorters) { + const resetFilters = setInitialFilters( + preferredPermanentFilters, + defaultFilter ?? [], + ); + const resetSorters = setInitialSorters( + preferredPermanentSorters, + defaultSorter ?? [], + ); + + setFilters(resetFilters); + setSorters(resetSorters); + } + }, [ + parsedParams, + preferredPermanentFilters, + defaultFilter, + preferredPermanentSorters, + defaultSorter, + ]); + useEffect(() => { if (search === "") { setCurrent(defaultCurrent); From 402aaed9b4b9bf82a3bcd5ef17dbe6930ba69fec Mon Sep 17 00:00:00 2001 From: arndom Date: Sun, 6 Oct 2024 22:13:06 +0100 Subject: [PATCH 2/3] chore(core): add changeset --- .changeset/spicy-flowers-allow.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/spicy-flowers-allow.md diff --git a/.changeset/spicy-flowers-allow.md b/.changeset/spicy-flowers-allow.md new file mode 100644 index 000000000000..d7f0a1b1a8ff --- /dev/null +++ b/.changeset/spicy-flowers-allow.md @@ -0,0 +1,7 @@ +--- +"@refinedev/core": major +--- + +Update `useTable` hook to handle case where a user navigates to current page by clicking side-nav link intending to reset the filters and sorters. + +[Resolves #6300](https://github.com/refinedev/refine/issues/6300) From d72941ee81711160834050024705156fb4873e27 Mon Sep 17 00:00:00 2001 From: Nabil Alamin Date: Mon, 7 Oct 2024 17:49:00 +0100 Subject: [PATCH 3/3] Update .changeset/spicy-flowers-allow.md Co-authored-by: Batuhan Wilhelm --- .changeset/spicy-flowers-allow.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/spicy-flowers-allow.md b/.changeset/spicy-flowers-allow.md index d7f0a1b1a8ff..a280a1ca8142 100644 --- a/.changeset/spicy-flowers-allow.md +++ b/.changeset/spicy-flowers-allow.md @@ -1,5 +1,5 @@ --- -"@refinedev/core": major +"@refinedev/core": patch --- Update `useTable` hook to handle case where a user navigates to current page by clicking side-nav link intending to reset the filters and sorters.