import { i18n } from '@osd/i18n' ; import { Assign } from '@osd/utility-types' ; import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common' ; import { AggExpressionType , AggExpressionFunctionArgs , BUCKET_TYPES } from '../' ; import { getParsedValue } from '../utils/get_parsed_value' ; const fnName = 'aggFilter' ; type Input = any ; type AggArgs = AggExpressionFunctionArgs < typeof BUCKET_TYPES . FILTER > ; type Arguments = Assign < AggArgs , { geo_bounding_box ? : string ; } > ; type Output = AggExpressionType ; type FunctionDefinition = ExpressionFunctionDefinition < typeof fnName , Input , Arguments , Output > ; export const aggFilter = ( ) : FunctionDefinition => ( { name : fnName , help : i18n . translate ( 'data.search.aggs.function.buckets.filter.help' , { defaultMessage : 'Generates a serialized agg config for a Filter agg' , } ) , type : 'agg_type' , args : { id : { types : [ 'string' ] , help : i18n . translate ( 'data.search.aggs.buckets.filter.id.help' , { defaultMessage : 'ID for this aggregation' , } ) , } , enabled : { types : [ 'boolean' ] , default : true , help : i18n . translate ( 'data.search.aggs.buckets.filter.enabled.help' , { defaultMessage : 'Specifies whether this aggregation should be enabled' , } ) , } , schema : { types : [ 'string' ] , help : i18n . translate ( 'data.search.aggs.buckets.filter.schema.help' , { defaultMessage : 'Schema to use for this aggregation' , } ) , } , geo_bounding_box : { types : [ 'string' ] , help : i18n . translate ( 'data.search.aggs.buckets.filter.geoBoundingBox.help' , { defaultMessage : 'Filter results based on a point location within a bounding box' , } ) , } , json : { types : [ 'string' ] , help : i18n . translate ( 'data.search.aggs.buckets.filter.json.help' , { defaultMessage : 'Advanced json to include when the agg is sent to OpenSearch' , } ) , } , customLabel : { types : [ 'string' ] , help : i18n . translate ( 'data.search.aggs.buckets.filter.customLabel.help' , { defaultMessage : 'Represents a custom label for this aggregation' , } ) , } , } , fn : ( input , args ) => { const { id , enabled , schema , ... rest } = args ; return { type : 'agg_type' , value : { id , enabled , schema , type : BUCKET_TYPES . FILTER , params : { ... rest , json : getParsedValue ( args , 'json' ) , geo_bounding_box : getParsedValue ( args , 'geo_bounding_box' ) , } , } , } ; } , } ) ;