/**
 * Generic configuration for a filter with different selectable  FilterSelectionOption options.
 *
 * This is a reusable format for any kind of dropdown or selection component that offers the user a choice
 * to narrow down a list of data items.
 * As the filter function is provided as part of each  FilterSelectionOption * an instance of this FilterSelection class can manage all filter selection logic.
  export class FilterSelection < T > { /**
     * Generate filter options dynamically from the given value to be matched.
     *
     * This is a utility function to make it easier to generate  FilterSelectionOption s for standard cases
     * if you simply want each option to filter items having the given attribute matching different values.
     * If you have more sophisticated filtering needs, use the constructor to set  FilterSelectionOption s that
     * you created yourself.
     *
     *  param valuesToMatchAsOptions param attributeName public static generateOptions < TT > ( valuesToMatchAsOptions , attributeName ) { const options = [ { key : "" , label : $localize `:generic filter option showing all entries:All` , filterFun : ( e ) => true , } , ] ; valuesToMatchAsOptions . forEach ( ( k ) => { if ( k ) { options . push ( { key : k . toLowerCase ( ) , label : k . toString ( ) , filterFun : ( e ) => e [ attributeName ] === k , } ) ; } } ) ; return options ; } param name param options param label constructor ( public name , public options , public label = name ) { } /** default filter will keep all items in the result */ defaultFilterFunction = ( c ) => true ; param key getOption ( key ) { return this . options . find ( ( option ) => option . key === key ) ; } /**
     * Get the filter function for the given option.
     * If the given key is undefined or invalid, the returned filter function will keep all items in the result if applied.
     *
     * This can be directly used on a data array, e.g. "data.filter(filterSelection.getFilterFunction('a'))"
     */ public getFilterFunction ( key ) { const option = this . getOption ( key ) ; if ( ! option ) { return this . defaultFilterFunction ; } else { return option . filterFun ; } } } /**
 * Represents one specific option to filter data in a certain way.
 * used by  FilterSelection export interface FilterSelectionOption < T > { /** identifier for this option in the parent FilterSelection instance */ key : string ; /** label displayed for this option to the user in the UI */ label : string ; /**
     * function that filters a dataset.
     * This filter logic will be applied to data when this option is selected.
     */ filterFun : ( c : T ) => boolean ; }