mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 19:54:10 -06:00
Templating: Made default template variable query editor field a text area with dynamic automatic height (#20288)
This commit is contained in:
parent
8430a182ef
commit
dd6f5efabe
@ -1,5 +1,4 @@
|
|||||||
import React, { PureComponent } from 'react';
|
import React, { PureComponent } from 'react';
|
||||||
import { Input } from '@grafana/ui';
|
|
||||||
import { VariableQueryProps } from 'app/types/plugins';
|
import { VariableQueryProps } from 'app/types/plugins';
|
||||||
|
|
||||||
export default class DefaultVariableQueryEditor extends PureComponent<VariableQueryProps, any> {
|
export default class DefaultVariableQueryEditor extends PureComponent<VariableQueryProps, any> {
|
||||||
@ -8,20 +7,30 @@ export default class DefaultVariableQueryEditor extends PureComponent<VariableQu
|
|||||||
this.state = { value: props.query };
|
this.state = { value: props.query };
|
||||||
}
|
}
|
||||||
|
|
||||||
onChange = (event: React.FormEvent<HTMLInputElement>) => {
|
onChange = (event: React.FormEvent<HTMLTextAreaElement>) => {
|
||||||
this.setState({ value: event.currentTarget.value });
|
this.setState({ value: event.currentTarget.value });
|
||||||
};
|
};
|
||||||
|
|
||||||
onBlur = (event: React.FormEvent<HTMLInputElement>) => {
|
onBlur = (event: React.FormEvent<HTMLTextAreaElement>) => {
|
||||||
this.props.onChange(event.currentTarget.value, event.currentTarget.value);
|
this.props.onChange(event.currentTarget.value, event.currentTarget.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
getLineCount() {
|
||||||
|
const { value } = this.state;
|
||||||
|
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
return value.split('\n').length;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="gf-form">
|
<div className="gf-form">
|
||||||
<span className="gf-form-label width-10">Query</span>
|
<span className="gf-form-label width-10">Query</span>
|
||||||
<Input
|
<textarea
|
||||||
type="text"
|
rows={this.getLineCount()}
|
||||||
className="gf-form-input"
|
className="gf-form-input"
|
||||||
value={this.state.value}
|
value={this.state.value}
|
||||||
onChange={this.onChange}
|
onChange={this.onChange}
|
||||||
|
Loading…
Reference in New Issue
Block a user