added search-results parent component

This commit is contained in:
2026-07-08 03:27:29 +02:00
parent f469594c17
commit 48e33e7fe5
4 changed files with 521 additions and 0 deletions
@@ -0,0 +1,44 @@
import { Injectable, computed, signal } from '@angular/core';
import { KeywordEntryWithTopic } from '../../../api/model/keywordEntryWithTopic';
export interface SearchResultsPayload {
extractedKeywords: KeywordEntryWithTopic[];
manualKeywords: KeywordEntryWithTopic[];
keywords: string[];
options: {
softSearch: boolean;
};
}
/**
* Provided at the parent route (KeywordsSearchResultsComponent) so it's
* created once when entering /search-results and destroyed when leaving it.
* Child routes (persons/projects/patents) inject it read-only to build
* their own search requests without re-deriving the keyword state.
*/
@Injectable()
export class SearchResultsStateService {
private readonly _payload = signal<SearchResultsPayload | null>(null);
readonly payload = this._payload.asReadonly();
readonly hasValidSearch = computed(() => {
const payload = this._payload();
return !!payload && payload.keywords.length > 0;
});
readonly keywords = computed(() => this._payload()?.keywords ?? []);
readonly softSearch = computed(
() => this._payload()?.options.softSearch ?? false,
);
readonly extractedKeywords = computed(
() => this._payload()?.extractedKeywords ?? [],
);
readonly manualKeywords = computed(
() => this._payload()?.manualKeywords ?? [],
);
setPayload(payload: SearchResultsPayload): void {
this._payload.set(payload);
}
}
@@ -0,0 +1,77 @@
<div class="search-results-page">
<div class="search-results-header">
<button mat-stroked-button color="primary" (click)="goBackToSearch()">
<mat-icon>arrow_back</mat-icon>
Keywords anpassen
</button>
</div>
@if (state.hasValidSearch()) {
<mat-card class="summary-card">
<mat-card-content>
<div class="summary-header">
<div>
<span class="summary-label">Suchprofil</span>
<span class="summary-count"
>{{ selectedKeywordCount() }} Keywords</span
>
</div>
<span class="mode-badge">
<mat-icon>account_tree</mat-icon>
{{ state.softSearch() ? 'Topic Mapping' : 'Keyword Matching' }}
</span>
</div>
<div class="keyword-stack">
@for (entry of selectedKeywordEntries(); track getEntryTrack(entry)) {
<app-topic-chip
[label]="getChipLabel(entry)"
[count]="getChipCount(entry)"
[description]="getChipDescription(entry)"
[subfieldName]="getChipSubfieldName(entry)"
[fieldName]="getChipFieldName(entry)"
[domainName]="getChipDomainName(entry)"
[color]="getTopicColor(entry.topic_mapping?.topic)"
[active]="true"
countIcon="article"
descriptionTooltipTarget="button" />
}
@for (keyword of missingKeywordLabels(); track keyword) {
<app-topic-chip
[label]="keyword"
[active]="true"
countIcon="article" />
}
</div>
</mat-card-content>
</mat-card>
<nav mat-tab-nav-bar [tabPanel]="resultTabPanel" class="result-nav">
@for (route of childRoutes; track route.path) {
<a
mat-tab-link
[routerLink]="route.path"
routerLinkActive
#rla="routerLinkActive"
[active]="rla.isActive">
<mat-icon>{{ route.icon }}</mat-icon>
{{ route.label }}
</a>
}
</nav>
<mat-tab-nav-panel #resultTabPanel>
<router-outlet />
</mat-tab-nav-panel>
} @else {
<mat-card class="empty-card">
<mat-card-content class="empty-state">
<mat-icon>manage_search</mat-icon>
<h2>Keine Suchdaten</h2>
<p>Starte eine neue Suche, um Ergebnisse zu sehen.</p>
<button mat-flat-button color="primary" (click)="goBackToSearch()">
Zur Suche
</button>
</mat-card-content>
</mat-card>
}
</div>
@@ -0,0 +1,209 @@
/* ============================================================
DESIGN TOKENS
============================================================ */
$phone: 599px;
$tablet: 900px;
$touch-target: 44px;
/* ============================================================
SEARCH RESULTS PAGE (parent shell)
============================================================ */
.search-results-page {
display: flex;
flex-direction: column;
gap: 0.75rem;
padding: 0.75rem 1rem;
}
.page-header {
display: flex;
align-items: flex-start;
gap: 0.75rem;
h1 {
margin: 0;
font-size: clamp(1.2rem, 2vw, 1.6rem);
font-weight: 650;
color: var(--sg-text-primary);
}
p {
margin: 0.2rem 0 0;
color: var(--sg-text-secondary);
font-size: 0.9rem;
}
}
/* ============================================================
KEYWORD SUMMARY CARD
============================================================ */
.summary-card {
background: var(--sg-surface, #ffffff);
border: 1px solid var(--sg-divider, rgba(0, 0, 0, 0.12));
box-shadow: none;
.mat-mdc-card-content {
padding: 0.75rem;
}
}
.summary-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 0.5rem;
margin-bottom: 0.5rem;
}
.summary-label {
display: block;
font-size: 0.75rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.03em;
color: var(--sg-text-secondary);
}
.summary-count {
display: block;
margin-top: 0.15rem;
font-size: 0.95rem;
font-weight: 650;
color: var(--sg-text-primary);
}
.mode-badge {
display: inline-flex;
align-items: center;
gap: 0.25rem;
border-radius: 999px;
padding: 0.25rem 0.5rem;
background: var(--sg-background-muted, #f4f5f7);
color: var(--sg-text-secondary);
font-size: 0.75rem;
font-weight: 500;
mat-icon {
font-size: 16px;
width: 16px;
height: 16px;
}
}
.keyword-stack {
display: flex;
flex-wrap: wrap;
gap: 0.6rem;
::ng-deep app-topic-chip .topic-chip__count {
display: none;
}
}
/* ============================================================
CHILD ROUTE NAV
============================================================ */
.result-nav {
display: flex;
gap: 0.25rem;
border-bottom: 1px solid var(--sg-divider, rgba(0, 0, 0, 0.12));
}
.result-nav__link {
display: inline-flex;
align-items: center;
gap: 0.35rem;
padding: 0.5rem 0.85rem;
border-radius: 6px 6px 0 0;
color: var(--sg-text-secondary);
text-decoration: none;
font-size: 0.85rem;
font-weight: 500;
border-bottom: 2px solid transparent;
transition:
color 0.15s ease,
border-color 0.15s ease;
mat-icon {
font-size: 18px;
width: 18px;
height: 18px;
}
&:hover {
color: var(--sg-text-primary);
}
&--active {
color: var(--sg-text-primary);
border-bottom-color: var(--sg-primary, currentColor);
}
}
/* ============================================================
EMPTY STATE
============================================================ */
.empty-card {
background: var(--sg-surface, #ffffff);
border: 1px solid var(--sg-divider, rgba(0, 0, 0, 0.12));
box-shadow: none;
}
.empty-state {
min-height: 240px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 0.5rem;
text-align: center;
color: var(--sg-text-secondary);
mat-icon {
font-size: 48px;
width: 48px;
height: 48px;
opacity: 0.65;
}
h2 {
margin: 0;
color: var(--sg-text-primary);
font-size: 1.1rem;
}
p {
margin: 0;
max-width: 480px;
line-height: 1.4;
}
button {
margin-top: 0.5rem;
min-height: $touch-target;
}
}
/* ============================================================
PHONE
============================================================ */
@media (max-width: $phone) {
.search-results-page {
padding: 0.5rem;
}
.summary-header {
flex-direction: column;
align-items: flex-start;
gap: 0.3rem;
}
.mode-badge {
width: 100%;
justify-content: center;
}
.result-nav {
overflow-x: auto;
}
}
@@ -0,0 +1,191 @@
import { Component, computed, inject } from '@angular/core';
import {
Router,
RouterLink,
RouterLinkActive,
RouterOutlet,
} from '@angular/router';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { MatIconModule } from '@angular/material/icon';
import { KeywordEntryWithTopic } from '../../../api/model/keywordEntryWithTopic';
import { Topic } from '../../../api/model/topic';
import { TopicChipComponent } from '../../../shared/ui/topic-chip/topic-chip.component';
import {
topicHierarchyColor,
TopicHierarchyColorInput,
} from '../../../resolvers/utils/topic-colors';
import { MatTabsModule } from '@angular/material/tabs';
import {
SearchResultsPayload,
SearchResultsStateService,
} from './search-results-state.service';
@Component({
selector: 'app-keywords-search-results',
standalone: true,
imports: [
RouterLink,
RouterLinkActive,
RouterOutlet,
MatButtonModule,
MatCardModule,
MatIconModule,
TopicChipComponent,
MatTabsModule,
],
// Scoped to this component's route subtree: created on entering /results,
// destroyed on leaving it entirely — survives switching persons/projects/patents.
providers: [SearchResultsStateService],
templateUrl: './search-results.component.html',
styleUrl: './search-results.component.scss',
})
export class KeywordsSearchResultsComponent {
private readonly router = inject(Router);
protected readonly state = inject(SearchResultsStateService);
protected readonly childRoutes = [
{ path: 'persons', label: 'Personen', icon: 'groups' },
{ path: 'projects', label: 'Projekte', icon: 'account_tree' },
{ path: 'patents', label: 'Patente', icon: 'workspace_premium' },
];
readonly selectedKeywordCount = computed(() => this.state.keywords().length);
readonly selectedKeywordEntries = computed(() => {
const payload = this.state.payload();
if (!payload) return [];
const allEntries = [
...(payload.extractedKeywords ?? []),
...(payload.manualKeywords ?? []),
];
const entryByKeyword = new Map<string, KeywordEntryWithTopic>();
for (const entry of allEntries) {
entryByKeyword.set(
this.normalizeKeyword(this.getKeywordLabel(entry)),
entry,
);
}
const result: KeywordEntryWithTopic[] = [];
const seen = new Set<string>();
for (const keyword of payload.keywords) {
const normalized = this.normalizeKeyword(keyword);
const entry = entryByKeyword.get(normalized);
if (!entry || seen.has(normalized)) continue;
seen.add(normalized);
result.push(entry);
}
return result;
});
readonly missingKeywordLabels = computed(() => {
const payload = this.state.payload();
if (!payload) return [];
const entryKeywordSet = new Set(
this.selectedKeywordEntries().map((entry) =>
this.normalizeKeyword(this.getKeywordLabel(entry)),
),
);
return payload.keywords.filter(
(keyword) => !entryKeywordSet.has(this.normalizeKeyword(keyword)),
);
});
constructor() {
const navigationState =
this.router.currentNavigation()?.extras.state ?? window.history.state;
const restoredPayload = this.parsePayload(navigationState);
if (restoredPayload) {
this.state.setPayload(restoredPayload);
}
}
goBackToSearch(): void {
void this.router.navigate(['/keywords']);
}
getChipLabel(keyword: KeywordEntryWithTopic): string {
return keyword.llm_keyword?.keyword ?? '';
}
getChipDescription(item: KeywordEntryWithTopic): string | null {
return this.getTopic(item)?.description ?? null;
}
getChipSubfieldName(item: KeywordEntryWithTopic): string | null {
return this.getTopic(item)?.subfield?.display_name ?? null;
}
getChipFieldName(item: KeywordEntryWithTopic): string | null {
return this.getTopic(item)?.field?.display_name ?? null;
}
getChipDomainName(item: KeywordEntryWithTopic): string | null {
return this.getTopic(item)?.domain?.display_name ?? null;
}
getChipCount(item: KeywordEntryWithTopic): number | null {
return this.getTopic(item)?.works_count ?? null;
}
getTopicColor(topic: Topic | undefined | null): string {
const topicInput: TopicHierarchyColorInput = {
id: topic?.id ?? null,
name: topic?.display_name ?? null,
field_id: topic?.field?.id ?? null,
field_name: topic?.field?.display_name ?? null,
domain_id: topic?.domain?.id ?? null,
domain_name: topic?.domain?.display_name ?? null,
};
return topicHierarchyColor(topicInput);
}
getEntryTrack(entry: KeywordEntryWithTopic): string {
return this.getKeywordLabel(entry);
}
private parsePayload(value: unknown): SearchResultsPayload | null {
if (!value || typeof value !== 'object') return null;
const maybePayload = value as Partial<SearchResultsPayload>;
if (!Array.isArray(maybePayload.keywords)) return null;
return {
extractedKeywords: maybePayload.extractedKeywords ?? [],
manualKeywords: maybePayload.manualKeywords ?? [],
keywords: maybePayload.keywords ?? [],
options: {
softSearch: maybePayload.options?.softSearch ?? false,
},
};
}
private getKeywordLabel(item: KeywordEntryWithTopic): string {
return item.llm_keyword.keyword;
}
private getTopic(item: KeywordEntryWithTopic): Topic | null {
return item.topic_mapping?.topic ?? null;
}
private normalizeKeyword(value: string): string {
return value.trim().toLowerCase();
}
}