diff --git a/src-ui/src/app/components/common/tag/tag.component.html b/src-ui/src/app/components/common/tag/tag.component.html
index a7f2de44ce..38a58a6541 100644
--- a/src-ui/src/app/components/common/tag/tag.component.html
+++ b/src-ui/src/app/components/common/tag/tag.component.html
@@ -1,13 +1,18 @@
@if (tag()) {
- @if (showParents() && tag().parent) {
-
- >
- }
- @if (!clickable()) {
- {{tag().name}}
- }
- @if (clickable()) {
- {{tag().name}}
+ @if (ancestorSegments.length) {
+
+ @for (ancestor of ancestorSegments; track ancestor.id; let first = $first) {
+ {{ancestor.name}}
+ }
+ {{tag().name}}
+
+ } @else {
+ @if (!clickable()) {
+ {{tag().name}}
+ }
+ @if (clickable()) {
+ {{tag().name}}
+ }
}
} @else if (loading) {
diff --git a/src-ui/src/app/components/common/tag/tag.component.scss b/src-ui/src/app/components/common/tag/tag.component.scss
index 5dc28b65f2..67167ec301 100644
--- a/src-ui/src/app/components/common/tag/tag.component.scss
+++ b/src-ui/src/app/components/common/tag/tag.component.scss
@@ -11,3 +11,45 @@ a, span {
opacity: .5;
font-style: italic;
}
+
+.split-parent,
+.split-child {
+ overflow: hidden;
+ white-space: nowrap;
+ transition: color .2s ease;
+}
+
+.split-parent {
+ min-width: 1.5em;
+ max-width: 10em;
+ padding-inline: .4em;
+ text-overflow: clip;
+
+ &:nth-last-child(2) { flex-shrink: 1e12; }
+ &:nth-last-child(3) { flex-shrink: 1e18; }
+ &:nth-last-child(4) { flex-shrink: 1e24; }
+ &:nth-last-child(5) { flex-shrink: 1e30; }
+
+ &.collapsed {
+ color: transparent !important;
+ }
+}
+
+.split-child {
+ flex-shrink: 1e6;
+ min-width: 2em;
+ text-overflow: ellipsis;
+}
+
+// Hovered segment gets priority, other parents can shrink to a sliver
+.split-pill {
+ > .split-parent.focused,
+ > .split-child.focused {
+ flex-shrink: 1;
+ text-overflow: ellipsis;
+ }
+
+ &:has(> .focused) > .split-parent:not(.focused) {
+ min-width: 0;
+ }
+}
diff --git a/src-ui/src/app/components/common/tag/tag.component.ts b/src-ui/src/app/components/common/tag/tag.component.ts
index 0cb17ad8e0..5f6d0d9267 100644
--- a/src-ui/src/app/components/common/tag/tag.component.ts
+++ b/src-ui/src/app/components/common/tag/tag.component.ts
@@ -1,11 +1,27 @@
-import { Component, effect, inject, input, model } from '@angular/core'
+import {
+ Component,
+ computed,
+ effect,
+ inject,
+ input,
+ model,
+ output,
+ signal,
+} from '@angular/core'
import { Tag } from 'src/app/data/tag'
+import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
import {
PermissionAction,
PermissionsService,
PermissionType,
} from 'src/app/services/permissions.service'
import { TagService } from 'src/app/services/rest/tag.service'
+import { SettingsService } from 'src/app/services/settings.service'
+import { getTagAncestors } from 'src/app/utils/collapse-tags'
+
+const FOCUS_ANIMATION_MS = 200
+// matches the .split-parent min-width in tag.component.scss
+const COLLAPSE_BELOW_EM = 1.5
@Component({
selector: 'pngx-tag',
@@ -13,8 +29,9 @@ import { TagService } from 'src/app/services/rest/tag.service'
styleUrls: ['./tag.component.scss'],
})
export class TagComponent {
- private permissionsService = inject(PermissionsService)
- private tagService = inject(TagService)
+ private readonly permissionsService = inject(PermissionsService)
+ private readonly tagService = inject(TagService)
+ private readonly settingsService = inject(SettingsService)
readonly tag = model(null)
readonly tagID = input(undefined)
@@ -23,27 +40,101 @@ export class TagComponent {
transform: (value: boolean | string) =>
value === '' || value === true || value === 'true',
})
- readonly showParents = input(false)
+
+ readonly split = input(false)
+
+ readonly parentClick = output()
+
+ private readonly ancestors = signal([])
+
+ public get ancestorSegments(): Tag[] {
+ return this.split() &&
+ this.settingsService.get(SETTINGS_KEYS.TAGS_SHOW_HIERARCHY)
+ ? this.ancestors()
+ : []
+ }
+
+ public readonly path = computed(() =>
+ [...this.ancestors(), this.tag()]
+ .filter(Boolean)
+ .map((t) => t.name)
+ .join(' › ')
+ )
constructor() {
effect(() => {
const tagID = this.tagID()
- if (tagID) {
- if (
- this.permissionsService.currentUserCan(
- PermissionAction.View,
- PermissionType.Tag
- )
- ) {
- this.tagService.getCached(tagID).subscribe((tag) => {
- this.tag.set(tag)
- })
- }
+ if (tagID && this.canViewTags) {
+ this.tagService.getCached(tagID).subscribe((tag) => {
+ this.tag.set(tag)
+ })
}
})
+
+ // ancestors for split badges, from either tagID or a passed-in tag
+ effect(() => {
+ const id = this.tagID() || this.tag()?.id
+ if (!this.split() || !id || !this.canViewTags) {
+ this.ancestors.set([])
+ return
+ }
+ this.tagService.listAll().subscribe((tags) => {
+ this.ancestors.set(
+ getTagAncestors(
+ id,
+ new Map(tags.results.map((t) => [t.id, t]))
+ )
+ )
+ })
+ })
+ }
+
+ private get canViewTags(): boolean {
+ return this.permissionsService.currentUserCan(
+ PermissionAction.View,
+ PermissionType.Tag
+ )
}
public get loading(): boolean {
return this.tagService.loading
}
+
+ /**
+ * Gives the hovered segment priority (.focused class, see scss)
+ * and animates each from old width to new
+ */
+ setFocus(segment: HTMLElement, focused: HTMLElement | null) {
+ const segments = Array.from(segment.children) as HTMLElement[]
+ const before = segments.map((s) => s.getBoundingClientRect().width)
+ for (const segment of segments) {
+ segment.getAnimations().forEach((a) => a.cancel())
+ segment.classList.toggle('focused', segment === focused)
+ }
+ const after = segments.map((s) => s.getBoundingClientRect().width)
+
+ segments.forEach((segment, i) => {
+ const em = Number.parseFloat(getComputedStyle(segment).fontSize)
+ segment.classList.toggle(
+ 'collapsed',
+ !!focused &&
+ segment.classList.contains('split-parent') &&
+ after[i] < COLLAPSE_BELOW_EM * em
+ )
+ if (Math.abs(after[i] - before[i]) < 0.5) return
+ segment.animate(
+ [
+ { flex: `0 0 ${before[i]}px`, minWidth: 0 },
+ { flex: `0 0 ${after[i]}px`, minWidth: 0 },
+ ],
+ { duration: FOCUS_ANIMATION_MS, easing: 'ease' }
+ )
+ })
+ }
+
+ onParentClick(event: MouseEvent, id: number) {
+ event.preventDefault()
+ event.stopImmediatePropagation()
+ this.parentClick.emit(id)
+ }
}