Commit edbde6c0 by Peter Holmberg Committed by GitHub

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

* math placeholder

* resample changes
parent 6118ab41
// Libraries // Libraries
import React, { PureComponent, ChangeEvent } from 'react'; import React, { PureComponent, ChangeEvent } from 'react';
import { css } from 'emotion';
import { InlineField, InlineFieldRow, Input, Select, TextArea } from '@grafana/ui'; import { InlineField, InlineFieldRow, Input, Select, TextArea } from '@grafana/ui';
import { SelectableValue, ReducerID, QueryEditorProps } from '@grafana/data'; import { SelectableValue, ReducerID, QueryEditorProps } from '@grafana/data';
...@@ -39,6 +40,11 @@ const upsamplingTypes: Array<SelectableValue<string>> = [ ...@@ -39,6 +40,11 @@ const upsamplingTypes: Array<SelectableValue<string>> = [
{ value: 'fillna', label: 'fillna', description: 'Fill with NaNs' }, { 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> { export class ExpressionQueryEditor extends PureComponent<Props, State> {
state = {}; state = {};
...@@ -123,42 +129,73 @@ export class ExpressionQueryEditor extends PureComponent<Props, State> { ...@@ -123,42 +129,73 @@ export class ExpressionQueryEditor extends PureComponent<Props, State> {
const reducer = reducerTypes.find(o => o.value === query.reducer); const reducer = reducerTypes.find(o => o.value === query.reducer);
const downsampler = downsamplingTypes.find(o => o.value === query.downsampler); const downsampler = downsamplingTypes.find(o => o.value === query.downsampler);
const upsampler = upsamplingTypes.find(o => o.value === query.upsampler); const upsampler = upsamplingTypes.find(o => o.value === query.upsampler);
const labelWidth = 14;
return ( return (
<div> <div>
<InlineField label="Operation"> <InlineField label="Operation" labelWidth={labelWidth}>
<Select options={gelTypes} value={selected} onChange={this.onSelectGELType} width={25} /> <Select options={gelTypes} value={selected} onChange={this.onSelectGELType} width={25} />
</InlineField> </InlineField>
{query.type === GELQueryType.math && ( {query.type === GELQueryType.math && (
<InlineField label="Expression"> <InlineField
<TextArea value={query.expression} onChange={this.onExpressionChange} rows={2} /> label="Expression"
labelWidth={labelWidth}
className={css`
align-items: baseline;
`}
>
<TextArea
value={query.expression}
onChange={this.onExpressionChange}
rows={4}
placeholder={mathPlaceholder}
/>
</InlineField> </InlineField>
)} )}
{query.type === GELQueryType.reduce && ( {query.type === GELQueryType.reduce && (
<InlineFieldRow> <InlineFieldRow>
<InlineField label="Function"> <InlineField label="Function" labelWidth={labelWidth}>
<Select options={reducerTypes} value={reducer} onChange={this.onSelectReducer} width={25} /> <Select options={reducerTypes} value={reducer} onChange={this.onSelectReducer} width={25} />
</InlineField> </InlineField>
<InlineField label="Input"> <InlineField label="Query" labelWidth={labelWidth}>
<Input onChange={this.onExpressionChange} value={query.expression} width={25} /> <Input
onChange={this.onExpressionChange}
value={query.expression}
width={30}
placeholder="Choose query by refId (eg. $A or A)"
/>
</InlineField> </InlineField>
</InlineFieldRow> </InlineFieldRow>
)} )}
{query.type === GELQueryType.resample && ( {query.type === GELQueryType.resample && (
<>
<InlineFieldRow> <InlineFieldRow>
<InlineField label="Input"> <InlineField label="Query" labelWidth={labelWidth}>
<Input onChange={this.onExpressionChange} value={query.expression} width={25} /> <Input
onChange={this.onExpressionChange}
value={query.expression}
width={30}
placeholder="Choose query by refId (eg. $A or A)"
/>
</InlineField> </InlineField>
<InlineField label="Window"> </InlineFieldRow>
<Input onChange={this.onWindowChange} value={query.window} width={25} /> <InlineFieldRow>
<InlineField label="Resample to" labelWidth={labelWidth} tooltip="10s, 1m, 30m, 1h">
<Input onChange={this.onWindowChange} value={query.window} width={15} />
</InlineField> </InlineField>
<InlineField label="Downsample"> <InlineField label="Downsample">
<Select options={downsamplingTypes} value={downsampler} onChange={this.onSelectDownsampler} width={25} /> <Select
options={downsamplingTypes}
value={downsampler}
onChange={this.onSelectDownsampler}
width={25}
/>
</InlineField> </InlineField>
<InlineField label="Upsample"> <InlineField label="Upsample">
<Select options={upsamplingTypes} value={upsampler} onChange={this.onSelectUpsampler} width={25} /> <Select options={upsamplingTypes} value={upsampler} onChange={this.onSelectUpsampler} width={25} />
</InlineField> </InlineField>
</InlineFieldRow> </InlineFieldRow>
</>
)} )}
</div> </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