import _ from 'lodash'; import React from 'react'; // @ts-ignore import PluginPrism from 'slate-prism'; // @ts-ignore import Prism from 'prismjs'; // dom also includes Element polyfills import QueryField from 'app/features/explore/QueryField'; import { ExploreQueryFieldProps } from '@grafana/ui'; import { ElasticDatasource } from '../datasource'; import { ElasticsearchOptions, ElasticsearchQuery } from '../types'; interface Props extends ExploreQueryFieldProps {} interface State { syntaxLoaded: boolean; } class ElasticsearchQueryField extends React.PureComponent { plugins: any[]; constructor(props: Props, context: React.Context) { super(props, context); this.plugins = [ PluginPrism({ 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 { queryResponse, query } = this.props; const { syntaxLoaded } = this.state; return ( <>
{queryResponse && queryResponse.error ? (
{queryResponse.error.message}
) : null} ); } } export default ElasticsearchQueryField;