diff --git a/src-ui/src/app/components/common/input/tags/tags.component.scss b/src-ui/src/app/components/common/input/tags/tags.component.scss
index 94da626994..ebeffbfdd3 100644
--- a/src-ui/src/app/components/common/input/tags/tags.component.scss
+++ b/src-ui/src/app/components/common/input/tags/tags.component.scss
@@ -7,6 +7,11 @@
font-size: 1rem;
}
+// ancestors of another selected tag render inside that tag's badge
+::ng-deep .paperless-input-tags .ng-value:has(> .implied-tag) {
+ display: none !important;
+}
+
.paperless-input-select.disabled {
.input-group {
cursor: not-allowed;
diff --git a/src-ui/src/app/components/common/input/tags/tags.component.ts b/src-ui/src/app/components/common/input/tags/tags.component.ts
index b0db1f3d3a..97305d495a 100644
--- a/src-ui/src/app/components/common/input/tags/tags.component.ts
+++ b/src-ui/src/app/components/common/input/tags/tags.component.ts
@@ -21,7 +21,13 @@ import { NgSelectComponent, NgSelectModule } from '@ng-select/ng-select'
import { first, firstValueFrom, tap } from 'rxjs'
import { BootstrapIconComponent } from 'src/app/components/common/bootstrap-icon/bootstrap-icon.component'
import { Tag } from 'src/app/data/tag'
+import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
import { TagService } from 'src/app/services/rest/tag.service'
+import { SettingsService } from 'src/app/services/settings.service'
+import {
+ collapseImpliedAncestors,
+ getTagAncestors,
+} from 'src/app/utils/collapse-tags'
import { matchesSearchText } from 'src/app/utils/text-search'
import { EditDialogMode } from '../../edit-dialog/edit-dialog.component'
import { TagEditDialogComponent } from '../../edit-dialog/tag-edit-dialog/tag-edit-dialog.component'
@@ -50,6 +56,7 @@ import { TagComponent } from '../../tag/tag.component'
export class TagsComponent implements OnInit, ControlValueAccessor {
private tagService = inject(TagService)
private modalService = inject(NgbModal)
+ private readonly settingsService = inject(SettingsService)
private readonly changeDetector = inject(ChangeDetectorRef)
constructor() {
@@ -131,6 +138,21 @@ export class TagsComponent implements OnInit, ControlValueAccessor {
term
)
+ /**
+ * Selected tags that are ancestors of another selected tag which are shown
+ * as segments of their descendant's badge.
+ */
+ isImplied(id: number): boolean {
+ if (
+ !this.preserveHierarchy ||
+ !this.tags ||
+ !this.value ||
+ !this.settingsService.get(SETTINGS_KEYS.TAGS_SHOW_HIERARCHY)
+ )
+ return false
+ return !collapseImpliedAncestors(this.value, this.tagsById).includes(id)
+ }
+
getTag(id: number) {
if (this.tags) {
return this.tags.find((tag) => tag.id == id)
@@ -235,18 +257,17 @@ export class TagsComponent implements OnInit, ControlValueAccessor {
}
getParentChain(id: number): Tag[] {
- // Returns ancestors from root → immediate parent for a tag id
- const chain: Tag[] = []
- let current = this.getTag(id)
- const guard = new Set()
- while (current?.parent) {
- if (guard.has(current.parent)) break
- guard.add(current.parent)
- const parent = this.getTag(current.parent)
- if (!parent) break
- chain.unshift(parent)
- current = parent
+ return getTagAncestors(id, this.tagsById)
+ }
+
+ private tagsByIdSource: Tag[]
+ private tagsByIdCache: Map
+
+ private get tagsById(): Map {
+ if (this.tagsByIdSource !== this.tags) {
+ this.tagsByIdSource = this.tags
+ this.tagsByIdCache = new Map(this.tags?.map((t) => [t.id, t]))
}
- return chain
+ return this.tagsByIdCache
}
}