import { Filter , IAggConfig , TabbedTable } from '../../../common' ; const getOtherBucketFilterTerms = ( table , columnIndex , rowIndex ) => { if ( rowIndex === - 1 ) { return [ ] ; } const rows = table . rows . filter ( ( row ) => { return table . columns . every ( ( column , i ) => { return row [ column . id ] === table . rows [ rowIndex ] [ column . id ] || i >= columnIndex ; } ) ; } ) ; const terms = rows . map ( ( row ) => row [ table . columns [ columnIndex ] . id ] ) ; return [ ... new Set ( terms . filter ( ( term ) => { const notOther = term !== '__other__' ; const notMissing = term !== '__missing__' ; return notOther && notMissing ; } ) ) , ] ; } ; export const createFilter = ( aggConfigs , table , columnIndex , rowIndex , cellValue ) => { const column = table . columns [ columnIndex ] ; const aggConfig = aggConfigs [ columnIndex ] ; let filter = [ ] ; const value = rowIndex > - 1 ? table . rows [ rowIndex ] [ column . id ] : cellValue ; if ( value === null || value === undefined || ! aggConfig . isFilterable ( ) ) { return ; } if ( aggConfig . type . name === 'terms' && aggConfig . params . otherBucket ) { const terms = getOtherBucketFilterTerms ( table , columnIndex , rowIndex ) ; filter = aggConfig . createFilter ( value , { terms } ) ; } else { filter = aggConfig . createFilter ( value ) ; } if ( ! filter ) { return ; } if ( ! Array . isArray ( filter ) ) { filter = [ filter ] ; } return filter ; } ;