From f6b805515093809eb7998a7c9229cdde34c27fc6 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:33:37 -0800 Subject: [PATCH] Wire in the collapseTags, split and parentClick. Update get more tags too --- .../saved-view-widget.component.html | 4 +-- .../saved-view-widget.component.ts | 2 ++ .../document-card-large.component.html | 4 +-- .../document-card-large.component.ts | 2 ++ .../document-card-small.component.html | 9 ++--- .../document-card-small.component.scss | 3 +- .../document-card-small.component.spec.ts | 35 +++++++++++++++++-- .../document-card-small.component.ts | 26 +++++++------- .../document-list.component.html | 4 +-- .../document-list/document-list.component.ts | 2 ++ 10 files changed, 64 insertions(+), 27 deletions(-) diff --git a/src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.html b/src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.html index 823e4f2aff..4f94cfee47 100644 --- a/src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.html +++ b/src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.html @@ -76,8 +76,8 @@ } } @case (DisplayField.TAGS) { - @for (tagID of doc.tags; track tagID) { - + @for (tagID of doc.tags | collapseTags | async; track tagID) { + } } @case (DisplayField.DOCUMENT_TYPE) { diff --git a/src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.ts b/src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.ts index 5daf99fb22..4e5e2d3bd0 100644 --- a/src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.ts +++ b/src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.ts @@ -38,6 +38,7 @@ import { } from 'src/app/data/filter-rule-type' import { SavedView } from 'src/app/data/saved-view' import { IfPermissionsDirective } from 'src/app/directives/if-permissions.directive' +import { CollapseTagsPipe } from 'src/app/pipes/collapse-tags.pipe' import { CorrespondentNamePipe } from 'src/app/pipes/correspondent-name.pipe' import { CustomDatePipe } from 'src/app/pipes/custom-date.pipe' import { DocumentTitlePipe } from 'src/app/pipes/document-title.pipe' @@ -75,6 +76,7 @@ import { WidgetFrameComponent } from '../widget-frame/widget-frame.component' DocumentTypeNamePipe, StoragePathNamePipe, AsyncPipe, + CollapseTagsPipe, DocumentTitlePipe, CustomDatePipe, NgClass, diff --git a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.html b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.html index 19a1e816bf..6f6067a932 100644 --- a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.html +++ b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.html @@ -36,8 +36,8 @@ {{document().title | documentTitle}} } @if (displayFields().includes(DisplayField.TAGS)) { - @for (tagID of document().tags; track tagID) { - + @for (tagID of document().tags | collapseTags | async; track tagID) { + } } } @else { diff --git a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts index 293b3ddd2f..98a5d286e4 100644 --- a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts +++ b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts @@ -20,6 +20,7 @@ import { Document, } from 'src/app/data/document' import { SETTINGS_KEYS } from 'src/app/data/ui-settings' +import { CollapseTagsPipe } from 'src/app/pipes/collapse-tags.pipe' import { CorrespondentNamePipe } from 'src/app/pipes/correspondent-name.pipe' import { CustomDatePipe } from 'src/app/pipes/custom-date.pipe' import { DocumentTitlePipe } from 'src/app/pipes/document-title.pipe' @@ -45,6 +46,7 @@ import { LoadingComponentWithPermissions } from '../../loading-component/loading TagComponent, CustomFieldDisplayComponent, AsyncPipe, + CollapseTagsPipe, NgOptimizedImage, UsernamePipe, CorrespondentNamePipe, diff --git a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.html b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.html index 8c05d95d74..1b77c34ecf 100644 --- a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.html +++ b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.html @@ -19,11 +19,12 @@ } @if (document() && displayFields().includes(DisplayField.TAGS)) { -
- @for (tagID of tagIDs; track tagID) { - + @let visibleTagIDs = document().tags | collapseTags | async; +
+ @for (tagID of getTagIDs(visibleTagIDs); track tagID) { + } - @if (moreTags) { + @if (getMoreTags(visibleTagIDs); as moreTags) {
+ {{moreTags}}
diff --git a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.scss b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.scss index d098b126bc..0aa525fa31 100644 --- a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.scss +++ b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.scss @@ -103,7 +103,8 @@ a { line-height: 1; &.tags-no-wrap { - ::ng-deep .badge { + // split-pill parents clip to a stub instead (see TagComponent) + ::ng-deep .badge:not(.split-parent) { display: inline-block; max-width: 100%; white-space: nowrap; diff --git a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.spec.ts b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.spec.ts index 2b5b3245d4..c28037ab7f 100644 --- a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.spec.ts +++ b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.spec.ts @@ -4,6 +4,9 @@ import { provideHttpClientTesting } from '@angular/common/http/testing' import { ComponentFixture, TestBed } from '@angular/core/testing' import { By } from '@angular/platform-browser' import { RouterTestingModule } from '@angular/router/testing' +import { of } from 'rxjs' +import { PermissionsService } from 'src/app/services/permissions.service' +import { TagService } from 'src/app/services/rest/tag.service' import { TagComponent } from '../../common/tag/tag.component' import { DocumentCardSmallComponent } from './document-card-small.component' @@ -97,8 +100,36 @@ describe('DocumentCardSmallComponent', () => { ).toHaveLength(6) }) + it('should hide parent tags implied by a child and count pills for the hidden tag counter', () => { + jest + .spyOn(TestBed.inject(PermissionsService), 'currentUserCan') + .mockReturnValue(true) + jest.spyOn(TestBed.inject(TagService), 'listAll').mockReturnValue( + of({ + count: 8, + all: [1, 2, 3, 4, 5, 6, 7, 8], + results: [ + { id: 1, name: 'Parent' }, + { id: 2, name: 'Child', parent: 1 }, + ...[3, 4, 5, 6, 7, 8].map((id) => ({ id, name: `Tag ${id}` })), + ], + }) + ) + fixture.componentRef.setInput('document', { + ...component.document(), + tags: [1, 2, 3, 4, 5, 6, 7, 8], + }) + fixture.detectChanges() + + const tags = fixture.debugElement.queryAll(By.directive(TagComponent)) + expect(tags.map((t) => t.componentInstance.tagID())).toEqual([ + 2, 3, 4, 5, 6, + ]) + expect(fixture.nativeElement.textContent).toContain('+ 2') + }) + it('should clear hidden tag counter when tag count falls below the limit', () => { - expect(component.moreTags).toEqual(3) + expect(component.getMoreTags(component.document().tags)).toEqual(3) fixture.componentRef.setInput('document', { ...component.document(), @@ -106,7 +137,7 @@ describe('DocumentCardSmallComponent', () => { }) fixture.detectChanges() - expect(component.moreTags).toBeNull() + expect(component.getMoreTags(component.document().tags)).toBeNull() expect(fixture.nativeElement.textContent).not.toContain('+ 3') }) diff --git a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.ts b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.ts index 784b47ce08..6b9e5f0972 100644 --- a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.ts +++ b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.ts @@ -20,6 +20,7 @@ import { Document, } from 'src/app/data/document' import { SETTINGS_KEYS } from 'src/app/data/ui-settings' +import { CollapseTagsPipe } from 'src/app/pipes/collapse-tags.pipe' import { CorrespondentNamePipe } from 'src/app/pipes/correspondent-name.pipe' import { CustomDatePipe } from 'src/app/pipes/custom-date.pipe' import { DocumentTitlePipe } from 'src/app/pipes/document-title.pipe' @@ -45,6 +46,7 @@ import { LoadingComponentWithPermissions } from '../../loading-component/loading TagComponent, CustomFieldDisplayComponent, AsyncPipe, + CollapseTagsPipe, NgOptimizedImage, UsernamePipe, CorrespondentNamePipe, @@ -90,12 +92,13 @@ export class DocumentCardSmallComponent @Output() clickStoragePath = new EventEmitter() - get moreTags(): number { - const document = this.document() - const limit = document?.notes.length > 0 ? 6 : 7 - return document?.tags.length > limit - ? document.tags.length - (limit - 1) - : null + private get tagLimit(): number { + return this.document()?.notes.length > 0 ? 6 : 7 + } + + getMoreTags(tagIDs: number[]): number { + const limit = this.tagLimit + return tagIDs?.length > limit ? tagIDs.length - (limit - 1) : null } @ViewChild('popupPreview') popupPreview: PreviewPopupComponent @@ -116,14 +119,9 @@ export class DocumentCardSmallComponent return this.documentService.getDownloadUrl(this.document().id) } - get tagIDs() { - const document = this.document() - const limit = document.notes.length > 0 ? 6 : 7 - if (document.tags.length > limit) { - return document.tags.slice(0, limit - 1) - } else { - return document.tags - } + getTagIDs(tagIDs: number[]): number[] { + const limit = this.tagLimit + return tagIDs?.length > limit ? tagIDs.slice(0, limit - 1) : tagIDs } mouseLeaveCard() { diff --git a/src-ui/src/app/components/document-list/document-list.component.html b/src-ui/src/app/components/document-list/document-list.component.html index 71c384300c..3f6e2e56bd 100644 --- a/src-ui/src/app/components/document-list/document-list.component.html +++ b/src-ui/src/app/components/document-list/document-list.component.html @@ -335,8 +335,8 @@ {{d.title | documentTitle}} } @if (activeDisplayFields.includes(DisplayField.TAGS)) { - @for (tagID of d.tags; track tagID) { - + @for (tagID of d.tags | collapseTags | async; track tagID) { + } } 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 b182b40af2..146e3dda88 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 @@ -39,6 +39,7 @@ import { SortableDirective, SortEvent, } from 'src/app/directives/sortable.directive' +import { CollapseTagsPipe } from 'src/app/pipes/collapse-tags.pipe' import { CorrespondentNamePipe } from 'src/app/pipes/correspondent-name.pipe' import { CustomDatePipe } from 'src/app/pipes/custom-date.pipe' import { DocumentTitlePipe } from 'src/app/pipes/document-title.pipe' @@ -96,6 +97,7 @@ import { SaveViewConfigDialogComponent } from './save-view-config-dialog/save-vi StoragePathNamePipe, BootstrapIconComponent, AsyncPipe, + CollapseTagsPipe, FormsModule, ReactiveFormsModule, NgTemplateOutlet,