/* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ import React from "react"; import { EuiPanel, EuiButton, EuiFlexGroup, EuiFlexItem, EuiText, EuiCodeEditor, EuiSpacer, EuiCodeBlock, EuiModal, EuiModalBody, EuiModalFooter, EuiModalHeader, EuiModalHeaderTitle, EuiOverlayMask, } from "@elastic/eui"; import { ResponseDetail, TranslateResult } from '../Main/main'; import _ from 'lodash'; interface PPLPageProps { onRun: (query: string) => void, onTranslate: (query: string) => void, onClear: () => void, updatePPLQueries: (query: string) => void, pplQuery: string, pplTranslations: ResponseDetail[] } interface PPLPageState { pplQuery: string, translation: string, isModalVisible: boolean } export class PPLPage extends React.Component { constructor(props: PPLPageProps) { super(props); this.state = { pplQuery: this.props.pplQuery, translation: "", isModalVisible: false }; } setIsModalVisible(visible: boolean): void { this.setState({ isModalVisible: visible }) } render() { const closeModal = () => this.setIsModalVisible(false); const showModal = () => this.setIsModalVisible(true); const pplTranslationsNotEmpty = () => { if (this.props.pplTranslations.length > 0) { return this.props.pplTranslations[0].fulfilled; } return false; } const explainContent = pplTranslationsNotEmpty() ? this.props.pplTranslations.map((queryTranslation: any) => JSON.stringify(queryTranslation.data, null, 2)).join("\n") : 'This query is not explainable.'; let modal; if (this.state.isModalVisible) { modal = ( Explain {explainContent} Close ); } return (

Query editor

this.props.onRun(this.props.pplQuery)} > Run { this.props.updatePPLQueries(""); this.props.onClear(); }} > Clear this.props.onTranslate(this.props.pplQuery) } > Explain {modal}
) } }