Loki query editor is starting to work, had to make changes to explore query field in order to update query from the outside without unmount between

This commit is contained in:
Torkel Ödegaard
2019-01-23 17:44:22 +01:00
parent 90787a5299
commit 02083d71c8
12 changed files with 94 additions and 30 deletions

View File

@@ -0,0 +1,47 @@
// Libraries
import React, { PureComponent } from 'react';
// Types
import { QueryEditorProps } from '@grafana/ui/src/types';
import { LokiDatasource } from '../datasource';
import { LokiQuery } from '../types';
import { LokiQueryField } from './LokiQueryField';
type Props = QueryEditorProps<LokiDatasource, LokiQuery>;
interface State {
query: LokiQuery;
}
export class LokiQueryEditor extends PureComponent<Props> {
state: State = {
query: this.props.query
};
onRunQuery = () => {
const { query } = this.state;
this.props.onChange(query);
this.props.onRunQuery();
};
onFieldChange = (query: LokiQuery, override?) => {
this.setState({
query: query
});
};
render() {
const { query } = this.state;
const { datasource } = this.props;
return (
<div>
<LokiQueryField datasource={datasource} initialQuery={query} onQueryChange={this.onFieldChange} onPressEnter={this.onRunQuery} />
</div>
);
}
}
export default LokiQueryEditor;