2020-11-18 08:10:32 -06:00
|
|
|
import React, { FC, useCallback, useState } from 'react';
|
|
|
|
import { selectors } from '@grafana/e2e-selectors';
|
|
|
|
|
|
|
|
import { VariableQueryProps } from 'app/types/plugins';
|
2020-11-25 03:21:48 -06:00
|
|
|
import { VariableTextAreaField } from './VariableTextAreaField';
|
|
|
|
import { useStyles } from '@grafana/ui';
|
2020-11-18 08:10:32 -06:00
|
|
|
import { GrafanaTheme } from '@grafana/data';
|
|
|
|
import { css } from 'emotion';
|
|
|
|
|
|
|
|
export const LEGACY_VARIABLE_QUERY_EDITOR_NAME = 'Grafana-LegacyVariableQueryEditor';
|
|
|
|
|
|
|
|
export const LegacyVariableQueryEditor: FC<VariableQueryProps> = ({ onChange, query }) => {
|
|
|
|
const styles = useStyles(getStyles);
|
|
|
|
const [value, setValue] = useState(query);
|
|
|
|
const onValueChange = useCallback(
|
|
|
|
(event: React.FormEvent<HTMLTextAreaElement>) => {
|
|
|
|
setValue(event.currentTarget.value);
|
|
|
|
},
|
|
|
|
[onChange]
|
|
|
|
);
|
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]
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
2020-11-25 03:21:48 -06:00
|
|
|
<div className={styles.container}>
|
|
|
|
<VariableTextAreaField
|
|
|
|
name="Query"
|
2020-11-18 08:10:32 -06:00
|
|
|
value={value}
|
2020-11-25 03:21:48 -06:00
|
|
|
placeholder="metric name or tags query"
|
|
|
|
width={100}
|
2020-11-18 08:10:32 -06:00
|
|
|
onChange={onValueChange}
|
|
|
|
onBlur={onBlur}
|
|
|
|
required
|
2020-11-25 03:21:48 -06:00
|
|
|
labelWidth={20}
|
|
|
|
ariaLabel={selectors.pages.Dashboard.Settings.Variables.Edit.QueryVariable.queryOptionsQueryInput}
|
2020-11-18 08:10:32 -06:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
function getStyles(theme: GrafanaTheme) {
|
|
|
|
return {
|
2020-11-25 03:21:48 -06:00
|
|
|
container: css`
|
|
|
|
margin-bottom: ${theme.spacing.xs};
|
2020-11-18 08:10:32 -06:00
|
|
|
`,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
LegacyVariableQueryEditor.displayName = LEGACY_VARIABLE_QUERY_EDITOR_NAME;
|