mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 10:03:33 -06:00
* Chore: move constants to own file * Chore: moves safe* functions to grafana/data * Chore: moves safe* functions to grafana/data * Chore: adds VariableQueryEditorProps and deprecates VariableQueryProps * Chore: remove getDefaultVariableAdapters function * Chore: moves transaction status to types * Chore: fix tests that do not initialise TemplateSrv * Chore: change space when stringifying * Chore: revert safe* func move * Chore: remove circular dependency in Explore utils
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import React, { FC, useCallback, useState } from 'react';
|
|
import { selectors } from '@grafana/e2e-selectors';
|
|
import { useStyles } from '@grafana/ui';
|
|
import { GrafanaTheme } from '@grafana/data';
|
|
import { css } from '@emotion/css';
|
|
|
|
import { VariableTextAreaField } from './VariableTextAreaField';
|
|
import { VariableQueryEditorProps } from '../types';
|
|
|
|
export const LEGACY_VARIABLE_QUERY_EDITOR_NAME = 'Grafana-LegacyVariableQueryEditor';
|
|
|
|
export const LegacyVariableQueryEditor: FC<VariableQueryEditorProps> = ({ onChange, query }) => {
|
|
const styles = useStyles(getStyles);
|
|
const [value, setValue] = useState(query);
|
|
const onValueChange = (event: React.FormEvent<HTMLTextAreaElement>) => {
|
|
setValue(event.currentTarget.value);
|
|
};
|
|
|
|
const onBlur = useCallback(
|
|
(event: React.FormEvent<HTMLTextAreaElement>) => {
|
|
onChange(event.currentTarget.value, event.currentTarget.value);
|
|
},
|
|
[onChange]
|
|
);
|
|
|
|
return (
|
|
<div className={styles.container}>
|
|
<VariableTextAreaField
|
|
name="Query"
|
|
value={value}
|
|
placeholder="metric name or tags query"
|
|
width={100}
|
|
onChange={onValueChange}
|
|
onBlur={onBlur}
|
|
required
|
|
labelWidth={20}
|
|
ariaLabel={selectors.pages.Dashboard.Settings.Variables.Edit.QueryVariable.queryOptionsQueryInput}
|
|
/>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
function getStyles(theme: GrafanaTheme) {
|
|
return {
|
|
container: css`
|
|
margin-bottom: ${theme.spacing.xs};
|
|
`,
|
|
};
|
|
}
|
|
|
|
LegacyVariableQueryEditor.displayName = LEGACY_VARIABLE_QUERY_EDITOR_NAME;
|