-
Notifications
You must be signed in to change notification settings - Fork 48
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
Define tables #126
Changes from 3 commits
1f28351
dffcdc6
f9944e6
66f1372
2923a5d
93e1d39
f775a6e
a604984
02f6baf
6bc5ad6
aa03a8d
b19e07d
3aa3948
e615ec8
ccfa0f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
|
|
||
| import React, { useState, useEffect } from "react"; | ||
| import { EuiIcon, EuiTreeView } from "@elastic/eui"; | ||
| import _ from 'lodash'; | ||
| import { CoreStart } from '../../../../../src/core/public'; | ||
|
|
||
| interface CustomView { | ||
| http: CoreStart['http'] | ||
| } | ||
|
|
||
| export const TableView = ({ http }: CustomView) => { | ||
| const [tablenames, setTablenames] = useState<string[]>([]); | ||
| const [selectedNode, setSelectedNode] = useState<string | null>(null); | ||
| const [childData, setChildData] = useState<string[]>([]); | ||
| const [selectedChildNode, setSelectedChildNode] = useState<string | null>(null); | ||
| const [indexData, setIndexedData] = useState<string[]>([]); | ||
|
|
||
| const getSidebarContent = () => { | ||
| const query = { query: `SHOW tables LIKE '%';` } | ||
| http | ||
| .post(`../api/sql_console/sqlquery`, { | ||
|
sumukhswamy marked this conversation as resolved.
Outdated
|
||
| body: JSON.stringify(query), | ||
| }) | ||
| .then((res) => { | ||
| const responseObj = res.data.resp | ||
| ? JSON.parse(res.data.resp) | ||
| : ''; | ||
| const datarows: any[][] = _.get(responseObj, 'datarows'); | ||
| const fields = datarows.map((data) => { | ||
| return data[2] | ||
| }) | ||
| setTablenames(fields) | ||
| }) | ||
| .catch((err) => { | ||
| console.error(err); | ||
|
Member
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. should user be notified?
Member
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. if there is an error in the query, will there be a visual indication besides the console message?
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. this is for the side bar, so here will be no visual indication, this is to list the datasources he has available
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. also for #126 (comment) i have made the changes and spoken to Derek about it
Member
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.
do we expect this to fail often? my concern is for example user accidentally deleted sql plugin, and workbench can't get the list of datasources but user doesn't know why
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. oh okay , will add cod to show error if it occurs
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. have added an error message for handling missing data |
||
| }); | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
|
|
||
| getSidebarContent(); | ||
| }, []); | ||
|
|
||
| const handleNodeClick = (nodeLabel: string) => { | ||
|
|
||
| // // will update after new query | ||
| // const query = { query: `SHOW tables LIKE '%';` } | ||
| // http | ||
| // .post(`../api/sql_console/sqlquery`, { | ||
| // body: JSON.stringify(query), | ||
| // }) | ||
| // .then((res) => { | ||
| // const responseObj = res.data.resp | ||
| // ? JSON.parse(res.data.resp) | ||
| // : ''; | ||
| // const datarows: any[][] = _.get(responseObj, 'datarows'); | ||
| // const fields = datarows.map((data) => { | ||
| // return data[2] | ||
| // }) | ||
| // setChildData(fields) | ||
| // }) | ||
| // .catch((err) => { | ||
| // console.error(err); | ||
| // }); | ||
|
sumukhswamy marked this conversation as resolved.
Outdated
|
||
|
|
||
| const newData = ["Child 1", "Child 2", "Child 3"]; | ||
| setChildData(newData); | ||
| setSelectedNode(nodeLabel); | ||
| }; | ||
|
|
||
| const handleChildClick = (nodeLabel1: string) => { | ||
|
|
||
| // will update after new query | ||
| // const query = { query: `SHOW tables LIKE '%';` } | ||
| // http | ||
| // .post(`../api/sql_console/sqlquery`, { | ||
| // body: JSON.stringify(query), | ||
| // }) | ||
| // .then((res) => { | ||
| // const responseObj = res.data.resp | ||
| // ? JSON.parse(res.data.resp) | ||
| // : ''; | ||
| // const datarows: any[][] = _.get(responseObj, 'datarows'); | ||
| // const fields = datarows.map((data) => { | ||
| // return data[2] | ||
| // }) | ||
| // setIndexdData(fields) | ||
| // }) | ||
| // .catch((err) => { | ||
| // console.error(err); | ||
| // }); | ||
|
sumukhswamy marked this conversation as resolved.
Outdated
|
||
|
|
||
| const newData1 = ["Child 1", "Child 2", "Child 3"]; | ||
| setIndexedData(newData1); | ||
| setSelectedChildNode(nodeLabel1); | ||
| }; | ||
|
|
||
|
|
||
| const treeData = tablenames.map((element, index) => ({ | ||
| label: element, | ||
| icon: <EuiIcon type='database' size="m" />, | ||
| id: 'element_' + index, | ||
| callback: () => handleNodeClick(element), | ||
| isSelectable: true, | ||
| isExpanded: true, | ||
| children: selectedNode === element ? childData.map(child => ({ | ||
| label: child, | ||
| id: `${element}_${child}`, | ||
| icon: <EuiIcon type='tableDensityCompact' size="s" />, | ||
| callback: () => handleChildClick(child), | ||
| sSelectable: true, | ||
| isExpanded: true, | ||
| children: selectedChildNode === element ? indexData.map(child => ({ | ||
| label: child, | ||
| id: `${element}_${child}`, | ||
| icon: <EuiIcon type='bolt' size="s" /> | ||
| })):undefined, | ||
| })) : undefined, | ||
| })); | ||
| console.log(treeData) | ||
|
sumukhswamy marked this conversation as resolved.
Outdated
|
||
|
|
||
| return ( | ||
| <> | ||
| <EuiTreeView | ||
| aria-label="Sample Folder Tree" | ||
| items={treeData} | ||
| aria-labelledby="" | ||
| /> | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.