mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Fix comment lines * Introduce graphite variable editor * Render results differently based on queryType * Add comments and fallback values * Unit tests for different type of graphite queries * Use metrics/expand endpoint to retrieve metric names
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
import React, { 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) => 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: React.FC<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) => {
|
|
onChange({
|
|
...value,
|
|
queryType: selectableValue.value,
|
|
});
|
|
}}
|
|
/>
|
|
</InlineField>
|
|
<InlineField label="Select query type" labelWidth={20} grow>
|
|
<Input
|
|
aria-label="Variable editor query input"
|
|
value={value.target}
|
|
onBlur={() => onChange(value)}
|
|
onChange={(e) => {
|
|
setValue({
|
|
...value,
|
|
target: e.currentTarget.value,
|
|
});
|
|
}}
|
|
/>
|
|
</InlineField>
|
|
</>
|
|
);
|
|
};
|