-
Notifications
You must be signed in to change notification settings - Fork 47
Define tables #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Define tables #126
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1f28351
added changes for sidebar
sumukhswamy dffcdc6
added side bar with tables indexed
sumukhswamy f9944e6
added dynamic element for tree view, addressed pr comments
sumukhswamy 66f1372
made a few design and panel changes, addressed pr comments
sumukhswamy 2923a5d
changed the constants file
sumukhswamy 93e1d39
added changes for search bar removal, pr comments
sumukhswamy f775a6e
readded console.log
sumukhswamy a604984
updated test suites, removed search field
sumukhswamy 02f6baf
added changes for Data connection and combo box
sumukhswamy 6bc5ad6
updated mock for http query
sumukhswamy aa03a8d
updated mock template name in tests
sumukhswamy b19e07d
addressed pr comments
sumukhswamy 3aa3948
addressed more comments
sumukhswamy e615ec8
added error message for sidebar
sumukhswamy ccfa0f5
updated snapshots
sumukhswamy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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' | ||
|
sumukhswamy marked this conversation as resolved.
Outdated
|
||
|
|
||
| interface ResponseData { | ||
| ok: boolean; | ||
|
|
@@ -64,7 +65,7 @@ export type DataRow = { | |
| rowId: number; | ||
| data: { [key: string]: any }; | ||
| }; | ||
|
|
||
|
sumukhswamy marked this conversation as resolved.
Outdated
|
||
| interface MainProps { | ||
| httpClient: CoreStart['http']; | ||
| setBreadcrumbs: (newBreadcrumbs: ChromeBreadcrumb[]) => void; | ||
|
|
@@ -87,6 +88,7 @@ interface MainState { | |
| itemIdToExpandedRowMap: ItemIdToExpandedRowMap; | ||
| messages: Array<QueryMessage>; | ||
| isResultFullScreen: boolean; | ||
| tablenames: string[] | ||
| } | ||
|
|
||
| const SUCCESS_MESSAGE = 'Success'; | ||
|
|
@@ -99,6 +101,29 @@ const errorQueryResponse = (queryResultResponseDetail: any) => { | |
| return errorMessage; | ||
| }; | ||
|
|
||
| function getQueryResultsForSidebar(queryResults: ResponseDetail<string>[]){ | ||
| let fields; | ||
| queryResults.map((queries: ResponseDetail<string>) => { | ||
| 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'); | ||
|
sumukhswamy marked this conversation as resolved.
Outdated
|
||
| const datarows: any[][] = _.get(responseObj, 'datarows'); | ||
| fields = datarows.map((data)=>{ | ||
| return data[2] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the third element?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }) | ||
| } | ||
| }) | ||
| return fields | ||
| } | ||
|
|
||
| export function getQueryResultsForTable( | ||
| queryResults: ResponseDetail<string>[] | ||
| ): ResponseDetail<QueryResult>[] { | ||
|
|
@@ -218,12 +243,13 @@ export class Main extends React.Component<MainProps, MainState> { | |
| 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<MainProps, MainState> { | |
| }); | ||
| } | ||
|
|
||
| onRunSidebar = (): void => { | ||
| let values :string[]; | ||
| const queries: string[] = getQueries(`SHOW tables LIKE '%';`) | ||
| if (queries.length > 0) { | ||
|
sumukhswamy marked this conversation as resolved.
Outdated
|
||
| let endpoint = '../api/sql_console/sqlquery'; | ||
|
sumukhswamy marked this conversation as resolved.
Outdated
|
||
| 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<string>[] = response.map((response) => | ||
| this.processQueryResponse(response as IHttpResponse<ResponseData>) | ||
| ); | ||
| values = getQueryResultsForSidebar(results); | ||
| this.setState( | ||
| { | ||
| tablenames : values | ||
| }, | ||
| () => console.log('Successfully updated the states') | ||
|
sumukhswamy marked this conversation as resolved.
Outdated
|
||
| ); // 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<MainProps, MainState> { | |
| let linkTitle; | ||
|
|
||
| if (this.state.language == 'SQL') { | ||
| // this.onRunSidebar() | ||
|
sumukhswamy marked this conversation as resolved.
Outdated
|
||
| page = ( | ||
| <SQLPage | ||
| onRun={this.onRun} | ||
|
|
@@ -685,25 +750,61 @@ export class Main extends React.Component<MainProps, MainState> { | |
| } | ||
|
|
||
| return ( | ||
| <div> | ||
| <div className="sql-console-query-container"> | ||
| <div className="query-language-switch"> | ||
| <> | ||
| <EuiPanel> | ||
| <EuiFlexGroup direction='row' alignItems='center'> | ||
| <EuiFlexItem> | ||
| <EuiText> | ||
| Data Connection | ||
| </EuiText> | ||
| <EuiComboBox | ||
| placeholder='Connection Name' | ||
| /> | ||
| <EuiSpacer/> | ||
| </EuiFlexItem> | ||
| <EuiFlexItem grow={false}> | ||
| <Switch onChange={this.onChange} language={this.state.language} /> | ||
| </EuiFlexItem> | ||
| <EuiFlexItem grow={false}> | ||
| <EuiButton href={link} target="_blank" iconType="popout" iconSide="right"> | ||
| {linkTitle} | ||
| </EuiButton> | ||
|
sumukhswamy marked this conversation as resolved.
|
||
| </EuiFlexItem> | ||
| </EuiFlexGroup> | ||
| </EuiPanel> | ||
| <EuiPage paddingSize='none'> | ||
| {(this.state.language=='SQL')? | ||
| <EuiPanel className={`col-md-3`}> | ||
| <EuiPageSideBar > | ||
| <EuiFlexGroup direction="column"> | ||
| <EuiFlexItem> | ||
| <EuiFlexItem grow={1}> | ||
| <EuiButton | ||
| iconType="arrowDown" | ||
| iconSide="right" | ||
| fullWidth | ||
| > | ||
| Create | ||
| </EuiButton> | ||
| </EuiFlexItem> | ||
| <EuiSpacer/> | ||
| <EuiFlexItem> | ||
| <EuiFieldSearch | ||
| placeholder="Search this" | ||
| /> | ||
| </EuiFlexItem> | ||
| <EuiSpacer/> | ||
| <TableView | ||
| tablenames = {this.state.tablenames}/> | ||
| <EuiSpacer/> | ||
| </EuiFlexItem> | ||
| </EuiFlexGroup> | ||
| </EuiPageSideBar> | ||
| </EuiPanel> : null} | ||
| <EuiPageContent> | ||
| <EuiPageContentBody> | ||
| <EuiFlexGroup alignItems="center"> | ||
| <EuiFlexItem> | ||
| <EuiTitle size="l"> | ||
| <h1>Query Workbench</h1> | ||
| </EuiTitle> | ||
| </EuiFlexItem> | ||
| <EuiFlexItem grow={false}> | ||
| <Switch onChange={this.onChange} language={this.state.language} /> | ||
| </EuiFlexItem> | ||
| <EuiFlexItem grow={false}> | ||
| <EuiButton href={link} target="_blank" iconType="popout" iconSide="right"> | ||
| {linkTitle} | ||
| </EuiButton> | ||
| </EuiFlexItem> | ||
| </EuiFlexGroup> | ||
| </div> | ||
| <EuiSpacer size="l" /> | ||
| <div>{page}</div> | ||
|
|
||
|
|
@@ -746,8 +847,11 @@ export class Main extends React.Component<MainProps, MainState> { | |
| setIsResultFullScreen={this.setIsResultFullScreen} | ||
| /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </EuiPageContentBody> | ||
| </EuiPageContent> | ||
| </EuiPage> | ||
| </> | ||
|
|
||
| ); | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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: <EuiIcon type='tableDensityNormal' size="m" /> , | ||
| id:'element_'+index | ||
| })) | ||
| } | ||
| return ( | ||
| <> | ||
| {tablenames.length>0? | ||
| <EuiTreeView | ||
| aria-label = "Sample Folder Tree" | ||
| items = {treeData} | ||
| aria-labelledby="" | ||
| /> | ||
| :null} | ||
| </> | ||
|
sumukhswamy marked this conversation as resolved.
Outdated
|
||
| ) | ||
|
|
||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Uh oh!
There was an error while loading. Please reload this page.