feat(person-overview): add secondary action to tooltips in 'person interesting' section
LocationBasedServices/smartguide/pipeline/head This commit looks good
LocationBasedServices/smartguide/pipeline/pr-dev Build queued...

This commit is contained in:
2026-08-17 14:04:12 +02:00
parent ce218cbfa1
commit a8db8194cf
5 changed files with 147 additions and 1 deletions
@@ -45,6 +45,7 @@ export class ComponentTooltipDirective<T extends object> implements OnDestroy {
private componentRef: ComponentRef<T> | null = null;
private showTimeout?: ReturnType<typeof setTimeout>;
private hideTimeout?: ReturnType<typeof setTimeout>;
private dismissTimeout?: ReturnType<typeof setTimeout>;
private isOverHost = false;
private isOverOverlay = false;
@@ -84,6 +85,24 @@ export class ComponentTooltipDirective<T extends object> implements OnDestroy {
this.scheduleHide();
}
@HostListener('click')
onHostClick(): void {
this.scheduleDismiss();
}
private scheduleDismiss(): void {
clearTimeout(this.dismissTimeout);
this.dismissTimeout = setTimeout(() => this.dismiss());
}
private dismiss(): void {
clearTimeout(this.showTimeout);
clearTimeout(this.hideTimeout);
this.isOverHost = false;
this.isOverOverlay = false;
this.hide();
}
private scheduleHide(): void {
this.hideTimeout = setTimeout(() => {
if (!this.isOverHost && !this.isOverOverlay) {
@@ -155,6 +174,7 @@ export class ComponentTooltipDirective<T extends object> implements OnDestroy {
overlayElement.addEventListener('mouseenter', this.onOverlayEnter);
overlayElement.addEventListener('mouseleave', this.onOverlayLeave);
overlayElement.addEventListener('click', this.onOverlayClick, true);
}
private applyMaxWidth(
@@ -179,11 +199,16 @@ export class ComponentTooltipDirective<T extends object> implements OnDestroy {
this.scheduleHide();
};
private readonly onOverlayClick = (): void => {
this.scheduleDismiss();
};
private hide(): void {
if (this.overlayRef) {
const overlayElement = this.overlayRef.overlayElement;
overlayElement.removeEventListener('mouseenter', this.onOverlayEnter);
overlayElement.removeEventListener('mouseleave', this.onOverlayLeave);
overlayElement.removeEventListener('click', this.onOverlayClick, true);
this.overlayRef.detach();
}
this.componentRef = null;
@@ -192,6 +217,7 @@ export class ComponentTooltipDirective<T extends object> implements OnDestroy {
ngOnDestroy(): void {
clearTimeout(this.showTimeout);
clearTimeout(this.hideTimeout);
clearTimeout(this.dismissTimeout);
this.overlayRef?.dispose();
}
}
@@ -44,6 +44,9 @@
[color]="tag.color"
[disabled]="!tag.id"
[active]="isTagActive(tag)"
[secondaryActionLabel]="tagAction(tag)?.label ?? null"
[secondaryActionLink]="tagAction(tag)?.link ?? null"
[secondaryActionQueryParams]="tagAction(tag)?.queryParams ?? null"
countIcon="article"
descriptionTooltipTarget="button"
(chipClick)="onTagClick(tag)">
@@ -14,6 +14,7 @@ import { CommonModule } from '@angular/common';
import { ActivatedRoute, Router } from '@angular/router';
import { TopicCount } from '../../api';
import { workQueryParamKeys } from '../../resolvers/work-page.resolver';
import { TopicChipComponent } from '../../shared/ui/topic-chip/topic-chip.component';
import { TopicLegendComponent } from '../../shared/ui/topic-legend/topic-legend.component';
import { LoadingComponent } from '../../shared/ui/loading/loading.component';
@@ -45,6 +46,12 @@ interface InterestTag {
domainDescription: string;
}
interface InterestTagAction {
label: string;
link: unknown[];
queryParams: Record<string, string | number>;
}
const MAX_TAGS = 5;
@Component({
@@ -69,6 +76,10 @@ export class PersonInterestingComponent implements OnInit {
readonly topics = input<TopicCount[] | null>(null);
readonly loading = input<boolean>(false);
readonly personPublicationsLink = input<unknown[] | null>(null);
readonly personName = input<string>('');
readonly legendExpanded = signal(false);
readonly activeLegendFieldIds = signal<ReadonlySet<string>>(new Set());
readonly activeLegendSubfieldIds = signal<ReadonlySet<string>>(new Set());
@@ -142,6 +153,36 @@ export class PersonInterestingComponent implements OnInit {
});
}
private readonly tagActions = computed(() => {
const actions = new Map<string, InterestTagAction>();
const link = this.personPublicationsLink();
if (!link) {
return actions;
}
const person = this.personName() || 'dieser Person';
for (const tag of this.tags()) {
if (!tag.id) continue;
actions.set(tag.id, {
label: `Publikationen von ${person}`,
link,
queryParams: {
[workQueryParamKeys.page]: 0,
[workQueryParamKeys.topicId]: tag.id,
},
});
}
return actions;
});
tagAction(tag: InterestTag): InterestTagAction | null {
return this.tagActions().get(tag.id) ?? null;
}
onTagClick(tag: InterestTag): void {
if (!tag.id) return;
this.tagClick.emit({
@@ -130,6 +130,8 @@
<app-person-interesting
[topics]="primaryTopicCounts()"
[loading]="isTopicsLoading()"
[personName]="personName()"
[personPublicationsLink]="personPublicationsLink()"
(tagClick)="onInterestingTagClick($event)"></app-person-interesting>
</section>
@if (this.links()) {
@@ -5,6 +5,7 @@ import {
inject,
signal,
DestroyRef,
ElementRef,
input,
viewChild,
} from '@angular/core';
@@ -18,11 +19,20 @@ import { MatTabsModule } from '@angular/material/tabs';
import { MatTooltipModule } from '@angular/material/tooltip';
import {
ActivatedRoute,
NavigationEnd,
Router,
RouterModule,
RouterOutlet,
} from '@angular/router';
import { of, switchMap, finalize, map, catchError, combineLatest } from 'rxjs';
import {
of,
switchMap,
finalize,
map,
catchError,
combineLatest,
filter,
} from 'rxjs';
import { PersonInterestingComponent } from '../person-interesting/person-interesting.component';
import { CountryFlagComponent } from '../../shared/ui/country-flag/country-flag.component';
@@ -82,11 +92,28 @@ export class PersonComponent {
() => this.navBar()?.activeLink() ?? null,
);
private readonly tabPanelElement = viewChild('tabPanel', {
read: ElementRef,
});
private publicationFilterKey: string | null = null;
constructor() {
this.bookmarkService
.load()
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe();
this.router.events
.pipe(
filter(
(event): event is NavigationEnd => event instanceof NavigationEnd,
),
takeUntilDestroyed(this.destroyRef),
)
.subscribe((event) =>
this.scrollToPanelOnFilterChange(event.urlAfterRedirects),
);
}
readonly params = toSignal(this.activatedRoute.paramMap);
@@ -169,6 +196,13 @@ export class PersonComponent {
readonly displayName = computed(
() => this.person()?.display_name ?? 'Unbekannte Person',
);
readonly personName = computed(() => this.person()?.display_name ?? '');
readonly personPublicationsLink = computed<unknown[] | null>(() => {
const authorId = this.authorId();
return authorId ? ['/person', authorId, 'publications'] : null;
});
readonly initials = computed(() => this.buildInitials(this.displayName()));
readonly primaryAffiliation = computed(
() => this.person()?.affiliations?.[0] ?? null,
@@ -368,6 +402,46 @@ export class PersonComponent {
});
}
private scrollToPanelOnFilterChange(url: string): void {
const { queryParams } = this.router.parseUrl(url);
const filterKey = [workQueryParamKeys.topicId, workQueryParamKeys.years]
.map((key) => {
const value = queryParams[key];
return Array.isArray(value) ? value.join(',') : (value ?? '');
})
.join('|');
const previousFilterKey = this.publicationFilterKey;
this.publicationFilterKey = filterKey;
const hasFilter = filterKey !== '|';
const isFirstNavigation = previousFilterKey === null;
if (isFirstNavigation || !hasFilter || filterKey === previousFilterKey) {
return;
}
this.scrollPanelIntoView();
}
private scrollPanelIntoView(): void {
const scrollToPanel = (): void => {
this.tabPanelElement()?.nativeElement.scrollIntoView({
behavior: 'smooth',
block: 'start',
});
};
requestAnimationFrame(scrollToPanel);
setTimeout(() => {
const panel = this.tabPanelElement();
if (panel && panel.nativeElement.getBoundingClientRect().top > 8) {
scrollToPanel();
}
}, 400);
}
private getId(key: string): string | null {
const ids = this.person()?.ids as Record<string, string> | undefined;
if (!ids) {