import { i18n } from '@osd/i18n' ; import { IndexPattern } from 'src/plugins/data/public' ; /**
 * A hidden parameter can be hidden from the UI completely.
 */ interface Param { hidden ? : boolean ; help ? : string ; } /**
 * A fixed parameter has a fixed value for a specific field.
 * It can optionally also be hidden.
 */ export type FixedParam = Partial < Param > & { fixedValue : any ; } ; /**
 * Numeric interval parameters must always be set in the editor to a multiple of
 * the specified base. It can optionally also be hidden.
 */ export type NumericIntervalParam = Partial < Param > & { base : number ; } ; /**
 * Time interval parameters must always be set in the editor to a multiple of
 * the specified base. It can optionally also be hidden.
 */ export type TimeIntervalParam = Partial < Param > & { default : string ; timeBase : string ; } ; export type EditorParamConfig = NumericIntervalParam | TimeIntervalParam | FixedParam | Param ; export interface EditorConfig { [ paramName ] : EditorParamConfig ; } export function getEditorConfig ( indexPattern , aggTypeName , fieldName ) { const aggRestrictions = indexPattern . getAggregationRestrictions ( ) ; if ( ! aggRestrictions || ! aggTypeName || ! fieldName ) { return { } ; } if ( aggTypeName === 'terms' ) { return { otherBucket : { hidden : true , } , missingBucket : { hidden : true , } , } ; } const fieldAgg = aggRestrictions [ aggTypeName ] && aggRestrictions [ aggTypeName ] [ fieldName ] ; if ( ! fieldAgg ) { return { } ; } if ( aggTypeName === 'histogram' ) { const interval = fieldAgg . interval ; return interval ? { intervalBase : { fixedValue : interval , } , interval : { base : interval , help : i18n . translate ( 'visDefaultEditor.editorConfig.histogram.interval.helpText' , { defaultMessage : 'Must be a multiple of configuration interval: {interval}' , values : { interval } , } ) , } , } : { } ; } if ( aggTypeName === 'date_histogram' ) { const interval = fieldAgg . calendar_interval || fieldAgg . fixed_interval ; return { useNormalizedOpenSearchInterval : { fixedValue : false , } , interval : { default : interval , timeBase : interval , help : i18n . translate ( 'visDefaultEditor.editorConfig.dateHistogram.customInterval.helpText' , { defaultMessage : 'Must be a multiple of configuration interval: {interval}' , values : { interval } , } ) , } , } ; } return { } ; }