From c7a1b5b514229672001e3aad11016784e22ecca9 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 7 Apr 2024 17:50:50 -0700 Subject: [PATCH] Support opening selected document --- .../document-list.component.spec.ts | 8 ++++++++ .../document-list/document-list.component.ts | 18 ++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src-ui/src/app/components/document-list/document-list.component.spec.ts b/src-ui/src/app/components/document-list/document-list.component.spec.ts index c4420ad3f..c1b95295c 100644 --- a/src-ui/src/app/components/document-list/document-list.component.spec.ts +++ b/src-ui/src/app/components/document-list/document-list.component.spec.ts @@ -629,5 +629,13 @@ describe('DocumentListComponent', () => { const detailSpy = jest.spyOn(component, 'openDocumentDetail') document.dispatchEvent(new KeyboardEvent('keydown', { key: 'o' })) expect(detailSpy).toHaveBeenCalledWith(docs[0]) + + jest.spyOn(documentListService, 'documents', 'get').mockReturnValue(docs) + jest + .spyOn(documentListService, 'selected', 'get') + .mockReturnValue(new Set([docs[1].id])) + fixture.detectChanges() + document.dispatchEvent(new KeyboardEvent('keydown', { key: 'o' })) + expect(detailSpy).toHaveBeenCalledWith(docs[1].id) }) }) diff --git a/src-ui/src/app/components/document-list/document-list.component.ts b/src-ui/src/app/components/document-list/document-list.component.ts index 75658f4c7..5a455846d 100644 --- a/src-ui/src/app/components/document-list/document-list.component.ts +++ b/src-ui/src/app/components/document-list/document-list.component.ts @@ -216,11 +216,18 @@ export class DocumentListComponent }) this.hotKeyService - .addShortcut({ keys: 'o', description: $localize`Open first document` }) + .addShortcut({ + keys: 'o', + description: $localize`Open first [selected] document`, + }) .pipe(takeUntil(this.unsubscribeNotifier)) .subscribe(() => { if (this.list.documents.length > 0) { - this.openDocumentDetail(this.list.documents[0]) + if (this.list.selected.size > 0) { + this.openDocumentDetail(Array.from(this.list.selected)[0]) + } else { + this.openDocumentDetail(this.list.documents[0]) + } } }) } @@ -301,8 +308,11 @@ export class DocumentListComponent }) } - openDocumentDetail(document: Document) { - this.router.navigate(['documents', document.id]) + openDocumentDetail(document: Document | number) { + this.router.navigate([ + 'documents', + typeof document === 'number' ? document : document.id, + ]) } toggleSelected(document: Document, event: MouseEvent): void {