Skip to content

Commit

Permalink
111731: Migrated the renderSearchLabelFor to standalone form
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrevryghem committed Apr 30, 2024
1 parent f40a68f commit 36ac600
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -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) {
return function decorator(objectElement: any) {
if (!objectElement) {
return;
}
map.set(operator, objectElement);
};
}
export const LABEL_DECORATOR_MAP: Map<string, Type<Component>> = new Map([
[DEFAULT_LABEL_OPERATOR, SearchLabelComponent as Type<Component>],
['range', SearchLabelRangeComponent as Type<Component>],
]);

export function getSearchLabelByOperator(operator: string): GenericConstructor<Component> {
return map.get(operator);
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);
}
return comp;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,7 +37,6 @@ import { renderSearchLabelFor } from '../search-label-loader/search-label-loader
TranslateModule,
],
})
@renderSearchLabelFor('range')
export class SearchLabelRangeComponent implements OnInit {

@Input() inPlaceSearch: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 36ac600

Please sign in to comment.