@@ -30,12 +30,16 @@ import type {
30
30
GetOverviewBranch ,
31
31
GetOverviewBranches ,
32
32
GetOverviewResponse ,
33
+ OverviewFilters ,
34
+ OverviewRecentThreshold ,
35
+ OverviewStaleThreshold ,
33
36
State ,
34
37
} from './protocol' ;
35
38
import {
36
39
CollapseSectionCommand ,
37
40
DidChangeIntegrationsConnections ,
38
41
DidChangeOrgSettings ,
42
+ DidChangeOverviewFilter ,
39
43
DidChangePreviewEnabled ,
40
44
DidChangeRepositories ,
41
45
DidChangeRepositoryWip ,
@@ -45,6 +49,8 @@ import {
45
49
DismissWalkthroughSection ,
46
50
GetLaunchpadSummary ,
47
51
GetOverview ,
52
+ GetOverviewFilterState ,
53
+ SetOverviewFilter ,
48
54
} from './protocol' ;
49
55
import type { HomeWebviewShowingArgs } from './registration' ;
50
56
@@ -87,6 +93,16 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
87
93
} ;
88
94
}
89
95
96
+ private _overviewBranchFilter : OverviewFilters = {
97
+ recent : {
98
+ threshold : 'OneWeek' ,
99
+ } ,
100
+ stale : {
101
+ threshold : 'OneYear' ,
102
+ show : false ,
103
+ } ,
104
+ } ;
105
+
90
106
onShowing (
91
107
loading : boolean ,
92
108
_options ?: WebviewShowOptions ,
@@ -133,6 +149,11 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
133
149
] ;
134
150
}
135
151
152
+ private setOverviewFilter ( value : OverviewFilters ) {
153
+ this . _overviewBranchFilter = value ;
154
+ void this . host . notify ( DidChangeOverviewFilter , { filter : this . _overviewBranchFilter } ) ;
155
+ }
156
+
136
157
async onMessageReceived ( e : IpcMessage ) {
137
158
switch ( true ) {
138
159
case CollapseSectionCommand . is ( e ) :
@@ -141,12 +162,18 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
141
162
case DismissWalkthroughSection . is ( e ) :
142
163
this . dismissWalkthrough ( ) ;
143
164
break ;
165
+ case SetOverviewFilter . is ( e ) :
166
+ this . setOverviewFilter ( e . params ) ;
167
+ break ;
144
168
case GetLaunchpadSummary . is ( e ) :
145
169
void this . host . respond ( GetLaunchpadSummary , e , await getLaunchpadSummary ( this . container ) ) ;
146
170
break ;
147
171
case GetOverview . is ( e ) :
148
172
void this . host . respond ( GetOverview , e , await this . getBranchOverview ( ) ) ;
149
173
break ;
174
+ case GetOverviewFilterState . is ( e ) :
175
+ void this . host . respond ( GetOverviewFilterState , e , this . _overviewBranchFilter ) ;
176
+ break ;
150
177
}
151
178
}
152
179
@@ -202,7 +229,6 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
202
229
}
203
230
204
231
private getWalkthroughDismissed ( ) {
205
- console . log ( { test : this . container . storage . get ( 'home:walkthrough:dismissed' ) } ) ;
206
232
return Boolean ( this . container . storage . get ( 'home:walkthrough:dismissed' ) ) ;
207
233
}
208
234
@@ -276,7 +302,7 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
276
302
branchesAndWorktrees ?. branches ,
277
303
branchesAndWorktrees ?. worktrees ,
278
304
this . container ,
279
- // TODO: add filters
305
+ this . _overviewBranchFilter ,
280
306
) ;
281
307
if ( overviewBranches == null ) return undefined ;
282
308
@@ -427,26 +453,18 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
427
453
}
428
454
}
429
455
430
- const branchOverviewDefaults = Object . freeze ( {
431
- recent : { threshold : 1000 * 60 * 60 * 24 * 14 } ,
432
- stale : { threshold : 1000 * 60 * 60 * 24 * 365 } ,
433
- } ) ;
434
-
435
- interface BranchOverviewOptions {
436
- recent ?: {
437
- threshold : number ;
438
- } ;
439
- stale ?: {
440
- show ?: boolean ;
441
- threshold ?: number ;
442
- } ;
443
- }
456
+ const thresholdValues : Record < OverviewStaleThreshold | OverviewRecentThreshold , number > = {
457
+ OneDay : 1000 * 60 * 60 * 24 * 1 ,
458
+ OneWeek : 1000 * 60 * 60 * 24 * 7 ,
459
+ OneMonth : 1000 * 60 * 60 * 24 * 30 ,
460
+ OneYear : 1000 * 60 * 60 * 24 * 365 ,
461
+ } ;
444
462
445
463
async function getOverviewBranches (
446
464
branches : GitBranch [ ] ,
447
465
worktrees : GitWorktree [ ] ,
448
466
container : Container ,
449
- options ?: BranchOverviewOptions ,
467
+ options : OverviewFilters ,
450
468
) : Promise < GetOverviewBranches | undefined > {
451
469
if ( branches . length === 0 ) return undefined ;
452
470
@@ -469,7 +487,7 @@ async function getOverviewBranches(
469
487
const contributorPromises = new Map < string , Promise < BranchContributorOverview | undefined > > ( ) ;
470
488
471
489
const now = Date . now ( ) ;
472
- const recentThreshold = now - ( options ? .recent ? .threshold ?? branchOverviewDefaults . recent . threshold ) ;
490
+ const recentThreshold = now - thresholdValues [ options . recent . threshold ] ;
473
491
474
492
for ( const branch of branches ) {
475
493
const wt = worktreesByBranch . get ( branch . id ) ;
@@ -520,7 +538,7 @@ async function getOverviewBranches(
520
538
}
521
539
522
540
if ( options ?. stale ?. show === true ) {
523
- const staleThreshold = now - ( options ? .stale ? .threshold ?? branchOverviewDefaults . stale . threshold ) ;
541
+ const staleThreshold = now - thresholdValues [ options . stale . threshold ] ;
524
542
sortBranches ( branches , {
525
543
missingUpstream : true ,
526
544
orderBy : 'date:asc' ,
0 commit comments