/// /// Copyright 2015-2026 Micro Focus or one of its affiliates. /// /// Licensed under the Apache License, Version 2.0 (the "License"); /// you may not use this file except in compliance with the License. /// You may obtain a copy of the License at /// /// http://www.apache.org/licenses/LICENSE-2.0 /// /// Unless required by applicable law or agreed to in writing, software /// distributed under the License is distributed on an "AS IS" BASIS, /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// See the License for the specific language governing permissions and /// limitations under the License. /// import { NgTemplateOutlet, AsyncPipe } from '@angular/common'; import { ChangeDetectionStrategy, Component, ContentChild, EventEmitter, inject, Input, OnDestroy, Output, TemplateRef, } from '@angular/core'; import { Subject } from 'rxjs'; import { distinctUntilChanged, takeUntil } from 'rxjs/operators'; import { DefaultFocusIndicatorDirective } from '../../directives/accessibility/focus-indicator/default-focus-indicator.directive'; import { TooltipDirective } from '../tooltip/tooltip.directive'; import { FilterEvent } from './events/filter-event'; import { FilterService } from './filter.service'; import { Filter } from './interfaces/filter.interface'; @Component({ selector: 'ux-filter-container', templateUrl: './filter-container.component.html', providers: [FilterService], changeDetection: ChangeDetectionStrategy.OnPush, imports: [DefaultFocusIndicatorDirective, TooltipDirective, NgTemplateOutlet, AsyncPipe], }) export class FilterContainerComponent implements OnDestroy { readonly filterService = inject(FilterService); /** Allow filters to set from outside the component */ @Input() set filters(filters: Filter[]) { this.filterService.filters$.next(filters); } /** Define the tooltip text */ @Input() clearTooltip: string; /** Defines the aria-label for the clear all button */ @Input() clearAriaLabel: string = 'Clear All Filters'; /** Emit when the active filters chance */ @Output() filtersChange = new EventEmitter(); /** Emit when a specific event occurs */ @Output() events = new EventEmitter(); /** Allow the content of the clear all button to be customized */ @ContentChild('clearAllTemplate', { static: false }) clearAllTemplate: TemplateRef; /** Unsubscribe from the subscriptions on destroy */ private readonly _onDestroy = new Subject(); constructor() { // subscribe to changes to the active filters this.filterService.filters$ .pipe(distinctUntilChanged(), takeUntil(this._onDestroy)) .subscribe(filters => this.filtersChange.emit(filters)); // relay any events to the event emitter this.filterService.events$ .pipe(takeUntil(this._onDestroy)) .subscribe(event => this.events.emit(event)); } /** Destroy all subscriptions */ ngOnDestroy(): void { this._onDestroy.next(); this._onDestroy.complete(); } }