From de8ac013eea0bfc4f844ae52fca45c9532e703b5 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Wed, 10 Jul 2024 20:27:04 -0700 Subject: [PATCH] Enhancement: disable add split button when approrpriate (#7215) --- .../split-confirm-dialog.component.html | 2 +- .../split-confirm-dialog.component.spec.ts | 12 ++++++++++++ .../split-confirm-dialog.component.ts | 8 ++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src-ui/src/app/components/common/confirm-dialog/split-confirm-dialog/split-confirm-dialog.component.html b/src-ui/src/app/components/common/confirm-dialog/split-confirm-dialog/split-confirm-dialog.component.html index 411f5ab79..7fb68218a 100644 --- a/src-ui/src/app/components/common/confirm-dialog/split-confirm-dialog/split-confirm-dialog.component.html +++ b/src-ui/src/app/components/common/confirm-dialog/split-confirm-dialog/split-confirm-dialog.component.html @@ -23,7 +23,7 @@
- diff --git a/src-ui/src/app/components/common/confirm-dialog/split-confirm-dialog/split-confirm-dialog.component.spec.ts b/src-ui/src/app/components/common/confirm-dialog/split-confirm-dialog/split-confirm-dialog.component.spec.ts index 66bf2bf71..ffb5e12f3 100644 --- a/src-ui/src/app/components/common/confirm-dialog/split-confirm-dialog/split-confirm-dialog.component.spec.ts +++ b/src-ui/src/app/components/common/confirm-dialog/split-confirm-dialog/split-confirm-dialog.component.spec.ts @@ -92,4 +92,16 @@ describe('SplitConfirmDialogComponent', () => { component.pdfPreviewLoaded({ numPages: 5 } as any) expect(component.totalPages).toEqual(5) }) + + it('should correctly disable split button', () => { + component.totalPages = 5 + component.page = 1 + expect(component.canSplit).toBeTruthy() + component.page = 5 + expect(component.canSplit).toBeFalsy() + component.page = 4 + expect(component.canSplit).toBeTruthy() + component['pages'] = new Set([1, 2, 3, 4]) + expect(component.canSplit).toBeFalsy() + }) }) diff --git a/src-ui/src/app/components/common/confirm-dialog/split-confirm-dialog/split-confirm-dialog.component.ts b/src-ui/src/app/components/common/confirm-dialog/split-confirm-dialog/split-confirm-dialog.component.ts index 266da00ab..d5f264116 100644 --- a/src-ui/src/app/components/common/confirm-dialog/split-confirm-dialog/split-confirm-dialog.component.ts +++ b/src-ui/src/app/components/common/confirm-dialog/split-confirm-dialog/split-confirm-dialog.component.ts @@ -42,6 +42,14 @@ export class SplitConfirmDialogComponent public totalPages: number public deleteOriginal: boolean = false + public get canSplit(): boolean { + return ( + this.page < this.totalPages && + this.pages.size < this.totalPages - 1 && + !this.pages.has(this.page) + ) + } + public get pdfSrc(): string { return this.documentService.getPreviewUrl(this.documentID) }