import { IndexPatternField } from '../../../../../../data/public' ; export interface FieldFilterState { missing : boolean ; type : string ; name : string ; aggregatable : null | boolean ; searchable : null | boolean ; } export function getDefaultFieldFilter ( ) { return { missing : true , type : 'any' , name : '' , aggregatable : null , searchable : null , } ; } export function setFieldFilterProp ( state , name , value ) { const newState = { ... state } ; if ( name === 'missing' ) { newState . missing = Boolean ( value ) ; } else if ( name === 'aggregatable' ) { newState . aggregatable = typeof value !== 'boolean' ? null : value ; } else if ( name === 'searchable' ) { newState . searchable = typeof value !== 'boolean' ? null : value ; } else if ( name === 'name' ) { newState . name = String ( value ) ; } else if ( name === 'type' ) { newState . type = String ( value ) ; } return newState ; } export function isFieldFiltered ( field , filterState , fieldCounts ) { const matchFilter = filterState . type === 'any' || field . type === filterState . type ; const isAggregatable = filterState . aggregatable === null || field . aggregatable === filterState . aggregatable ; const isSearchable = filterState . searchable === null || field . searchable === filterState . searchable ; const scriptedOrMissing = ! filterState . missing || field . type === '_source' || field . scripted || fieldCounts [ field . name ] > 0 ; const matchName = ! filterState . name || field . name . indexOf ( filterState . name ) !== - 1 ; return matchFilter && isAggregatable && isSearchable && scriptedOrMissing && matchName ; }