111731: Migrated the renderSearchLabelFor to standalone form

This commit is contained in:
Alexandre Vryghem
2024-04-30 13:48:14 +02:00
parent f40a68f05e
commit 36ac6002cb
3 changed files with 19 additions and 24 deletions

View File

@@ -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<string, GenericConstructor<Component>> = new Map(); export const DEFAULT_LABEL_OPERATOR = undefined;
export function renderSearchLabelFor(operator: string) { export const LABEL_DECORATOR_MAP: Map<string, Type<Component>> = new Map([
return function decorator(objectElement: any) { [DEFAULT_LABEL_OPERATOR, SearchLabelComponent as Type<Component>],
if (!objectElement) { ['range', SearchLabelRangeComponent as Type<Component>],
return; ]);
export function getSearchLabelByOperator(operator: string): Type<Component> {
const comp: Type<Component> = LABEL_DECORATOR_MAP.get(operator);
if (hasNoValue(comp)) {
return LABEL_DECORATOR_MAP.get(DEFAULT_LABEL_OPERATOR);
} }
map.set(operator, objectElement); return comp;
};
}
export function getSearchLabelByOperator(operator: string): GenericConstructor<Component> {
return map.get(operator);
} }

View File

@@ -21,7 +21,6 @@ import { SearchService } from '../../../../core/shared/search/search.service';
import { SearchConfigurationService } from '../../../../core/shared/search/search-configuration.service'; import { SearchConfigurationService } from '../../../../core/shared/search/search-configuration.service';
import { currentPath } from '../../../utils/route.utils'; import { currentPath } from '../../../utils/route.utils';
import { AppliedFilter } from '../../models/applied-filter.model'; 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 * Component that represents the label containing the currently active filters
@@ -38,7 +37,6 @@ import { renderSearchLabelFor } from '../search-label-loader/search-label-loader
TranslateModule, TranslateModule,
], ],
}) })
@renderSearchLabelFor('range')
export class SearchLabelRangeComponent implements OnInit { export class SearchLabelRangeComponent implements OnInit {
@Input() inPlaceSearch: boolean; @Input() inPlaceSearch: boolean;

View File

@@ -18,7 +18,6 @@ import { SearchService } from '../../../../core/shared/search/search.service';
import { SearchConfigurationService } from '../../../../core/shared/search/search-configuration.service'; import { SearchConfigurationService } from '../../../../core/shared/search/search-configuration.service';
import { currentPath } from '../../../utils/route.utils'; import { currentPath } from '../../../utils/route.utils';
import { AppliedFilter } from '../../models/applied-filter.model'; 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 * 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, standalone: true,
imports: [RouterLink, AsyncPipe, TranslateModule], imports: [RouterLink, AsyncPipe, TranslateModule],
}) })
@renderSearchLabelFor('equals')
@renderSearchLabelFor('notequals')
@renderSearchLabelFor('authority')
@renderSearchLabelFor('notauthority')
@renderSearchLabelFor('contains')
@renderSearchLabelFor('notcontains')
@renderSearchLabelFor('query')
export class SearchLabelComponent implements OnInit { export class SearchLabelComponent implements OnInit {
@Input() inPlaceSearch: boolean; @Input() inPlaceSearch: boolean;
@Input() appliedFilter: AppliedFilter; @Input() appliedFilter: AppliedFilter;