grafana/public/app/features/expressions/components/Resample.tsx
Ashley Harrison 8aa3845f70
Select: Make portalling the menu opt-in, but opt-in *everywhere* (#37501)
* Select: Don't portal by default

* Select: Portal all the Selects

* Fix indendentation in this comment

* Select: Remove @example docs until formatting is correct

* Docs: Add some documentation for the Select changes

* Update docs/sources/whatsnew/whats-new-in-v8-1.md

Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com>

* Update docs/sources/whatsnew/whats-new-in-v8-1.md

Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com>

* Update packages/grafana-ui/src/components/Select/types.ts

Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com>

* Update public/app/core/components/TransformersUI/configFromQuery/ConfigFromQueryTransformerEditor.tsx

Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com>

* Update public/app/core/components/TransformersUI/configFromQuery/ConfigFromQueryTransformerEditor.tsx

Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com>

* Update public/app/core/components/TransformersUI/configFromQuery/ConfigFromQueryTransformerEditor.tsx

Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com>

* Update public/app/core/components/TransformersUI/prepareTimeSeries/PrepareTimeSeriesEditor.tsx

Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com>

* Docs: Variants instead of varients

* Update public/app/core/components/TransformersUI/configFromQuery/ConfigFromQueryTransformerEditor.tsx

Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com>

Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com>
2021-08-04 15:47:53 +01:00

66 lines
2.1 KiB
TypeScript

import React, { ChangeEvent, FC } from 'react';
import { SelectableValue } from '@grafana/data';
import { InlineField, InlineFieldRow, Input, Select } from '@grafana/ui';
import { downsamplingTypes, ExpressionQuery, upsamplingTypes } from '../types';
interface Props {
refIds: Array<SelectableValue<string>>;
query: ExpressionQuery;
labelWidth: number;
onChange: (query: ExpressionQuery) => void;
}
export const Resample: FC<Props> = ({ labelWidth, onChange, refIds, query }) => {
const downsampler = downsamplingTypes.find((o) => o.value === query.downsampler);
const upsampler = upsamplingTypes.find((o) => o.value === query.upsampler);
const onWindowChange = (event: ChangeEvent<HTMLInputElement>) => {
onChange({ ...query, window: event.target.value });
};
const onRefIdChange = (value: SelectableValue<string>) => {
onChange({ ...query, expression: value.value });
};
const onSelectDownsampler = (value: SelectableValue<string>) => {
onChange({ ...query, downsampler: value.value });
};
const onSelectUpsampler = (value: SelectableValue<string>) => {
onChange({ ...query, upsampler: value.value });
};
return (
<>
<InlineFieldRow>
<InlineField label="Input" labelWidth={labelWidth}>
<Select menuShouldPortal onChange={onRefIdChange} options={refIds} value={query.expression} width={20} />
</InlineField>
</InlineFieldRow>
<InlineFieldRow>
<InlineField label="Resample to" labelWidth={labelWidth} tooltip="10s, 1m, 30m, 1h">
<Input onChange={onWindowChange} value={query.window} width={15} />
</InlineField>
<InlineField label="Downsample">
<Select
menuShouldPortal
options={downsamplingTypes}
value={downsampler}
onChange={onSelectDownsampler}
width={25}
/>
</InlineField>
<InlineField label="Upsample">
<Select
menuShouldPortal
options={upsamplingTypes}
value={upsampler}
onChange={onSelectUpsampler}
width={25}
/>
</InlineField>
</InlineFieldRow>
</>
);
};