From e92bf44487c21c5cfa06ef59a679f9ee6a4d102a Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Tue, 1 Mar 2022 17:38:31 +0200 Subject: [PATCH] fix RED-3352: deactivate multiselect on page change --- .../file-workload.component.html | 6 +- .../file-workload/file-workload.component.ts | 55 +++++++++---------- .../pdf-viewer/pdf-viewer.component.ts | 5 +- .../file-preview-screen.component.html | 4 +- .../file-preview-screen.component.ts | 5 +- 5 files changed, 31 insertions(+), 44 deletions(-) diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/file-workload/file-workload.component.html b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/file-workload/file-workload.component.html index 528e8846d..25e934cfe 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/file-workload/file-workload.component.html +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/file-workload/file-workload.component.html @@ -39,7 +39,7 @@ -
+
-
+
-
+
(); @Input() selectedAnnotations: AnnotationWrapper[]; @Input() activeViewerPage: number; - @Input() shouldDeselectAnnotationsOnPageChange: boolean; @Input() dialogRef: MatDialogRef; @Input() file!: File; @Input() annotationActionsTemplate: TemplateRef; @Input() viewer: WebViewerInstance; - @Output() readonly shouldDeselectAnnotationsOnPageChangeChange = new EventEmitter(); @Output() readonly selectAnnotations = new EventEmitter(); @Output() readonly deselectAnnotations = new EventEmitter(); @Output() readonly selectPage = new EventEmitter(); @@ -66,7 +64,6 @@ export class FileWorkloadComponent { displayedPages: number[] = []; pagesPanelActive = true; readonly displayedAnnotations$: Observable>; - readonly multiSelectActive$: Observable; readonly multiSelectInactive$: Observable; readonly showExcludedPages$: Observable; readonly title$: Observable; @@ -88,7 +85,6 @@ export class FileWorkloadComponent { private readonly _annotationProcessingService: AnnotationProcessingService, ) { this.displayedAnnotations$ = this._displayedAnnotations$; - this.multiSelectActive$ = this._multiSelectActive$; this.multiSelectInactive$ = this._multiSelectInactive$; this.showExcludedPages$ = this._showExcludedPages$; this.isHighlights$ = this._isHighlights$; @@ -140,16 +136,6 @@ export class FileWorkloadComponent { ); } - private get _multiSelectActive$() { - const disableDeselectOnPageChange = (value: boolean) => { - if (value) { - this.shouldDeselectAnnotationsOnPageChange = false; - this.shouldDeselectAnnotationsOnPageChangeChange.emit(false); - } - }; - return this.multiSelectService.active$.pipe(tap(disableDeselectOnPageChange), shareDistinctLast()); - } - private get _firstSelectedAnnotation() { return this.selectedAnnotations?.length ? this.selectedAnnotations[0] : null; } @@ -303,15 +289,11 @@ export class FileWorkloadComponent { // Displayed page doesn't have annotations if ($event.key === 'ArrowDown') { const nextPage = this._nextPageWithAnnotations(); - this.shouldDeselectAnnotationsOnPageChange = false; - this.shouldDeselectAnnotationsOnPageChangeChange.emit(false); this.selectAnnotations.emit([this.displayedAnnotations.get(nextPage)[0]]); return; } const prevPage = this._prevPageWithAnnotations(); - this.shouldDeselectAnnotationsOnPageChange = false; - this.shouldDeselectAnnotationsOnPageChangeChange.emit(false); const prevPageAnnotations = this.displayedAnnotations.get(prevPage); this.selectAnnotations.emit([prevPageAnnotations[prevPageAnnotations.length - 1]]); return; @@ -319,6 +301,8 @@ export class FileWorkloadComponent { const page = this._firstSelectedAnnotation.pageNumber; const pageIdx = this.displayedPages.indexOf(page); + const nextPageIdx = pageIdx + 1; + const previousPageIdx = pageIdx - 1; const annotationsOnPage = this.displayedAnnotations.get(page); const idx = annotationsOnPage.findIndex(a => a.id === this._firstSelectedAnnotation.id); @@ -326,22 +310,33 @@ export class FileWorkloadComponent { if (idx + 1 !== annotationsOnPage.length) { // If not last item in page this.selectAnnotations.emit([annotationsOnPage[idx + 1]]); - } else if (pageIdx + 1 < this.displayedPages.length) { + } else if (nextPageIdx < this.displayedPages.length) { // If not last page - const nextPageAnnotations = this.displayedAnnotations.get(this.displayedPages[pageIdx + 1]); - this.shouldDeselectAnnotationsOnPageChange = false; - this.shouldDeselectAnnotationsOnPageChangeChange.emit(false); - this.selectAnnotations.emit([nextPageAnnotations[0]]); + for (let i = nextPageIdx; i < this.displayedPages.length; i++) { + const nextPageAnnotations = this.displayedAnnotations.get(this.displayedPages[i]); + if (nextPageAnnotations) { + this.selectAnnotations.emit([nextPageAnnotations[0]]); + break; + } + } } - } else if (idx !== 0) { + return; + } + + if (idx !== 0) { // If not first item in page - this.selectAnnotations.emit([annotationsOnPage[idx - 1]]); - } else if (pageIdx) { + return this.selectAnnotations.emit([annotationsOnPage[idx - 1]]); + } + + if (pageIdx) { // If not first page - const prevPageAnnotations = this.displayedAnnotations.get(this.displayedPages[pageIdx - 1]); - this.shouldDeselectAnnotationsOnPageChange = false; - this.shouldDeselectAnnotationsOnPageChangeChange.emit(false); - this.selectAnnotations.emit([prevPageAnnotations[prevPageAnnotations.length - 1]]); + for (let i = previousPageIdx; i > 0; i--) { + const prevPageAnnotations = this.displayedAnnotations.get(this.displayedPages[i]); + if (prevPageAnnotations) { + this.selectAnnotations.emit([prevPageAnnotations[prevPageAnnotations.length - 1]]); + break; + } + } } } diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/pdf-viewer/pdf-viewer.component.ts b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/pdf-viewer/pdf-viewer.component.ts index 0c92b92ab..f6a2a834a 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/pdf-viewer/pdf-viewer.component.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/pdf-viewer/pdf-viewer.component.ts @@ -67,7 +67,6 @@ export class PdfViewerComponent extends AutoUnsubscribe implements OnInit, OnCha @Input() dossier: Dossier; @Input() canPerformActions = false; @Input() annotations: AnnotationWrapper[]; - @Input() shouldDeselectAnnotationsOnPageChange = true; @Output() readonly fileReady = new EventEmitter(); @Output() readonly annotationSelected = new EventEmitter(); @Output() readonly manualAnnotationRequested = new EventEmitter(); @@ -266,9 +265,7 @@ export class PdfViewerComponent extends AutoUnsubscribe implements OnInit, OnCha }); this.documentViewer.addEventListener('pageNumberUpdated', (pageNumber: number) => { - if (this.shouldDeselectAnnotationsOnPageChange) { - this.utils.deselectAllAnnotations(); - } + this.utils.deselectAllAnnotations(); this._ngZone.run(() => this.pageChanged.emit(pageNumber)); return this._handleCustomActions(); }); diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.html b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.html index 811373798..a2f32d01f 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.html +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.html @@ -20,8 +20,8 @@
@@ -93,7 +92,6 @@ (selectAnnotations)="selectAnnotations($event)" (selectPage)="selectPage($event)" *ngIf="!file.excluded" - [(shouldDeselectAnnotationsOnPageChange)]="shouldDeselectAnnotationsOnPageChange" [activeViewerPage]="activeViewerPage" [annotationActionsTemplate]="annotationActionsTemplate" [annotations]="visibleAnnotations" diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts index 2c988e34d..d50fbb5ef 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts @@ -65,7 +65,6 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni dialogRef: MatDialogRef; fullScreen = false; - shouldDeselectAnnotationsOnPageChange = true; selectedAnnotations: AnnotationWrapper[] = []; displayPdfViewer = false; activeViewerPage: number = null; @@ -394,9 +393,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni } this._scrollViews(); - if (!this.multiSelectService.isActive) { - this.shouldDeselectAnnotationsOnPageChange = true; - } + this.multiSelectService.deactivate(); // Add current page in URL query params const extras: NavigationExtras = {