@@ -95,83 +95,43 @@ export class WorkspaceExperiments extends BaseWorkspaceWebviews<
9595 )
9696 }
9797
98- public async addFilter ( overrideRoot ?: string ) {
99- const dvcRoot = await this . getDvcRoot ( overrideRoot )
100- if ( ! dvcRoot ) {
101- return
102- }
103- return this . getRepository ( dvcRoot ) . addFilter ( )
98+ public addFilter ( overrideRoot ?: string ) {
99+ return this . getRepositoryThenUpdate ( 'addFilter' , overrideRoot )
104100 }
105101
106- public async addStarredFilter ( overrideRoot ?: string ) {
107- const dvcRoot = await this . getDvcRoot ( overrideRoot )
108- if ( ! dvcRoot ) {
109- return
110- }
111- return this . getRepository ( dvcRoot ) . addStarredFilter ( )
102+ public addStarredFilter ( overrideRoot ?: string ) {
103+ return this . getRepositoryThenUpdate ( 'addStarredFilter' , overrideRoot )
112104 }
113105
114- public async removeFilters ( ) {
115- const dvcRoot = await this . getFocusedOrOnlyOrPickProject ( )
116- if ( ! dvcRoot ) {
117- return
118- }
119- return this . getRepository ( dvcRoot ) . removeFilters ( )
106+ public removeFilters ( ) {
107+ return this . getRepositoryThenUpdate ( 'removeFilters' )
120108 }
121109
122- public async addSort ( overrideRoot ?: string ) {
123- const dvcRoot = await this . getDvcRoot ( overrideRoot )
124- if ( ! dvcRoot ) {
125- return
126- }
127- return this . getRepository ( dvcRoot ) . addSort ( )
110+ public addSort ( overrideRoot ?: string ) {
111+ return this . getRepositoryThenUpdate ( 'addSort' , overrideRoot )
128112 }
129113
130- public async addStarredSort ( overrideRoot ?: string ) {
131- const dvcRoot = await this . getDvcRoot ( overrideRoot )
132- if ( ! dvcRoot ) {
133- return
134- }
135- return this . getRepository ( dvcRoot ) . addStarredSort ( )
114+ public addStarredSort ( overrideRoot ?: string ) {
115+ return this . getRepositoryThenUpdate ( 'addStarredSort' , overrideRoot )
136116 }
137117
138- public async removeSorts ( ) {
139- const dvcRoot = await this . getFocusedOrOnlyOrPickProject ( )
140- if ( ! dvcRoot ) {
141- return
142- }
143-
144- return this . getRepository ( dvcRoot ) . removeSorts ( )
118+ public removeSorts ( ) {
119+ return this . getRepositoryThenUpdate ( 'removeSorts' )
145120 }
146121
147- public async selectExperimentsToPlot ( overrideRoot ?: string ) {
148- const dvcRoot = await this . getDvcRoot ( overrideRoot )
149- if ( ! dvcRoot ) {
150- return
151- }
152- return this . getRepository ( dvcRoot ) . selectExperimentsToPlot ( )
122+ public selectExperimentsToPlot ( overrideRoot ?: string ) {
123+ return this . getRepositoryThenUpdate ( 'selectExperimentsToPlot' , overrideRoot )
153124 }
154125
155- public async selectColumns ( overrideRoot ?: string ) {
156- const dvcRoot = await this . getDvcRoot ( overrideRoot )
157- if ( ! dvcRoot ) {
158- return
159- }
160- return this . getRepository ( dvcRoot ) . selectColumns ( )
126+ public selectColumns ( overrideRoot ?: string ) {
127+ return this . getRepositoryThenUpdate ( 'selectColumns' , overrideRoot )
161128 }
162129
163- public async selectQueueTasksToKill ( ) {
164- const cwd = await this . getFocusedOrOnlyOrPickProject ( )
165- if ( ! cwd ) {
166- return
167- }
168-
169- const taskIds = await this . getRepository ( cwd ) . pickQueueTasksToKill ( )
170-
171- if ( ! taskIds || isEmpty ( taskIds ) ) {
172- return
173- }
174- return this . runCommand ( AvailableCommands . QUEUE_KILL , cwd , ...taskIds )
130+ public selectQueueTasksToKill ( ) {
131+ return this . pickIdsThenRun (
132+ 'pickQueueTasksToKill' ,
133+ AvailableCommands . QUEUE_KILL
134+ )
175135 }
176136
177137 public async selectExperimentsToPush ( setup : Setup ) {
@@ -190,20 +150,11 @@ export class WorkspaceExperiments extends BaseWorkspaceWebviews<
190150 return pushCommand ( { dvcRoot, ids } )
191151 }
192152
193- public async selectExperimentsToRemove ( ) {
194- const cwd = await this . getFocusedOrOnlyOrPickProject ( )
195- if ( ! cwd ) {
196- return
197- }
198-
199- const experimentIds = await this . getRepository (
200- cwd
201- ) . pickExperimentsToRemove ( )
202- if ( ! experimentIds || isEmpty ( experimentIds ) ) {
203- return
204- }
205-
206- return this . runCommand ( AvailableCommands . EXP_REMOVE , cwd , ...experimentIds )
153+ public selectExperimentsToRemove ( ) {
154+ return this . pickIdsThenRun (
155+ 'pickExperimentsToRemove' ,
156+ AvailableCommands . EXP_REMOVE
157+ )
207158 }
208159
209160 public async modifyExperimentParamsAndRun (
@@ -453,6 +404,25 @@ export class WorkspaceExperiments extends BaseWorkspaceWebviews<
453404 )
454405 }
455406
407+ private async getRepositoryThenUpdate (
408+ method :
409+ | 'addFilter'
410+ | 'addStarredFilter'
411+ | 'removeFilters'
412+ | 'addSort'
413+ | 'addStarredSort'
414+ | 'removeSorts'
415+ | 'selectExperimentsToPlot'
416+ | 'selectColumns' ,
417+ overrideRoot ?: string
418+ ) {
419+ const dvcRoot = await this . getDvcRoot ( overrideRoot )
420+ if ( ! dvcRoot ) {
421+ return
422+ }
423+ return this . getRepository ( dvcRoot ) [ method ] ( )
424+ }
425+
456426 private async shouldRun ( ) {
457427 const cwd = await this . getFocusedOrOnlyOrPickProject ( )
458428 if ( ! cwd ) {
@@ -555,6 +525,25 @@ export class WorkspaceExperiments extends BaseWorkspaceWebviews<
555525 return { command, enteredManually, trainingScript }
556526 }
557527
528+ private async pickIdsThenRun (
529+ pickMethod : 'pickQueueTasksToKill' | 'pickExperimentsToRemove' ,
530+ commandId :
531+ | typeof AvailableCommands . QUEUE_KILL
532+ | typeof AvailableCommands . EXP_REMOVE
533+ ) {
534+ const cwd = await this . getFocusedOrOnlyOrPickProject ( )
535+ if ( ! cwd ) {
536+ return
537+ }
538+
539+ const ids = await this . getRepository ( cwd ) [ pickMethod ] ( )
540+
541+ if ( ! ids || isEmpty ( ids ) ) {
542+ return
543+ }
544+ return this . runCommand ( commandId , cwd , ...ids )
545+ }
546+
558547 private async pickExpThenRun (
559548 commandId : CommandId ,
560549 pickFunc : ( cwd : string ) => Thenable < string | undefined > | undefined
0 commit comments