Skip to content

Commit 36ac600

Browse files
111731: Migrated the renderSearchLabelFor to standalone form
1 parent f40a68f commit 36ac600

3 files changed

Lines changed: 18 additions & 23 deletions

File tree

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
import { Component } from '@angular/core';
1+
import {
2+
Component,
3+
Type,
4+
} from '@angular/core';
25

3-
import { GenericConstructor } from '../../../../core/shared/generic-constructor';
6+
import { hasNoValue } from '../../../empty.util';
7+
import { SearchLabelComponent } from '../search-label/search-label.component';
8+
import { SearchLabelRangeComponent } from '../search-label-range/search-label-range.component';
49

5-
export const map: Map<string, GenericConstructor<Component>> = new Map();
10+
export const DEFAULT_LABEL_OPERATOR = undefined;
611

7-
export function renderSearchLabelFor(operator: string) {
8-
return function decorator(objectElement: any) {
9-
if (!objectElement) {
10-
return;
11-
}
12-
map.set(operator, objectElement);
13-
};
14-
}
12+
export const LABEL_DECORATOR_MAP: Map<string, Type<Component>> = new Map([
13+
[DEFAULT_LABEL_OPERATOR, SearchLabelComponent as Type<Component>],
14+
['range', SearchLabelRangeComponent as Type<Component>],
15+
]);
1516

16-
export function getSearchLabelByOperator(operator: string): GenericConstructor<Component> {
17-
return map.get(operator);
17+
export function getSearchLabelByOperator(operator: string): Type<Component> {
18+
const comp: Type<Component> = LABEL_DECORATOR_MAP.get(operator);
19+
if (hasNoValue(comp)) {
20+
return LABEL_DECORATOR_MAP.get(DEFAULT_LABEL_OPERATOR);
21+
}
22+
return comp;
1823
}

src/app/shared/search/search-labels/search-label-range/search-label-range.component.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { SearchService } from '../../../../core/shared/search/search.service';
2121
import { SearchConfigurationService } from '../../../../core/shared/search/search-configuration.service';
2222
import { currentPath } from '../../../utils/route.utils';
2323
import { AppliedFilter } from '../../models/applied-filter.model';
24-
import { renderSearchLabelFor } from '../search-label-loader/search-label-loader.decorator';
2524

2625
/**
2726
* Component that represents the label containing the currently active filters
@@ -38,7 +37,6 @@ import { renderSearchLabelFor } from '../search-label-loader/search-label-loader
3837
TranslateModule,
3938
],
4039
})
41-
@renderSearchLabelFor('range')
4240
export class SearchLabelRangeComponent implements OnInit {
4341

4442
@Input() inPlaceSearch: boolean;

src/app/shared/search/search-labels/search-label/search-label.component.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { SearchService } from '../../../../core/shared/search/search.service';
1818
import { SearchConfigurationService } from '../../../../core/shared/search/search-configuration.service';
1919
import { currentPath } from '../../../utils/route.utils';
2020
import { AppliedFilter } from '../../models/applied-filter.model';
21-
import { renderSearchLabelFor } from '../search-label-loader/search-label-loader.decorator';
2221

2322
/**
2423
* Component that represents the label containing the currently active filters
@@ -30,13 +29,6 @@ import { renderSearchLabelFor } from '../search-label-loader/search-label-loader
3029
standalone: true,
3130
imports: [RouterLink, AsyncPipe, TranslateModule],
3231
})
33-
@renderSearchLabelFor('equals')
34-
@renderSearchLabelFor('notequals')
35-
@renderSearchLabelFor('authority')
36-
@renderSearchLabelFor('notauthority')
37-
@renderSearchLabelFor('contains')
38-
@renderSearchLabelFor('notcontains')
39-
@renderSearchLabelFor('query')
4032
export class SearchLabelComponent implements OnInit {
4133
@Input() inPlaceSearch: boolean;
4234
@Input() appliedFilter: AppliedFilter;

0 commit comments

Comments
 (0)