From 36ac6002cb3218598a12391a16b86285ca415cc1 Mon Sep 17 00:00:00 2001 From: Alexandre Vryghem Date: Tue, 30 Apr 2024 13:48:14 +0200 Subject: [PATCH] 111731: Migrated the renderSearchLabelFor to standalone form --- .../search-label-loader.decorator.ts | 31 +++++++++++-------- .../search-label-range.component.ts | 2 -- .../search-label/search-label.component.ts | 8 ----- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/app/shared/search/search-labels/search-label-loader/search-label-loader.decorator.ts b/src/app/shared/search/search-labels/search-label-loader/search-label-loader.decorator.ts index c37607a4373..7f0d469b6e9 100644 --- a/src/app/shared/search/search-labels/search-label-loader/search-label-loader.decorator.ts +++ b/src/app/shared/search/search-labels/search-label-loader/search-label-loader.decorator.ts @@ -1,18 +1,23 @@ -import { Component } from '@angular/core'; +import { + Component, + Type, +} from '@angular/core'; -import { GenericConstructor } from '../../../../core/shared/generic-constructor'; +import { hasNoValue } from '../../../empty.util'; +import { SearchLabelComponent } from '../search-label/search-label.component'; +import { SearchLabelRangeComponent } from '../search-label-range/search-label-range.component'; -export const map: Map> = new Map(); +export const DEFAULT_LABEL_OPERATOR = undefined; -export function renderSearchLabelFor(operator: string) { - return function decorator(objectElement: any) { - if (!objectElement) { - return; - } - map.set(operator, objectElement); - }; -} +export const LABEL_DECORATOR_MAP: Map> = new Map([ + [DEFAULT_LABEL_OPERATOR, SearchLabelComponent as Type], + ['range', SearchLabelRangeComponent as Type], +]); -export function getSearchLabelByOperator(operator: string): GenericConstructor { - return map.get(operator); +export function getSearchLabelByOperator(operator: string): Type { + const comp: Type = LABEL_DECORATOR_MAP.get(operator); + if (hasNoValue(comp)) { + return LABEL_DECORATOR_MAP.get(DEFAULT_LABEL_OPERATOR); + } + return comp; } diff --git a/src/app/shared/search/search-labels/search-label-range/search-label-range.component.ts b/src/app/shared/search/search-labels/search-label-range/search-label-range.component.ts index f4f886c737b..46a8c1c534b 100644 --- a/src/app/shared/search/search-labels/search-label-range/search-label-range.component.ts +++ b/src/app/shared/search/search-labels/search-label-range/search-label-range.component.ts @@ -21,7 +21,6 @@ import { SearchService } from '../../../../core/shared/search/search.service'; import { SearchConfigurationService } from '../../../../core/shared/search/search-configuration.service'; import { currentPath } from '../../../utils/route.utils'; import { AppliedFilter } from '../../models/applied-filter.model'; -import { renderSearchLabelFor } from '../search-label-loader/search-label-loader.decorator'; /** * Component that represents the label containing the currently active filters @@ -38,7 +37,6 @@ import { renderSearchLabelFor } from '../search-label-loader/search-label-loader TranslateModule, ], }) -@renderSearchLabelFor('range') export class SearchLabelRangeComponent implements OnInit { @Input() inPlaceSearch: boolean; diff --git a/src/app/shared/search/search-labels/search-label/search-label.component.ts b/src/app/shared/search/search-labels/search-label/search-label.component.ts index 490a1475049..7795555c369 100644 --- a/src/app/shared/search/search-labels/search-label/search-label.component.ts +++ b/src/app/shared/search/search-labels/search-label/search-label.component.ts @@ -18,7 +18,6 @@ import { SearchService } from '../../../../core/shared/search/search.service'; import { SearchConfigurationService } from '../../../../core/shared/search/search-configuration.service'; import { currentPath } from '../../../utils/route.utils'; import { AppliedFilter } from '../../models/applied-filter.model'; -import { renderSearchLabelFor } from '../search-label-loader/search-label-loader.decorator'; /** * Component that represents the label containing the currently active filters @@ -30,13 +29,6 @@ import { renderSearchLabelFor } from '../search-label-loader/search-label-loader standalone: true, imports: [RouterLink, AsyncPipe, TranslateModule], }) -@renderSearchLabelFor('equals') -@renderSearchLabelFor('notequals') -@renderSearchLabelFor('authority') -@renderSearchLabelFor('notauthority') -@renderSearchLabelFor('contains') -@renderSearchLabelFor('notcontains') -@renderSearchLabelFor('query') export class SearchLabelComponent implements OnInit { @Input() inPlaceSearch: boolean; @Input() appliedFilter: AppliedFilter;