mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 20:22:19 +08:00

* update eslint, tsconfig + esbuild to handle new jsx transform * remove thing that breaks the new jsx transform * remove react imports * adjust grafana-icons build * is this the correct syntax? * try this * well this was much easier than expected... * change grafana-plugin-configs webpack config * fixes * fix lockfile * fix 2 more violations * use path.resolve instead of require.resolve * remove react import * fix react imports * more fixes * remove React import * remove import React from docs * remove another react import
66 lines
1.8 KiB
TypeScript
66 lines
1.8 KiB
TypeScript
import { useState } from 'react';
|
|
|
|
import { InlineField, Input, Select } from '@grafana/ui';
|
|
|
|
import { GraphiteQuery, GraphiteQueryType } from '../types';
|
|
|
|
import { convertToGraphiteQueryObject } from './helpers';
|
|
|
|
interface Props {
|
|
query: GraphiteQuery | string;
|
|
onChange: (query: GraphiteQuery, definition: string) => void;
|
|
}
|
|
|
|
const GRAPHITE_QUERY_VARIABLE_TYPE_OPTIONS = [
|
|
{ label: 'Default Query', value: GraphiteQueryType.Default },
|
|
{ label: 'Value Query', value: GraphiteQueryType.Value },
|
|
{ label: 'Metric Name Query', value: GraphiteQueryType.MetricName },
|
|
];
|
|
|
|
export const GraphiteVariableEditor = (props: Props) => {
|
|
const { query, onChange } = props;
|
|
const [value, setValue] = useState(convertToGraphiteQueryObject(query));
|
|
|
|
return (
|
|
<>
|
|
<InlineField label="Select query type" labelWidth={20}>
|
|
<Select
|
|
aria-label="select query type"
|
|
options={GRAPHITE_QUERY_VARIABLE_TYPE_OPTIONS}
|
|
width={25}
|
|
value={value.queryType ?? GraphiteQueryType.Default}
|
|
onChange={(selectableValue) => {
|
|
setValue({
|
|
...value,
|
|
queryType: selectableValue.value,
|
|
});
|
|
|
|
if (value.target) {
|
|
onChange(
|
|
{
|
|
...value,
|
|
queryType: selectableValue.value,
|
|
},
|
|
value.target ?? ''
|
|
);
|
|
}
|
|
}}
|
|
/>
|
|
</InlineField>
|
|
<InlineField label="Query" labelWidth={20} grow>
|
|
<Input
|
|
aria-label="Variable editor query input"
|
|
value={value.target}
|
|
onBlur={() => onChange(value, value.target ?? '')}
|
|
onChange={(e) => {
|
|
setValue({
|
|
...value,
|
|
target: e.currentTarget.value,
|
|
});
|
|
}}
|
|
/>
|
|
</InlineField>
|
|
</>
|
|
);
|
|
};
|