Templating: Made default template variable query editor field a text area with dynamic automatic height (#20288)

This commit is contained in:
Torkel Ödegaard 2019-11-11 10:04:22 +01:00 committed by GitHub
parent 8430a182ef
commit dd6f5efabe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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}