From 1f28351dc212937eca3860aabd8a57f4a42aa4e4 Mon Sep 17 00:00:00 2001 From: sumukhswamy Date: Sat, 16 Sep 2023 16:05:01 -0700 Subject: [PATCH 1/2] added changes for sidebar Signed-off-by: sumukhswamy --- public/components/Main/main.tsx | 86 +++++++++++++++++++++++++-------- public/components/app.tsx | 2 +- 2 files changed, 67 insertions(+), 21 deletions(-) diff --git a/public/components/Main/main.tsx b/public/components/Main/main.tsx index 1b458913..4ad13a15 100644 --- a/public/components/Main/main.tsx +++ b/public/components/Main/main.tsx @@ -3,10 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { EuiButton, EuiFlexGroup, EuiFlexItem, EuiSpacer, EuiTitle } from '@elastic/eui'; +import { EuiButton, EuiFlexGroup, EuiFlexItem, EuiSpacer, EuiTitle, EuiPageSideBar ,EuiSideNav, EuiPanel, EuiPageTemplate, EuiPage, EuiPageContent, EuiPageContentBody, EuiFlexGrid, EuiSplitPanel, EuiComboBox, EuiText, EuiPagination, EuiPopover, EuiFieldSearch} from '@elastic/eui'; import { IHttpResponse } from 'angular'; import _ from 'lodash'; -import React from 'react'; +import React, { useState } from 'react'; import { ChromeBreadcrumb, CoreStart } from '../../../../../src/core/public'; import { MESSAGE_TAB_LABEL } from '../../utils/constants'; import { @@ -683,27 +683,70 @@ export class Main extends React.Component { ); } + // const [isClearable, setIsClearable] = useState(true); + + // const [value, setValue] = useState(''); + // const onChange = (e) => { + // setValue(e.target.value); + // }; + + const button = ( + + Create + + ); + return ( -
-
-
- + <> + + + + - -

Query Workbench

-
-
- - - - - - {linkTitle} - + + Data Connection + + + + + + + + + +
-
+ + + + + + + +

Query

+
+
+ + + + + + {linkTitle} + + +
{page}
@@ -746,8 +789,11 @@ export class Main extends React.Component { setIsResultFullScreen={this.setIsResultFullScreen} />
-
- + + + + + ); } } diff --git a/public/components/app.tsx b/public/components/app.tsx index 44f09b5f..5e584c63 100644 --- a/public/components/app.tsx +++ b/public/components/app.tsx @@ -30,7 +30,7 @@ export const WorkbenchApp = ({ basename, notifications, http, navigation, chrome
- + Date: Wed, 20 Sep 2023 23:23:04 -0700 Subject: [PATCH 2/2] added side bar with tables indexed Signed-off-by: sumukhswamy --- public/components/Main/main.tsx | 166 ++++++++++++++++-------- public/components/SQLPage/TableView.tsx | 36 +++++ 2 files changed, 148 insertions(+), 54 deletions(-) create mode 100644 public/components/SQLPage/TableView.tsx diff --git a/public/components/Main/main.tsx b/public/components/Main/main.tsx index 4ad13a15..54f120f1 100644 --- a/public/components/Main/main.tsx +++ b/public/components/Main/main.tsx @@ -6,7 +6,7 @@ import { EuiButton, EuiFlexGroup, EuiFlexItem, EuiSpacer, EuiTitle, EuiPageSideBar ,EuiSideNav, EuiPanel, EuiPageTemplate, EuiPage, EuiPageContent, EuiPageContentBody, EuiFlexGrid, EuiSplitPanel, EuiComboBox, EuiText, EuiPagination, EuiPopover, EuiFieldSearch} from '@elastic/eui'; import { IHttpResponse } from 'angular'; import _ from 'lodash'; -import React, { useState } from 'react'; +import React from 'react'; import { ChromeBreadcrumb, CoreStart } from '../../../../../src/core/public'; import { MESSAGE_TAB_LABEL } from '../../utils/constants'; import { @@ -20,6 +20,7 @@ import { PPLPage } from '../PPLPage/PPLPage'; import Switch from '../QueryLanguageSwitch/Switch'; import QueryResults from '../QueryResults/QueryResults'; import { SQLPage } from '../SQLPage/SQLPage'; +import {TableView} from '../SQLPage/TableView' interface ResponseData { ok: boolean; @@ -64,7 +65,7 @@ export type DataRow = { rowId: number; data: { [key: string]: any }; }; - + interface MainProps { httpClient: CoreStart['http']; setBreadcrumbs: (newBreadcrumbs: ChromeBreadcrumb[]) => void; @@ -87,6 +88,7 @@ interface MainState { itemIdToExpandedRowMap: ItemIdToExpandedRowMap; messages: Array; isResultFullScreen: boolean; + tablenames: string[] } const SUCCESS_MESSAGE = 'Success'; @@ -99,6 +101,29 @@ const errorQueryResponse = (queryResultResponseDetail: any) => { return errorMessage; }; +function getQueryResultsForSidebar(queryResults: ResponseDetail[]){ + let fields; + queryResults.map((queries: ResponseDetail) => { + if (!queries.fulfilled) { + return { + fulfilled: queries.fulfilled, + errorMessage: errorQueryResponse(queries), + }; + } else { + const responseObj = queries.data + ? JSON.parse(queries.data) + : ''; + + const schema: object[] = _.get(responseObj, 'schema'); + const datarows: any[][] = _.get(responseObj, 'datarows'); + fields = datarows.map((data)=>{ + return data[2] + }) + } + }) + return fields +} + export function getQueryResultsForTable( queryResults: ResponseDetail[] ): ResponseDetail[] { @@ -218,12 +243,13 @@ export class Main extends React.Component { itemIdToExpandedRowMap: {}, messages: [], isResultFullScreen: false, + tablenames : [] }; - this.httpClient = this.props.httpClient; this.updateSQLQueries = _.debounce(this.updateSQLQueries, 250).bind(this); this.updatePPLQueries = _.debounce(this.updatePPLQueries, 250).bind(this); this.setIsResultFullScreen = this.setIsResultFullScreen.bind(this); + this.onRunSidebar() } componentDidMount() { @@ -335,6 +361,44 @@ export class Main extends React.Component { }); } + onRunSidebar = (): void => { + let values :string[]; + const queries: string[] = getQueries(`SHOW tables LIKE '%';`) + if (queries.length > 0) { + let endpoint = '../api/sql_console/sqlquery'; + const responsePromise = Promise.all( + queries.map((query: string) => + this.httpClient + .post(endpoint, { body: JSON.stringify({ query }) }) + .catch((error: any) => { + this.setState({ + messages: [ + { + text: error.message, + className: 'error-message', + }, + ], + }); + }) + ) + ); + Promise.all([responsePromise]).then(([response]) => { + const results: ResponseDetail[] = response.map((response) => + this.processQueryResponse(response as IHttpResponse) + ); + values = getQueryResultsForSidebar(results); + this.setState( + { + tablenames : values + }, + () => console.log('Successfully updated the states') + ); // added callback function to handle async issues + + return values + }); + } + } + onRun = (queriesString: string): void => { const queries: string[] = getQueries(queriesString); const language = this.state.language; @@ -617,6 +681,7 @@ export class Main extends React.Component { let linkTitle; if (this.state.language == 'SQL') { + // this.onRunSidebar() page = ( {
); } - // const [isClearable, setIsClearable] = useState(true); - - // const [value, setValue] = useState(''); - // const onChange = (e) => { - // setValue(e.target.value); - // }; - - const button = ( - - Create - - ); - return ( <> + + + + + Data Connection + + + + + + + + + + {linkTitle} + + + + + {(this.state.language=='SQL')? - - - Data Connection - - - - - - - - + + + Create + + + + + + + + + - - + : null} - - - -

Query

-
-
- - - - - - {linkTitle} - - -
+ +
{page}
diff --git a/public/components/SQLPage/TableView.tsx b/public/components/SQLPage/TableView.tsx new file mode 100644 index 00000000..0660c3cd --- /dev/null +++ b/public/components/SQLPage/TableView.tsx @@ -0,0 +1,36 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + + +import React from "react"; +import { + EuiIcon, + EuiTreeView +} from "@elastic/eui"; +import _ from 'lodash'; + +export const TableView =({tablenames}) =>{ + let treeData; + if(tablenames.length >0){ + treeData = tablenames.map((element,index)=>({ + label: element, + icon: , + id:'element_'+index + })) + } + return ( + <> + {tablenames.length>0? + + :null} + + ) + +} +