@@ -11,6 +11,7 @@ import warnOnce from "warn-once";
11
11
12
12
import { pickNotDeprecated } from "@definitions/helpers" ;
13
13
import {
14
+ mergeFilters ,
14
15
parseTableParams ,
15
16
setInitialFilters ,
16
17
setInitialSorters ,
@@ -439,27 +440,32 @@ export function useTable<
439
440
return `${ pathname ?? "" } ?${ stringifyParams ?? "" } ` ;
440
441
} ;
441
442
443
+ // watch URL filters to update internal filters
442
444
useEffect ( ( ) => {
443
- if ( ! parsedParams ?. params ?. filters && ! parsedParams ?. params ?. sorters ) {
444
- const resetFilters = setInitialFilters (
445
+ if ( syncWithLocation ) {
446
+ const current_filters = filters ;
447
+ const current_URL_filters = parsedParams ?. params ?. filters ;
448
+ const initial_filters = setInitialFilters (
445
449
preferredPermanentFilters ,
446
450
defaultFilter ?? [ ] ,
447
451
) ;
448
- const resetSorters = setInitialSorters (
449
- preferredPermanentSorters ,
450
- defaultSorter ?? [ ] ,
451
- ) ;
452
452
453
- setFilters ( resetFilters ) ;
454
- setSorters ( resetSorters ) ;
453
+ let new_filters : CrudFilter [ ] = [ ] ;
454
+ const urlsAreEqual = isEqual ( current_URL_filters , current_filters ) ;
455
+
456
+ if ( ! urlsAreEqual ) {
457
+ // fallback to initial filters
458
+ if ( ! current_URL_filters || current_URL_filters . length === 0 ) {
459
+ new_filters = initial_filters ;
460
+ } else {
461
+ // since they aren't equal, merge the two
462
+ new_filters = mergeFilters ( current_URL_filters , current_filters ) ;
463
+ }
464
+
465
+ setFilters ( new_filters ) ;
466
+ }
455
467
}
456
- } , [
457
- parsedParams ,
458
- preferredPermanentFilters ,
459
- defaultFilter ,
460
- preferredPermanentSorters ,
461
- defaultSorter ,
462
- ] ) ;
468
+ } , [ parsedParams , filters , preferredPermanentFilters ] ) ;
463
469
464
470
useEffect ( ( ) => {
465
471
if ( search === "" ) {
0 commit comments