3">
+ @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,