import { IIndexPattern , IFieldType } from '../..' ; import { Filter , FILTERS , FilterStateStore , FilterMeta , buildPhraseFilter , buildPhrasesFilter , buildRangeFilter , buildExistsFilter , } from '.' ; export function buildFilter ( indexPattern , field , type , negate , disabled , params , alias , store ) { const filter = buildBaseFilter ( indexPattern , field , type , params ) ; filter . meta . alias = alias ; filter . meta . negate = negate ; filter . meta . disabled = disabled ; filter . $state = { store } ; return filter ; } export function buildCustomFilter ( indexPatternString , queryDsl , disabled , negate , alias , store ) { const meta = { index : indexPatternString , type : FILTERS . CUSTOM , disabled , negate , alias , } ; const filter = { ... queryDsl , meta } ; filter . $state = { store } ; return filter ; } function buildBaseFilter ( indexPattern , field , type , params ) { switch ( type ) { case 'phrase' : return buildPhraseFilter ( field , params , indexPattern ) ; case 'phrases' : return buildPhrasesFilter ( field , params , indexPattern ) ; case 'range' : const newParams = { gte : params . from , lt : params . to } ; return buildRangeFilter ( field , newParams , indexPattern ) ; case 'exists' : return buildExistsFilter ( field , indexPattern ) ; default : throw new Error ( `Unknown filter type: ${ type }` ) ; } }