From 188d57e73054eb33164456f6ead4fbf98afeb873 Mon Sep 17 00:00:00 2001 From: Paul Sebastian Date: Wed, 4 Oct 2023 11:19:09 -0700 Subject: [PATCH] disable buttons while running async query (#136) * disable most buttons Signed-off-by: Paul Sebastian * code editor read only Signed-off-by: Paul Sebastian * disabled accelerate button Signed-off-by: Paul Sebastian --------- Signed-off-by: Paul Sebastian --- public/components/Main/main.tsx | 9 ++- public/components/PPLPage/PPLPage.tsx | 11 ++- .../components/QueryLanguageSwitch/Switch.tsx | 71 ++++++++++--------- public/components/SQLPage/DataSelect.tsx | 4 +- public/components/SQLPage/SQLPage.tsx | 12 +++- 5 files changed, 65 insertions(+), 42 deletions(-) diff --git a/public/components/Main/main.tsx b/public/components/Main/main.tsx index 789e8404..d173e223 100644 --- a/public/components/Main/main.tsx +++ b/public/components/Main/main.tsx @@ -423,7 +423,7 @@ export class Main extends React.Component { lang: language, query: query, datasource: this.state.selectedDatasource[0].label, - }), // TODO: dynamically datasource when accurate + }), }) .catch((error: any) => { this.setState({ @@ -891,11 +891,16 @@ export class Main extends React.Component { http={this.httpClient} onSelect={this.handleDataSelect} urlDataSource={this.props.urlDataSource} + asyncLoading={this.state.asyncLoading} /> - + diff --git a/public/components/PPLPage/PPLPage.tsx b/public/components/PPLPage/PPLPage.tsx index 69530e8f..4130bea7 100644 --- a/public/components/PPLPage/PPLPage.tsx +++ b/public/components/PPLPage/PPLPage.tsx @@ -117,6 +117,7 @@ export class PPLPage extends React.Component { showGutter: false, }} aria-label="Code Editor" + isReadOnly={this.props.asyncLoading} /> @@ -140,10 +141,16 @@ export class PPLPage extends React.Component { this.props.onClear(); }} > - Clear + + Clear + this.props.onTranslate(this.props.pplQuery)}> - + Explain {modal} diff --git a/public/components/QueryLanguageSwitch/Switch.tsx b/public/components/QueryLanguageSwitch/Switch.tsx index 3f3b7aad..2311de84 100644 --- a/public/components/QueryLanguageSwitch/Switch.tsx +++ b/public/components/QueryLanguageSwitch/Switch.tsx @@ -3,53 +3,54 @@ * SPDX-License-Identifier: Apache-2.0 */ - -import React from "react"; -import _ from "lodash"; -import { EuiButtonGroup } from "@elastic/eui"; +import React from 'react'; +import _ from 'lodash'; +import { EuiButtonGroup } from '@elastic/eui'; // @ts-ignore -import { htmlIdGenerator } from "@elastic/eui/lib/services"; +import { htmlIdGenerator } from '@elastic/eui/lib/services'; interface SwitchProps { - onChange: (id: string, value?: any) => void; - language: string; + onChange: (id: string, value?: any) => void; + language: string; + asyncLoading: boolean; } interface SwitchState { - // language: string + // language: string } const toggleButtons = [ - { - id: 'SQL', - label: 'SQL', - }, - { - id: 'PPL', - label: 'PPL', - }, + { + id: 'SQL', + label: 'SQL', + }, + { + id: 'PPL', + label: 'PPL', + }, ]; class Switch extends React.Component { - constructor(props: SwitchProps) { - super(props); - this.state = { - language: 'SQL' - }; - } - - render() { - - return ( - this.props.onChange(id)} - idSelected={this.props.language} - buttonSize="m" - /> - ) - } + constructor(props: SwitchProps) { + super(props); + this.state = { + language: 'SQL', + }; + } + + render() { + return ( + this.props.onChange(id)} + idSelected={this.props.language} + buttonSize="m" + isDisabled={this.props.asyncLoading} + /> + ); + } } export default Switch; diff --git a/public/components/SQLPage/DataSelect.tsx b/public/components/SQLPage/DataSelect.tsx index 0fe25e03..e2448b69 100644 --- a/public/components/SQLPage/DataSelect.tsx +++ b/public/components/SQLPage/DataSelect.tsx @@ -11,9 +11,10 @@ interface CustomView { http: CoreStart['http']; onSelect: (selectedItems: []) => void; urlDataSource: string; + asyncLoading: boolean; } -export const DataSelect = ({ http, onSelect, urlDataSource }: CustomView) => { +export const DataSelect = ({ http, onSelect, urlDataSource, asyncLoading }: CustomView) => { const [selectedOptions, setSelectedOptions] = useState([ { label: 'OpenSearch' }, ]); @@ -84,6 +85,7 @@ export const DataSelect = ({ http, onSelect, urlDataSource }: CustomView) => { options={options} selectedOptions={selectedOptions} onChange={(selectedItems) => handleSelectionChange(selectedItems)} + isDisabled={asyncLoading} /> ); }; diff --git a/public/components/SQLPage/SQLPage.tsx b/public/components/SQLPage/SQLPage.tsx index 6deab093..6d6436c8 100644 --- a/public/components/SQLPage/SQLPage.tsx +++ b/public/components/SQLPage/SQLPage.tsx @@ -141,6 +141,7 @@ export class SQLPage extends React.Component { enableLiveAutocompletion: true, }} aria-label="Code Editor" + isReadOnly={this.props.asyncLoading} /> @@ -162,13 +163,19 @@ export class SQLPage extends React.Component { this.props.onClear(); }} > - Clear + + Clear + this.props.onTranslate(this.props.sqlQuery)} > - + Explain @@ -181,6 +188,7 @@ export class SQLPage extends React.Component { fill={true} className="sql-accelerate-button" onClick={this.setAccelerationFlyout} + isDisabled={this.props.asyncLoading} > Accelerate Table