Files
Lukas Siatka 688283a5cc Explore: adds QueryRowErrors component, moves error display to QueryRow (#22438)
* Explore: adds QueryRowErrors component

* Explore: updates QueryRow to use QueryRowErrors component

* Explore: updates PromQueryField to remove error render

* Explore: updates Elastic query field  to remove error render

* Explore: updates LokiQueryFieldForm to remove error render

* Explore: updates QueryRow component - brings back passing errors down

* Explore: removes QueryRowErrors component

* Explore: updates ErrorContainer component - moves out data filtering

* Explore: updates QueryRow component - changes QueryRowErrors to ErrorContainer

* Explore: updates Explore component - adds error filtering for ErrorContainer

* Explore: updates ErrorContainer and adds a basic test for it

* Explore: updates Explore component props name and adds a basic render test

* Explore: adds snapshots for Explore and ErrorContainer

* Explore: adds a test for error render

* Explore: adds a comment to Explore component explaining the way we filter non-query-row-specific errors

* Explore: adds getFirstNonQueryRowSpecificError method to explore utilities

* Explore: extracts getFirstNonQueryRowSpecificError method and slightly refactors Explore component

* Explore: updates Explore component tests to cover non-query-row-specific errors
2020-03-11 10:01:58 +01:00

86 lines
2.2 KiB
TypeScript

import _ from 'lodash';
import React from 'react';
import { QueryField, SlatePrism } from '@grafana/ui';
import { ExploreQueryFieldProps } from '@grafana/data';
import { ElasticDatasource } from '../datasource';
import { ElasticsearchOptions, ElasticsearchQuery } from '../types';
interface Props extends ExploreQueryFieldProps<ElasticDatasource, ElasticsearchQuery, ElasticsearchOptions> {}
interface State {
syntaxLoaded: boolean;
}
class ElasticsearchQueryField extends React.PureComponent<Props, State> {
plugins: any[];
constructor(props: Props, context: React.Context<any>) {
super(props, context);
this.plugins = [
SlatePrism({
onlyIn: (node: any) => node.type === 'code_block',
getSyntax: (node: any) => 'lucene',
}),
];
this.state = {
syntaxLoaded: false,
};
}
componentDidMount() {
if (!this.props.query.isLogsQuery) {
this.onChangeQuery('', true);
}
}
componentWillUnmount() {}
componentDidUpdate(prevProps: Props) {
// if query changed from the outside (i.e. cleared via explore toolbar)
if (!this.props.query.isLogsQuery) {
this.onChangeQuery('', true);
}
}
onChangeQuery = (value: string, override?: boolean) => {
// Send text change to parent
const { query, onChange, onRunQuery } = this.props;
if (onChange) {
const nextQuery: ElasticsearchQuery = { ...query, query: value, isLogsQuery: true };
onChange(nextQuery);
if (override && onRunQuery) {
onRunQuery();
}
}
};
render() {
const { query } = this.props;
const { syntaxLoaded } = this.state;
return (
<>
<div className="gf-form-inline gf-form-inline--nowrap">
<div className="gf-form gf-form--grow flex-shrink-1">
<QueryField
additionalPlugins={this.plugins}
query={query.query}
onChange={this.onChangeQuery}
onRunQuery={this.props.onRunQuery}
placeholder="Enter a Lucene query"
portalOrigin="elasticsearch"
syntaxLoaded={syntaxLoaded}
/>
</div>
</div>
</>
);
}
}
export default ElasticsearchQueryField;