Commit edbde6c0 by Peter Holmberg Committed by GitHub

Expressions: Add placeholders to hint on input (#29773)

* math placeholder

* resample changes
parent 6118ab41
// Libraries
import React, { PureComponent, ChangeEvent } from 'react';
import { css } from 'emotion';
import { InlineField, InlineFieldRow, Input, Select, TextArea } from '@grafana/ui';
import { SelectableValue, ReducerID, QueryEditorProps } from '@grafana/data';
......@@ -39,6 +40,11 @@ const upsamplingTypes: Array<SelectableValue<string>> = [
{ value: 'fillna', label: 'fillna', description: 'Fill with NaNs' },
];
const mathPlaceholder =
'Math operations on one more queries, you reference the query by ${refId} ie. $A, $B, $C etc\n' +
'Example: $A + $B\n' +
'Available functions: abs(), log(), nan(), inf(), null()';
export class ExpressionQueryEditor extends PureComponent<Props, State> {
state = {};
......@@ -123,42 +129,73 @@ export class ExpressionQueryEditor extends PureComponent<Props, State> {
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;
return (
<div>
<InlineField label="Operation">
<InlineField label="Operation" labelWidth={labelWidth}>
<Select options={gelTypes} value={selected} onChange={this.onSelectGELType} width={25} />
</InlineField>
{query.type === GELQueryType.math && (
<InlineField label="Expression">
<TextArea value={query.expression} onChange={this.onExpressionChange} rows={2} />
<InlineField
label="Expression"
labelWidth={labelWidth}
className={css`
align-items: baseline;
`}
>
<TextArea
value={query.expression}
onChange={this.onExpressionChange}
rows={4}
placeholder={mathPlaceholder}
/>
</InlineField>
)}
{query.type === GELQueryType.reduce && (
<InlineFieldRow>
<InlineField label="Function">
<InlineField label="Function" labelWidth={labelWidth}>
<Select options={reducerTypes} value={reducer} onChange={this.onSelectReducer} width={25} />
</InlineField>
<InlineField label="Input">
<Input onChange={this.onExpressionChange} value={query.expression} width={25} />
<InlineField label="Query" labelWidth={labelWidth}>
<Input
onChange={this.onExpressionChange}
value={query.expression}
width={30}
placeholder="Choose query by refId (eg. $A or A)"
/>
</InlineField>
</InlineFieldRow>
)}
{query.type === GELQueryType.resample && (
<InlineFieldRow>
<InlineField label="Input">
<Input onChange={this.onExpressionChange} value={query.expression} width={25} />
</InlineField>
<InlineField label="Window">
<Input onChange={this.onWindowChange} value={query.window} width={25} />
</InlineField>
<InlineField label="Downsample">
<Select options={downsamplingTypes} value={downsampler} onChange={this.onSelectDownsampler} width={25} />
</InlineField>
<InlineField label="Upsample">
<Select options={upsamplingTypes} value={upsampler} onChange={this.onSelectUpsampler} width={25} />
</InlineField>
</InlineFieldRow>
<>
<InlineFieldRow>
<InlineField label="Query" labelWidth={labelWidth}>
<Input
onChange={this.onExpressionChange}
value={query.expression}
width={30}
placeholder="Choose query by refId (eg. $A or A)"
/>
</InlineField>
</InlineFieldRow>
<InlineFieldRow>
<InlineField label="Resample to" labelWidth={labelWidth} tooltip="10s, 1m, 30m, 1h">
<Input onChange={this.onWindowChange} value={query.window} width={15} />
</InlineField>
<InlineField label="Downsample">
<Select
options={downsamplingTypes}
value={downsampler}
onChange={this.onSelectDownsampler}
width={25}
/>
</InlineField>
<InlineField label="Upsample">
<Select options={upsamplingTypes} value={upsampler} onChange={this.onSelectUpsampler} width={25} />
</InlineField>
</InlineFieldRow>
</>
)}
</div>
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment