1import { ReducerID } from '@grafana/data'; 2import { ClassicCondition, ExpressionQuery, ExpressionQueryType } from '../types'; 3import { EvalFunction } from '../../alerting/state/alertDef'; 4 5export const getDefaults = (query: ExpressionQuery) => { 6 switch (query.type) { 7 case ExpressionQueryType.reduce: 8 if (!query.reducer) { 9 query.reducer = ReducerID.mean; 10 } 11 query.expression = undefined; 12 break; 13 14 case ExpressionQueryType.resample: 15 if (!query.downsampler) { 16 query.downsampler = ReducerID.mean; 17 } 18 19 if (!query.upsampler) { 20 query.upsampler = 'fillna'; 21 } 22 23 query.reducer = undefined; 24 break; 25 26 case ExpressionQueryType.classic: 27 if (!query.conditions) { 28 query.conditions = [defaultCondition]; 29 } 30 break; 31 32 default: 33 query.reducer = undefined; 34 } 35 36 return query; 37}; 38 39export const defaultCondition: ClassicCondition = { 40 type: 'query', 41 reducer: { 42 params: [], 43 type: 'avg', 44 }, 45 operator: { 46 type: 'and', 47 }, 48 query: { params: [] }, 49 evaluator: { 50 params: [0, 0], 51 type: EvalFunction.IsAbove, 52 }, 53}; 54