File tree Expand file tree Collapse file tree 2 files changed +82
-0
lines changed
static/app/actionCreators
tests/js/spec/actionCreators Expand file tree Collapse file tree 2 files changed +82
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import {
22
22
} from 'sentry/components/organizations/pageFilters/utils' ;
23
23
import { DATE_TIME_KEYS , URL_PARAM } from 'sentry/constants/pageFilters' ;
24
24
import OrganizationStore from 'sentry/stores/organizationStore' ;
25
+ import PageFiltersStore from 'sentry/stores/pageFiltersStore' ;
25
26
import {
26
27
DateString ,
27
28
Environment ,
@@ -534,3 +535,29 @@ function getNewQueryParams(
534
535
535
536
return Object . fromEntries ( paramEntries ) as PageFilterQuery ;
536
537
}
538
+
539
+ export function revertToPinnedFilters ( orgSlug : string , router : InjectedRouter ) {
540
+ const { selection, desyncedFilters} = PageFiltersStore . getState ( ) ;
541
+ const storedFilterState = getPageFilterStorage ( orgSlug ) ?. state ;
542
+
543
+ if ( ! storedFilterState ) {
544
+ return ;
545
+ }
546
+
547
+ const newParams = {
548
+ project : desyncedFilters . has ( 'projects' )
549
+ ? storedFilterState . project
550
+ : selection . projects ,
551
+ environment : desyncedFilters . has ( 'environments' )
552
+ ? storedFilterState . environment
553
+ : selection . environments ,
554
+ ...( desyncedFilters . has ( 'datetime' )
555
+ ? pick ( storedFilterState , DATE_TIME_KEYS )
556
+ : selection . datetime ) ,
557
+ } ;
558
+
559
+ updateParams ( newParams , router , {
560
+ keepCursor : true ,
561
+ } ) ;
562
+ updateDesyncedUrlState ( router ) ;
563
+ }
Original file line number Diff line number Diff line change 1
1
import {
2
2
initializeUrlState ,
3
+ revertToPinnedFilters ,
3
4
updateDateTime ,
4
5
updateEnvironments ,
5
6
updateProjects ,
@@ -483,4 +484,58 @@ describe('PageFilters ActionCreators', function () {
483
484
} ) ;
484
485
} ) ;
485
486
} ) ;
487
+
488
+ describe ( 'revertToPinnedFilters()' , function ( ) {
489
+ it ( 'reverts all filters that are desynced from localStorage' , async function ( ) {
490
+ const router = TestStubs . router ( {
491
+ location : {
492
+ pathname : '/test/' ,
493
+ query : { } ,
494
+ } ,
495
+ } ) ;
496
+ // Mock storage to have a saved value
497
+ const pageFilterStorageMock = jest
498
+ . spyOn ( PageFilterPersistence , 'getPageFilterStorage' )
499
+ . mockReturnValueOnce ( {
500
+ state : {
501
+ project : [ '1' ] ,
502
+ environment : [ ] ,
503
+ start : null ,
504
+ end : null ,
505
+ period : '14d' ,
506
+ utc : null ,
507
+ } ,
508
+ pinnedFilters : new Set ( [ 'projects' , 'environments' , 'datetime' ] ) ,
509
+ } ) ;
510
+
511
+ PageFiltersActions . initializeUrlState ( {
512
+ projects : [ '2' ] ,
513
+ environments : [ 'prod' ] ,
514
+ datetime : {
515
+ start : null ,
516
+ end : null ,
517
+ period : '1d' ,
518
+ utc : null ,
519
+ } ,
520
+ } ) ;
521
+ PageFiltersActions . updateDesyncedFilters (
522
+ new Set ( [ 'projects' , 'environments' , 'datetime' ] )
523
+ ) ;
524
+ // Tick for PageFiltersActions
525
+ await tick ( ) ;
526
+
527
+ revertToPinnedFilters ( 'org-slug' , router ) ;
528
+
529
+ expect ( router . push ) . toHaveBeenCalledWith ( {
530
+ pathname : '/test/' ,
531
+ query : {
532
+ environment : [ ] ,
533
+ project : [ '1' ] ,
534
+ statsPeriod : '14d' ,
535
+ } ,
536
+ } ) ;
537
+
538
+ pageFilterStorageMock . mockRestore ( ) ;
539
+ } ) ;
540
+ } ) ;
486
541
} ) ;
You can’t perform that action at this time.
0 commit comments