Update compact-filter.component.ts

This commit is contained in:
string 2025-10-25 21:57:10 +05:30
parent c6ad8b5c2f
commit cdcf1e07c7

View File

@ -1,4 +1,4 @@
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { Component, OnInit, Input, Output, EventEmitter, OnChanges, SimpleChanges } from '@angular/core';
import { FilterService, Filter } from './filter.service';
import { AlertsService } from 'src/app/services/fnd/alerts.service';
@ -7,7 +7,7 @@ import { AlertsService } from 'src/app/services/fnd/alerts.service';
templateUrl: './compact-filter.component.html',
styleUrls: ['./compact-filter.component.scss']
})
export class CompactFilterComponent implements OnInit {
export class CompactFilterComponent implements OnInit, OnChanges {
@Input() filterKey: string = '';
@Input() filterType: string = 'text';
@Input() filterOptions: string[] = [];
@ -67,6 +67,51 @@ export class CompactFilterComponent implements OnInit {
this.loadAvailableValues(this.filterKey);
}
}
// Register this filter with the filter service
this.registerFilter();
}
ngOnChanges(changes: SimpleChanges): void {
// If filterKey or filterType changes, re-register the filter
if (changes.filterKey || changes.filterType) {
this.registerFilter();
}
}
// Register this filter with the filter service
registerFilter(): void {
if (this.filterKey) {
// Create a filter definition for this compact filter
const filterDef: Filter = {
id: `compact-filter-${this.filterKey}`,
field: this.filterKey,
label: this.filterLabel || this.filterKey,
type: this.filterType as any,
options: this.filterOptions,
value: this.filterValue
};
// Get current filters
const currentFilters = this.filterService.getFilters();
// Check if this filter is already registered
const existingFilterIndex = currentFilters.findIndex(f => f.id === filterDef.id);
if (existingFilterIndex >= 0) {
// Update existing filter
currentFilters[existingFilterIndex] = filterDef;
} else {
// Add new filter
currentFilters.push(filterDef);
}
// Update the filter service with the new filter list
this.filterService.setFilters(currentFilters);
// Update the selected filter reference
this.selectedFilter = filterDef;
}
}
updateSelectedFilter(): void {
@ -175,6 +220,9 @@ export class CompactFilterComponent implements OnInit {
this.loadAvailableValues(this.filterKey);
}
// Register the updated filter with the filter service
this.registerFilter();
// Update selected filter
this.updateSelectedFilter();