diff --git a/public/components/SQLPage/TableView.tsx b/public/components/SQLPage/TableView.tsx index 328a4330..d1d84736 100644 --- a/public/components/SQLPage/TableView.tsx +++ b/public/components/SQLPage/TableView.tsx @@ -3,106 +3,128 @@ * SPDX-License-Identifier: Apache-2.0 */ - -import React, { useState, useEffect } from "react"; -import { EuiEmptyPrompt, EuiIcon, EuiTreeView } from "@elastic/eui"; +import { EuiEmptyPrompt, EuiIcon, EuiTreeView } from '@elastic/eui'; import _ from 'lodash'; +import React, { useEffect, useState } from 'react'; import { CoreStart } from '../../../../../src/core/public'; -import { ON_LOAD_QUERY } from "../../../common/constants"; +import { ON_LOAD_QUERY } from '../../../common/constants'; +import { AccelerationIndexFlyout } from './acceleration_index_flyout'; interface CustomView { - http: CoreStart['http'], - dataConnection: string + http: CoreStart['http']; + dataConnection: string; } export const TableView = ({ http, dataConnection }: CustomView) => { - const [tablenames, setTablenames] = useState([]); - const [selectedNode, setSelectedNode] = useState(null); - const [childData, setChildData] = useState([]); - const [selectedChildNode, setSelectedChildNode] = useState(null); - const [indexData, setIndexedData] = useState([]); - - const getSidebarContent = () => { - const query = { query: ON_LOAD_QUERY } - 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] - }) - setTablenames(fields) - }) - .catch((err) => { - console.error(err); - }); - }; - - useEffect(() => { - - getSidebarContent(); - }, []); - - const handleNodeClick = (nodeLabel: string) => { - - // // will update after new query - - const newData = ["Child 1", "Child 2", "Child 3"]; - setChildData(newData); - setSelectedNode(nodeLabel); - }; - - const handleChildClick = (nodeLabel1: string) => { - - // will update after new query - - const newData1 = ["Child 4", "Child 5", "Child 6"]; - setIndexedData(newData1); - setSelectedChildNode(nodeLabel1); - }; - - - const treeData = tablenames.map((element, index) => ({ - label: element, - icon: , - id: 'element_' + index, - callback: () => handleNodeClick(element), - isSelectable: true, - isExpanded: true, - children: dataConnection === 'S3' && selectedNode === element ? childData.map(child => ({ + const [tablenames, setTablenames] = useState([]); + const [selectedNode, setSelectedNode] = useState(null); + const [childData, setChildData] = useState([]); + const [selectedChildNode, setSelectedChildNode] = useState(null); + const [indexData, setIndexedData] = useState([]); + const [indexFlyout, setIndexFlyout] = useState(<>); + + const getSidebarContent = () => { + const query = { query: ON_LOAD_QUERY }; + 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]; + }); + setTablenames(fields); + }) + .catch((err) => { + console.error(err); + }); + }; + + useEffect(() => { + getSidebarContent(); + }, []); + + const handleNodeClick = (nodeLabel: string) => { + // // will update after new query + + const newData = ['Child 1', 'Child 2', 'Child 3']; + setChildData(newData); + setSelectedNode(nodeLabel); + }; + + const handleChildClick = (nodeLabel1: string) => { + // will update after new query + + const newData1 = ['Child 4', 'Child 5', 'Child 6']; + setIndexedData(newData1); + setSelectedChildNode(nodeLabel1); + }; + + const resetFlyout = () => { + setIndexFlyout(<>); + }; + + const handleAcclerationIndexClick = ( + dataSource: string, + database: string, + dataTable: string, + indexChild: string + ) => { + setIndexFlyout( + + ); + }; + + const treeData = tablenames.map((element, index) => ({ + label: element, + icon: , + id: 'element_' + index, + callback: () => handleNodeClick(element), + isSelectable: true, + isExpanded: true, + children: + dataConnection === 'S3' && selectedNode === element + ? childData.map((child) => ({ label: child, id: `${element}_${child}`, - icon: , + icon: , callback: () => handleChildClick(child), - sSelectable: true, + sSelectable: true, isExpanded: true, - children: selectedChildNode === child ? indexData.map(indexChild => ({ - label: indexChild, - id: `${child}_${indexChild}`, - icon: - })):undefined, - })) : undefined, - })); - - return ( - <> - {treeData.length > 0 ? - - : Error loading Datasources} - /> - } - - ) -} - + children: + selectedChildNode === child + ? indexData.map((indexChild) => ({ + label: indexChild, + id: `${child}_${indexChild}`, + icon: , + callback: () => + handleAcclerationIndexClick('myGlue', element, child, indexChild), + })) + : undefined, + })) + : undefined, + })); + + return ( + <> + {treeData.length > 0 ? ( + + ) : ( + Error loading Datasources} + /> + )} + {indexFlyout} + + ); +}; diff --git a/public/components/SQLPage/acceleration_index_flyout.tsx b/public/components/SQLPage/acceleration_index_flyout.tsx new file mode 100644 index 00000000..558d10cd --- /dev/null +++ b/public/components/SQLPage/acceleration_index_flyout.tsx @@ -0,0 +1,81 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { + EuiButtonEmpty, + EuiFlexGroup, + EuiFlexItem, + EuiFlyout, + EuiFlyoutBody, + EuiFlyoutFooter, + EuiFlyoutHeader, + EuiPageHeader, + EuiPageHeaderSection, + EuiSpacer, + EuiTitle, +} from '@elastic/eui'; +import React from 'react'; + +interface AccelerationIndexFlyoutProps { + dataSource: string; + database: string; + dataTable: string; + indexName: string; + resetFlyout: () => void; +} + +export const AccelerationIndexFlyout = ({ + dataSource, + database, + dataTable, + indexName, + resetFlyout, +}: AccelerationIndexFlyoutProps) => { + return ( + <> + + +
+ + + +

{indexName}

+
+
+
+
+
+ + + +

Data Source

+ +

{dataSource}

+
+ +

Database

+ +

{database}

+
+ +

Table

+ +

{dataTable}

+
+
+
+ + + + + Close + + + + +
+ + ); +}; diff --git a/public/components/acceleration/visual_editors/materialized_view/add_column_popover.tsx b/public/components/acceleration/visual_editors/materialized_view/add_column_popover.tsx index df6b276f..6d91c5b7 100644 --- a/public/components/acceleration/visual_editors/materialized_view/add_column_popover.tsx +++ b/public/components/acceleration/visual_editors/materialized_view/add_column_popover.tsx @@ -7,6 +7,7 @@ import { EuiButton, EuiButtonEmpty, EuiComboBox, + EuiComboBoxOptionOption, EuiFieldText, EuiFlexGroup, EuiFlexItem, @@ -17,7 +18,6 @@ import { EuiSpacer, htmlIdGenerator, } from '@elastic/eui'; -import { EuiComboBoxOptionOption } from '@opensearch-project/oui'; import producer from 'immer'; import React, { ChangeEvent, useEffect, useState } from 'react'; import { ACCELERATION_AGGREGRATION_FUNCTIONS } from '../../../../../common/constants';