@@ -47,11 +47,13 @@ export class WebviewMessages {
4747 private hasConfig = false
4848 private hasValidDvcYaml = true
4949 private hasMoreCommits = false
50+ private isShowingMoreCommits = true
51+
5052 private numberOfCommitsToShow = Number . parseInt ( NUM_OF_COMMITS_TO_SHOW , 10 )
5153
5254 private readonly addStage : ( ) => Promise < boolean >
5355 private readonly getNumCommits : ( ) => Promise < number >
54- private readonly getMoreCommits : ( nbOfCommits : number ) => Promise < void >
56+ private readonly changeNbOfCommits : ( nbOfCommits : number ) => Promise < void >
5557
5658 constructor (
5759 dvcRoot : string ,
@@ -68,7 +70,7 @@ export class WebviewMessages {
6870 hasStages : ( ) => Promise < string > ,
6971 addStage : ( ) => Promise < boolean > ,
7072 getNumCommits : ( ) => Promise < number > ,
71- getMoreCommits : ( nbOfCommits : number ) => Promise < void >
73+ changeNbOfCommits : ( nbOfCommits : number ) => Promise < void >
7274 ) {
7375 this . dvcRoot = dvcRoot
7476 this . experiments = experiments
@@ -81,10 +83,10 @@ export class WebviewMessages {
8183 this . hasStages = hasStages
8284 this . addStage = addStage
8385 this . getNumCommits = getNumCommits
84- this . getMoreCommits = getMoreCommits
86+ this . changeNbOfCommits = changeNbOfCommits
8587
8688 void this . changeHasConfig ( )
87- void this . changeHasMoreCommits ( )
89+ void this . changeHasMoreOrLessCommits ( )
8890 }
8991
9092 public async changeHasConfig ( update ?: boolean ) {
@@ -216,22 +218,27 @@ export class WebviewMessages {
216218 )
217219
218220 case MessageFromWebviewType . SHOW_MORE_COMMITS :
219- return this . changeNumberOfCommits ( )
221+ return this . changeCommitsToShow ( 1 )
222+
223+ case MessageFromWebviewType . SHOW_LESS_COMMITS :
224+ return this . changeCommitsToShow ( - 1 )
220225
221226 default :
222227 Logger . error ( `Unexpected message: ${ JSON . stringify ( message ) } ` )
223228 }
224229 }
225230
226- private async changeHasMoreCommits ( ) {
227- this . hasMoreCommits =
228- ( await this . getNumCommits ( ) ) > this . numberOfCommitsToShow
231+ private async changeHasMoreOrLessCommits ( ) {
232+ const availableNbCommits = await this . getNumCommits ( )
233+ this . hasMoreCommits = availableNbCommits > this . numberOfCommitsToShow
234+ this . isShowingMoreCommits =
235+ Math . min ( this . numberOfCommitsToShow , availableNbCommits ) > 1
229236 }
230237
231- private async changeNumberOfCommits ( ) {
232- this . numberOfCommitsToShow = this . numberOfCommitsToShow + 2
233- await this . getMoreCommits ( this . numberOfCommitsToShow )
234- await this . changeHasMoreCommits ( )
238+ private async changeCommitsToShow ( change : number ) {
239+ this . numberOfCommitsToShow = this . numberOfCommitsToShow + 2 * change
240+ await this . changeNbOfCommits ( this . numberOfCommitsToShow )
241+ await this . changeHasMoreOrLessCommits ( )
235242 }
236243
237244 private getWebviewData ( ) {
@@ -250,6 +257,7 @@ export class WebviewMessages {
250257 hasMoreCommits : this . hasMoreCommits ,
251258 hasRunningExperiment : this . experiments . hasRunningExperiment ( ) ,
252259 hasValidDvcYaml : this . hasValidDvcYaml ,
260+ isShowingMoreCommits : this . isShowingMoreCommits ,
253261 rows : this . experiments . getRowData ( ) ,
254262 sorts : this . experiments . getSorts ( )
255263 }
0 commit comments