topic-legend: select fields and subfields separately

This commit is contained in:
2026-06-26 14:16:56 +02:00
parent 512356e106
commit f2cf83f63b
5 changed files with 72 additions and 22 deletions
@@ -47,7 +47,7 @@
<div
*ngFor="let group of visibleGroups; trackBy: trackByGroup"
class="topic-legend-group"
[class.topic-legend-group-active]="isGroupActive(group)"
[class.topic-legend-group-active]="isFieldActive(group)"
[style.--legend-color]="group.color">
<button
type="button"
@@ -21,7 +21,7 @@ export class TopicLegendComponent {
@Input() groups: TopicLegendGroup[] = [];
@Input() title = 'Farben nach Fachgebiet';
@Input() infoTooltip =
'Fachgebiete bestimmen die Farbe. Themenbereiche werden darunter gruppiert.';
'Fachgebiete bestimmen die Farbe. Themenbereiche werden darunter gruppiert. Fachgebiete oder Themenbereiche können angeklickt werden, um die passenden Themen zu markieren.';
@Input() visible = true;
@Input() expanded = false;
@Input() showTitle = true;
@@ -99,13 +99,6 @@ export class TopicLegendComponent {
return this.isActiveLegendId(this.activeSubfieldIds, item.id);
}
isGroupActive(group: TopicLegendGroup): boolean {
return (
this.isFieldActive(group) ||
group.items.some((item) => this.isSubfieldActive(item))
);
}
trackByGroup(_: number, group: TopicLegendGroup): string {
return group.id;
}
@@ -31,6 +31,11 @@ export interface TopicLegendSubfieldSelection {
item: TopicLegendItem;
}
export interface TopicLegendSelectionState {
fieldIds: Set<string>;
subfieldIds: Set<string>;
}
export function getTopicLegendFieldId(topic: TopicLegendTopic): string {
const fieldName = normalizeLegendValue(topic.field_name) ?? 'Ohne Fachgebiet';
@@ -60,6 +65,41 @@ export function toggleTopicLegendSelection(
return nextSelection;
}
export function toggleTopicLegendFieldSelection(
currentFieldIds: ReadonlySet<string>,
currentSubfieldIds: ReadonlySet<string>,
group: TopicLegendGroup,
): TopicLegendSelectionState {
const fieldIds = toggleTopicLegendSelection(currentFieldIds, group.id);
const subfieldIds = new Set(currentSubfieldIds);
if (fieldIds.has(group.id)) {
for (const item of group.items) {
subfieldIds.delete(item.id);
}
}
return { fieldIds, subfieldIds };
}
export function toggleTopicLegendSubfieldSelection(
currentFieldIds: ReadonlySet<string>,
currentSubfieldIds: ReadonlySet<string>,
selection: TopicLegendSubfieldSelection,
): TopicLegendSelectionState {
const fieldIds = new Set(currentFieldIds);
const subfieldIds = toggleTopicLegendSelection(
currentSubfieldIds,
selection.item.id,
);
if (subfieldIds.has(selection.item.id)) {
fieldIds.delete(selection.group.id);
}
return { fieldIds, subfieldIds };
}
export function buildTopicLegendGroups(
topics: readonly TopicLegendTopic[],
): TopicLegendGroup[] {