diff --git a/packages/grafana-ui/src/components/Dropdown/ButtonSelect.tsx b/packages/grafana-ui/src/components/Dropdown/ButtonSelect.tsx index 9c04c84c1fe..978a01d4530 100644 --- a/packages/grafana-ui/src/components/Dropdown/ButtonSelect.tsx +++ b/packages/grafana-ui/src/components/Dropdown/ButtonSelect.tsx @@ -43,7 +43,7 @@ export const ButtonSelect = React.memo((props: Props) => { }; return ( - <> +
(props: Props) => {
)} - + ); }); diff --git a/public/app/features/alerting/state/alertDef.ts b/public/app/features/alerting/state/alertDef.ts index 489ad3bfae2..4b8fd89d759 100644 --- a/public/app/features/alerting/state/alertDef.ts +++ b/public/app/features/alerting/state/alertDef.ts @@ -25,12 +25,20 @@ const alertStateSortScore = { paused: 5, }; +export enum EvalFunction { + 'IsAbove' = 'gt', + 'IsBelow' = 'lt', + 'IsOutsideRange' = 'outside_range', + 'IsWithinRange' = 'within_range', + 'HasNoValue' = 'no_value', +} + const evalFunctions = [ - { text: 'IS ABOVE', value: 'gt' }, - { text: 'IS BELOW', value: 'lt' }, - { text: 'IS OUTSIDE RANGE', value: 'outside_range' }, - { text: 'IS WITHIN RANGE', value: 'within_range' }, - { text: 'HAS NO VALUE', value: 'no_value' }, + { value: EvalFunction.IsAbove, text: 'IS ABOVE' }, + { value: EvalFunction.IsBelow, text: 'IS BELOW' }, + { value: EvalFunction.IsOutsideRange, text: 'IS OUTSIDE RANGE' }, + { value: EvalFunction.IsWithinRange, text: 'IS WITHIN RANGE' }, + { value: EvalFunction.HasNoValue, text: 'HAS NO VALUE' }, ]; const evalOperators = [ diff --git a/public/app/features/expressions/ExpressionDatasource.ts b/public/app/features/expressions/ExpressionDatasource.ts index d1dd83c10ac..8ffc1028ddc 100644 --- a/public/app/features/expressions/ExpressionDatasource.ts +++ b/public/app/features/expressions/ExpressionDatasource.ts @@ -1,5 +1,5 @@ import { DataSourceInstanceSettings, DataSourcePluginMeta } from '@grafana/data'; -import { ExpressionQuery, GELQueryType } from './types'; +import { ExpressionQuery, ExpressionQueryType } from './types'; import { ExpressionQueryEditor } from './ExpressionQueryEditor'; import { DataSourceWithBackend } from '@grafana/runtime'; @@ -18,7 +18,7 @@ export class ExpressionDatasourceApi extends DataSourceWithBackend; -interface State {} - -const gelTypes: Array> = [ - { value: GELQueryType.math, label: 'Math' }, - { value: GELQueryType.reduce, label: 'Reduce' }, - { value: GELQueryType.resample, label: 'Resample' }, -]; - -const reducerTypes: Array> = [ - { value: ReducerID.min, label: 'Min', description: 'Get the minimum value' }, - { value: ReducerID.max, label: 'Max', description: 'Get the maximum value' }, - { value: ReducerID.mean, label: 'Mean', description: 'Get the average value' }, - { value: ReducerID.sum, label: 'Sum', description: 'Get the sum of all values' }, - { value: ReducerID.count, label: 'Count', description: 'Get the number of values' }, -]; - -const downsamplingTypes: Array> = [ - { value: ReducerID.min, label: 'Min', description: 'Fill with the minimum value' }, - { value: ReducerID.max, label: 'Max', description: 'Fill with the maximum value' }, - { value: ReducerID.mean, label: 'Mean', description: 'Fill with the average value' }, - { value: ReducerID.sum, label: 'Sum', description: 'Fill with the sum of all values' }, -]; - -const upsamplingTypes: Array> = [ - { value: 'pad', label: 'pad', description: 'fill with the last known value' }, - { value: 'backfilling', label: 'backfilling', description: 'fill with the next known value' }, - { value: 'fillna', label: 'fillna', description: 'Fill with NaNs' }, -]; - -const mathPlaceholder = - 'Math operations on one more queries, you reference the query by ${refId}, such as $A, $B, $C etc\n' + - 'Example: $A + $B\n' + - 'Available functions: abs(), log(), nan(), inf(), null()'; - -export class ExpressionQueryEditor extends PureComponent { - state = {}; - - onSelectGELType = (item: SelectableValue) => { +const labelWidth = 14; +export class ExpressionQueryEditor extends PureComponent { + onSelectExpressionType = (item: SelectableValue) => { const { query, onChange } = this.props; - const q = { - ...query, - type: item.value!, - }; - if (q.type === GELQueryType.reduce) { - if (!q.reducer) { - q.reducer = ReducerID.mean; - } - q.expression = undefined; - } else if (q.type === GELQueryType.resample) { - if (!q.downsampler) { - q.downsampler = ReducerID.mean; - } - if (!q.upsampler) { - q.upsampler = 'fillna'; - } - q.reducer = undefined; - } else { - q.reducer = undefined; + onChange(getDefaults({ ...query, type: item.value! })); + }; + + renderExpressionType() { + const { onChange, query, queries } = this.props; + const refIds = queries!.filter((q) => query.refId !== q.refId).map((q) => ({ value: q.refId, label: q.refId })); + + switch (query.type) { + case ExpressionQueryType.math: + return ; + + case ExpressionQueryType.reduce: + return ; + + case ExpressionQueryType.resample: + return ; + + case ExpressionQueryType.classic: + return ; } - - onChange(q); - }; - - onSelectReducer = (item: SelectableValue) => { - const { query, onChange } = this.props; - onChange({ - ...query, - reducer: item.value!, - }); - }; - - onSelectUpsampler = (item: SelectableValue) => { - const { query, onChange } = this.props; - onChange({ - ...query, - upsampler: item.value!, - }); - }; - - onSelectDownsampler = (item: SelectableValue) => { - const { query, onChange } = this.props; - onChange({ - ...query, - downsampler: item.value!, - }); - }; - - onRuleReducer = (item: SelectableValue) => { - const { query, onChange } = this.props; - onChange({ - ...query, - window: item.value!, - }); - }; - - onRefIdChange = (value: SelectableValue) => { - const { query, onChange } = this.props; - onChange({ - ...query, - expression: value.value, - }); - }; - - onExpressionChange = (evt: ChangeEvent) => { - const { query, onChange } = this.props; - onChange({ - ...query, - expression: evt.target.value, - }); - }; - - onWindowChange = (evt: ChangeEvent) => { - const { query, onChange } = this.props; - onChange({ - ...query, - window: evt.target.value, - }); - }; + } render() { - const { query, queries } = this.props; + const { query } = this.props; const selected = gelTypes.find((o) => o.value === query.type); - const reducer = reducerTypes.find((o) => o.value === query.reducer); - const downsampler = downsamplingTypes.find((o) => o.value === query.downsampler); - const upsampler = upsamplingTypes.find((o) => o.value === query.upsampler); - const labelWidth = 14; - - const refIds = queries!.filter((q) => query.refId !== q.refId).map((q) => ({ value: q.refId, label: q.refId })); return (
- - {query.type === GELQueryType.math && ( - -