Use the new display tags pipe and hidden badge on lists

This commit is contained in:
shamoon committed 2026-11-25 16:20:11 -08:00
1 parent 4f9832da8c
commit a55535eb54
9 files changed
+88 -13

No files matched your search

@@ -76,9 +76,13 @@
}
}
@case (DisplayField.TAGS) {
@for (tagID of doc.tags | collapseTags | async; track tagID) {
@let tags = doc.tags | displayTags | async;
@for (tagID of tags?.visible; track tagID) {
<pngx-tag [tagID]="tagID" [split]="true" class="ms-1 fs-6" (click)="clickTag(tagID, $event)" (parentClick)="clickTag($event)" [clickable]="true" linkTitle="Filter by tag" i18n-title></pngx-tag>
}
@if (tags?.hidden.length) {
<pngx-hidden-tags-badge [count]="tags.hidden.length" class="ms-1 fs-6"></pngx-hidden-tags-badge>
}
}
@case (DisplayField.DOCUMENT_TYPE) {
@if (doc.document_type) {
@@ -1,3 +1,4 @@
import { HiddenTagsBadgeComponent } from 'src/app/components/common/hidden-tags-badge/hidden-tags-badge.component'
import { AsyncPipe, NgClass, NgStyle } from '@angular/common'
import {
Component,
@@ -38,7 +39,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 { DisplayTagsPipe } from 'src/app/pipes/display-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'
@@ -76,7 +77,8 @@ import { WidgetFrameComponent } from '../widget-frame/widget-frame.component'
DocumentTypeNamePipe,
StoragePathNamePipe,
AsyncPipe,
CollapseTagsPipe,
DisplayTagsPipe,
HiddenTagsBadgeComponent,
DocumentTitlePipe,
CustomDatePipe,
NgClass,
@@ -36,9 +36,13 @@
{{document().title | documentTitle}}
}
@if (displayFields().includes(DisplayField.TAGS)) {
@for (tagID of document().tags | collapseTags | async; track tagID) {
@let tags = document().tags | displayTags | async;
@for (tagID of tags?.visible; track tagID) {
<pngx-tag [tagID]="tagID" [split]="true" linkTitle="Filter by tag" i18n-linkTitle class="ms-1" (click)="clickTag.emit(tagID);$event.stopPropagation()" (parentClick)="clickTag.emit($event)" [clickable]="clickTag.observers.length"></pngx-tag>
}
@if (tags?.hidden.length) {
<pngx-hidden-tags-badge [count]="tags.hidden.length" class="ms-1"></pngx-hidden-tags-badge>
}
}
} @else {
<div class="placeholder bg-secondary w-75 mb-3">&nbsp;</div>
@@ -1,3 +1,4 @@
import { HiddenTagsBadgeComponent } from 'src/app/components/common/hidden-tags-badge/hidden-tags-badge.component'
import { AsyncPipe, NgOptimizedImage } from '@angular/common'
import {
AfterViewInit,
@@ -20,7 +21,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 { DisplayTagsPipe } from 'src/app/pipes/display-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'
@@ -46,7 +47,8 @@ import { LoadingComponentWithPermissions } from '../../loading-component/loading
TagComponent,
CustomFieldDisplayComponent,
AsyncPipe,
CollapseTagsPipe,
DisplayTagsPipe,
HiddenTagsBadgeComponent,
NgOptimizedImage,
UsernamePipe,
CorrespondentNamePipe,
@@ -19,8 +19,10 @@
}
@if (document() && displayFields().includes(DisplayField.TAGS)) {
@let visibleTagIDs = document().tags | collapseTags | async;
<div class="tags d-flex flex-column text-end position-absolute me-1 fs-6" [class.tags-no-wrap]="visibleTagIDs?.length > 3">
@let tags = document().tags | displayTags | async;
@let visibleTagIDs = tags?.visible;
@let showHidden = showHiddenTags(tags);
<div class="tags d-flex flex-column text-end position-absolute me-1 fs-6" [class.tags-no-wrap]="(visibleTagIDs?.length ?? 0) + (showHidden ? 1 : 0) > 3">
@for (tagID of getTagIDs(visibleTagIDs); track tagID) {
<pngx-tag [tagID]="tagID" [split]="true" (click)="clickTag.emit(tagID);$event.stopPropagation()" (parentClick)="clickTag.emit($event)" [clickable]="true" linkTitle="Toggle tag filter" i18n-linkTitle></pngx-tag>
}
@@ -29,6 +31,9 @@
<span class="badge text-dark">+ {{moreTags}}</span>
</div>
}
@if (showHidden) {
<pngx-hidden-tags-badge [count]="tags.hidden.length"></pngx-hidden-tags-badge>
}
</div>
}
</div>
@@ -42,6 +42,19 @@ describe('DocumentCardSmallComponent', () => {
],
}).compileComponents()
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: [1, 2, 3, 4, 5, 6, 7, 8].map((id) => ({
id,
name: `Tag ${id}`,
})),
})
)
fixture = TestBed.createComponent(DocumentCardSmallComponent)
component = fixture.componentInstance
fixture.componentRef.setInput('document', Object.assign({}, doc))
@@ -148,4 +161,33 @@ describe('DocumentCardSmallComponent', () => {
component.mouseLeaveCard()
expect(component.popupPreview.close).toHaveBeenCalled()
})
it('should show hidden tags last, only when visible tags leave a slot free', () => {
fixture.componentRef.setInput('document', {
...component.document(),
tags: [1, 2, 3, 98, 99],
})
fixture.detectChanges()
const tagsEl = () => fixture.nativeElement.querySelector('.tags')
expect(tagsEl().lastElementChild.textContent).toContain('2 hidden')
// 6 visible tags fill the limit (document has notes)
fixture.componentRef.setInput('document', {
...component.document(),
tags: [1, 2, 3, 4, 5, 6, 98, 99],
})
fixture.detectChanges()
expect(tagsEl().textContent).not.toContain('hidden')
expect(
fixture.debugElement.queryAll(By.directive(TagComponent))
).toHaveLength(6)
fixture.componentRef.setInput('document', {
...component.document(),
tags: [1, 2, 3, 4, 5, 6, 7, 98],
})
fixture.detectChanges()
expect(tagsEl().textContent).toContain('+ 2')
expect(tagsEl().textContent).not.toContain('hidden')
})
})
@@ -1,3 +1,5 @@
import { TagPartition } from 'src/app/utils/tag-display'
import { HiddenTagsBadgeComponent } from 'src/app/components/common/hidden-tags-badge/hidden-tags-badge.component'
import { AsyncPipe, NgOptimizedImage } from '@angular/common'
import {
AfterViewInit,
@@ -20,7 +22,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 { DisplayTagsPipe } from 'src/app/pipes/display-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'
@@ -46,7 +48,8 @@ import { LoadingComponentWithPermissions } from '../../loading-component/loading
TagComponent,
CustomFieldDisplayComponent,
AsyncPipe,
CollapseTagsPipe,
DisplayTagsPipe,
HiddenTagsBadgeComponent,
NgOptimizedImage,
UsernamePipe,
CorrespondentNamePipe,
@@ -96,6 +99,13 @@ export class DocumentCardSmallComponent
return this.document()?.notes.length > 0 ? 6 : 7
}
/**
* The hidden tags badge only fills a slot the visible tags leave free.
*/
showHiddenTags(tags: TagPartition): boolean {
return tags?.hidden.length > 0 && tags.visible.length < this.tagLimit
}
getMoreTags(tagIDs: number[]): number {
const limit = this.tagLimit
return tagIDs?.length > limit ? tagIDs.length - (limit - 1) : null
@@ -335,9 +335,13 @@
<a routerLink="/documents/{{d.id}}" title="Edit document" i18n-title style="overflow-wrap: anywhere;">{{d.title | documentTitle}}</a>
}
@if (activeDisplayFields.includes(DisplayField.TAGS)) {
@for (tagID of d.tags | collapseTags | async; track tagID) {
@let tags = d.tags | displayTags | async;
@for (tagID of tags?.visible; track tagID) {
<pngx-tag [tagID]="tagID" [split]="true" class="ms-1 fs-6" clickable="true" linkTitle="Filter by tag" i18n-linkTitle (click)="clickTag(tagID);$event.stopPropagation()" (parentClick)="clickTag($event)"></pngx-tag>
}
@if (tags?.hidden.length) {
<pngx-hidden-tags-badge [count]="tags.hidden.length" class="ms-1 fs-6"></pngx-hidden-tags-badge>
}
}
</td>
}
@@ -1,3 +1,4 @@
import { HiddenTagsBadgeComponent } from 'src/app/components/common/hidden-tags-badge/hidden-tags-badge.component'
import { AsyncPipe, NgClass, NgTemplateOutlet } from '@angular/common'
import {
Component,
@@ -39,7 +40,7 @@ import {
SortableDirective,
SortEvent,
} from 'src/app/directives/sortable.directive'
import { CollapseTagsPipe } from 'src/app/pipes/collapse-tags.pipe'
import { DisplayTagsPipe } from 'src/app/pipes/display-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'
@@ -97,7 +98,8 @@ import { SaveViewConfigDialogComponent } from './save-view-config-dialog/save-vi
StoragePathNamePipe,
BootstrapIconComponent,
AsyncPipe,
CollapseTagsPipe,
DisplayTagsPipe,
HiddenTagsBadgeComponent,
FormsModule,
ReactiveFormsModule,
NgTemplateOutlet,