diff --git a/src/app/shared/search/search-labels/search-label-loader/search-label-loader.component.ts b/src/app/shared/search/search-labels/search-label-loader/search-label-loader.component.ts index 763dc1b032..f4682ecee9 100644 --- a/src/app/shared/search/search-labels/search-label-loader/search-label-loader.component.ts +++ b/src/app/shared/search/search-labels/search-label-loader/search-label-loader.component.ts @@ -1,6 +1,5 @@ -import { Component, ComponentRef, OnChanges, OnDestroy, OnInit, ViewChild, ViewContainerRef, SimpleChanges, Input } from '@angular/core'; +import { Component, ComponentRef, OnChanges, OnDestroy, OnInit, ViewChild, ViewContainerRef, SimpleChanges, Input, Type } from '@angular/core'; import { Subscription } from 'rxjs'; -import { GenericConstructor } from 'src/app/core/shared/generic-constructor'; import { hasValue, isNotEmpty } from 'src/app/shared/empty.util'; import { ThemeService } from '../../../theme-support/theme.service'; import { SearchLabelLoaderDirective } from './search-label-loader-directive.directive'; @@ -85,7 +84,7 @@ export class SearchLabelLoaderComponent implements OnInit, OnChanges, OnDestroy * Creates the component and connects the @Input() & @Output() from the ThemedComponent to its child Component. */ public instantiateComponent(): void { - const component: GenericConstructor = this.getComponent(); + const component: Type = this.getComponent(); const viewContainerRef: ViewContainerRef = this.componentDirective.viewContainerRef; viewContainerRef.clear(); @@ -113,8 +112,8 @@ export class SearchLabelLoaderComponent implements OnInit, OnChanges, OnDestroy /** * Fetch the component depending on the item's entity type, metadata representation type and context */ - public getComponent(): GenericConstructor { - return getSearchLabelByOperator(this.appliedFilter.operator); + public getComponent(): Type { + return getSearchLabelByOperator(this.appliedFilter.operator, this.themeService.getThemeName()); } /** 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 ffd73af6ba..5315d83479 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,17 +1,35 @@ -import { Component } from '@angular/core'; -import { GenericConstructor } from '../../../../core/shared/generic-constructor'; +import { Component, Type } from '@angular/core'; +import { DEFAULT_THEME } from '../../../object-collection/shared/listable-object/listable-object.decorator'; +import { hasNoValue } from '../../../empty.util'; -export const map: Map> = new Map(); +export const DEFAULT_LABEL_OPERATOR = undefined; -export function renderSearchLabelFor(operator: string) { +const map: Map>> = new Map(); + +export function renderSearchLabelFor(operator: string = DEFAULT_LABEL_OPERATOR, theme = DEFAULT_THEME) { return function decorator(objectElement: any) { if (!objectElement) { return; } - map.set(operator, objectElement); + if (hasNoValue(map.get(operator))) { + map.set(operator, new Map()); + } + if (hasNoValue(map.get(operator).get(theme))) { + map.get(operator).set(theme, objectElement); + } else { + throw new Error(`There can't be more than one component to render Label with operator "${operator}" and theme "${theme}"`); + } }; } -export function getSearchLabelByOperator(operator: string): GenericConstructor { - return map.get(operator); +export function getSearchLabelByOperator(operator: string, theme: string): Type { + let themeMap: Map> = map.get(operator); + if (hasNoValue(themeMap)) { + themeMap = map.get(DEFAULT_LABEL_OPERATOR); + } + const comp: Type = themeMap.get(theme); + if (hasNoValue(comp)) { + return themeMap.get(DEFAULT_THEME); + } + return comp; } 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 5563d124e8..ff891de12b 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 @@ -15,13 +15,7 @@ import { PaginationService } from '../../../../core/pagination/pagination.servic selector: 'ds-search-label', templateUrl: './search-label.component.html', }) -@renderSearchLabelFor('equals') -@renderSearchLabelFor('notequals') -@renderSearchLabelFor('authority') -@renderSearchLabelFor('notauthority') -@renderSearchLabelFor('contains') -@renderSearchLabelFor('notcontains') -@renderSearchLabelFor('query') +@renderSearchLabelFor() export class SearchLabelComponent implements OnInit { @Input() inPlaceSearch: boolean; @Input() appliedFilter: AppliedFilter;