2022-10-12 03:43:41 -05:00
|
|
|
import { useId } from '@react-aria/utils';
|
2020-11-18 08:10:32 -06:00
|
|
|
import React, { FC, useCallback, useState } from 'react';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2020-11-18 08:10:32 -06:00
|
|
|
import { selectors } from '@grafana/e2e-selectors';
|
2022-10-12 03:43:41 -05:00
|
|
|
import { TextArea, useStyles2 } from '@grafana/ui';
|
2020-11-18 08:10:32 -06:00
|
|
|
|
2022-01-17 05:48:26 -06:00
|
|
|
import { VariableQueryEditorProps } from '../types';
|
|
|
|
|
2022-10-12 03:43:41 -05:00
|
|
|
import { getStyles } from './VariableTextAreaField';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2020-11-18 08:10:32 -06:00
|
|
|
export const LEGACY_VARIABLE_QUERY_EDITOR_NAME = 'Grafana-LegacyVariableQueryEditor';
|
|
|
|
|
2022-01-17 05:48:26 -06:00
|
|
|
export const LegacyVariableQueryEditor: FC<VariableQueryEditorProps> = ({ onChange, query }) => {
|
2022-10-12 03:43:41 -05:00
|
|
|
const styles = useStyles2(getStyles);
|
2020-11-18 08:10:32 -06:00
|
|
|
const [value, setValue] = useState(query);
|
2021-03-25 06:42:14 -05:00
|
|
|
const onValueChange = (event: React.FormEvent<HTMLTextAreaElement>) => {
|
|
|
|
setValue(event.currentTarget.value);
|
|
|
|
};
|
2020-11-25 03:21:48 -06:00
|
|
|
|
2020-11-18 08:10:32 -06:00
|
|
|
const onBlur = useCallback(
|
|
|
|
(event: React.FormEvent<HTMLTextAreaElement>) => {
|
|
|
|
onChange(event.currentTarget.value, event.currentTarget.value);
|
|
|
|
},
|
|
|
|
[onChange]
|
|
|
|
);
|
|
|
|
|
2022-10-12 03:43:41 -05:00
|
|
|
const id = useId();
|
|
|
|
|
2020-11-18 08:10:32 -06:00
|
|
|
return (
|
2022-10-12 03:43:41 -05:00
|
|
|
<TextArea
|
|
|
|
id={id}
|
|
|
|
rows={2}
|
|
|
|
value={value}
|
|
|
|
onChange={onValueChange}
|
|
|
|
onBlur={onBlur}
|
|
|
|
placeholder="Metric name or tags query"
|
|
|
|
required
|
|
|
|
aria-label={selectors.pages.Dashboard.Settings.Variables.Edit.QueryVariable.queryOptionsQueryInput}
|
|
|
|
cols={52}
|
|
|
|
className={styles.textarea}
|
|
|
|
/>
|
2020-11-18 08:10:32 -06:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
LegacyVariableQueryEditor.displayName = LEGACY_VARIABLE_QUERY_EDITOR_NAME;
|