diff --git a/public/components/Main/main.tsx b/public/components/Main/main.tsx index 1b458913..54f120f1 100644 --- a/public/components/Main/main.tsx +++ b/public/components/Main/main.tsx @@ -3,7 +3,7 @@ * 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'; @@ -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 = ( { } return ( -
-
-
+ <> + + + + + Data Connection + + + + + + + + + + {linkTitle} + + + + + + {(this.state.language=='SQL')? + + + + + + + Create + + + + + + + + + + + + + : null} + + - - -

Query Workbench

-
-
- - - - - - {linkTitle} - -
-
{page}
@@ -746,8 +847,11 @@ export class Main extends React.Component { setIsResultFullScreen={this.setIsResultFullScreen} />
-
- + + + + + ); } } 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} + + ) + +} + 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
- +