Unverified Commit 32f03fba authored by Licho's avatar Licho Committed by GitHub

feat: multi tab to display watch table information. (#1858)

parent 7e48aae6
...@@ -17,61 +17,118 @@ ...@@ -17,61 +17,118 @@
* *
*/ */
import {Input, Space} from "antd"; import {Input, Modal, Tabs} from "antd";
import {StateType} from "@/pages/DataStudio/model";
import {registerWatchTable, unRegisterWatchTable} from "@/pages/DataStudio/service"; import {registerWatchTable, unRegisterWatchTable} from "@/pages/DataStudio/service";
import {connect} from "umi"; import {Component, useEffect, useState} from "react";
import {useEffect, useRef, useState} from "react";
import stompClientUtil from "@/utils/stompClientUtil" import stompClientUtil from "@/utils/stompClientUtil"
import {Scrollbars} from 'react-custom-scrollbars'; import {Scrollbars} from 'react-custom-scrollbars';
import CodeShow from "@/components/Common/CodeShow"; import CodeShow from "@/components/Common/CodeShow";
import {l} from "@/utils/intl";
import {clearConsole} from "@/components/Studio/StudioEvent/DDL";
import {StateType} from "@/pages/DataStudio/model";
import {connect} from "umi";
import {Subscription} from "stompjs";
import TabPane = Tabs.TabPane;
const {Search} = Input; const DatePage = (props: any) => {
const {height, title} = props;
const {stompClient} = props;
const StudioData = (props: any) => { const [subScription, setSubScription] = useState<Subscription>();
const {height, isActive} = props;
const [consoleInfo, setConsoleInfo] = useState<string>(""); const [consoleInfo, setConsoleInfo] = useState<string>("");
const preConsoleInfo = useRef(consoleInfo)
const [tableName, setTableName] = useState<string>(""); const [tableName, setTableName] = useState<string>("");
const preTableNameRef = useRef(tableName)
let consoleHeight = (height - 37.6); let consoleHeight = (height - 37.6);
const id = Number(localStorage.getItem('dlink-tenantId')); const id = Number(localStorage.getItem('dlink-tenantId'));
const onSearchName = (value: string) => { const onSearchName = (value: string) => {
unRegisterWatchTable({id, table: preTableNameRef.current}).then(res => {
setConsoleInfo("")
stompClientUtil.unsubscribe();
registerWatchTable({id, table: value}).then(res => { registerWatchTable({id, table: value}).then(res => {
stompClientUtil.subScription = stompClientUtil.stompClient.subscribe(res.msg, (res: any) => { let ss = stompClient.subscribe(res.msg, (res: any) => {
preConsoleInfo.current = preConsoleInfo.current + "\n" + res.body setConsoleInfo(preConsoleInfo => preConsoleInfo + "\n" + res.body);
if (preConsoleInfo.current.length > 1024 * 1024) { });
preConsoleInfo.current = preConsoleInfo.current.substring(1024, preConsoleInfo.current.length) setSubScription(ss);
}
setConsoleInfo(preConsoleInfo.current);
})
})
}) })
setTableName(value) setTableName(value)
}; };
useEffect(() => { useEffect(() => {
stompClientUtil.connect(); return () => unRegisterWatchTable({id, table: tableName}).then(res => {
}, [isActive]) console.log("unsubscribe: " + tableName)
subScription?.unsubscribe();
});
}, [subScription]);
const editorDidMountHandle = (editor: any, monaco: any) => {
onSearchName(title);
editor.addAction({
id: 'btn-studio-data-clear',
label: l('pages.datastudio.editor.clearConsole'),
contextMenuGroupId: '9_cutcopypaste',
run: () => {
clearConsole().then((result) => {
setConsoleInfo("")
});
},
})
};
return (<div style={{width: '100%'}}> return (<div style={{width: '100%'}}>
<Space direction="horizontal" style={{margin: 10}}>
<Search placeholder="table name" onSearch={onSearchName} style={{width: 200}}/>
</Space>
<Scrollbars style={{height: consoleHeight}}> <Scrollbars style={{height: consoleHeight}}>
<CodeShow code={consoleInfo} language='text' height={height} theme="vs-dark" /> <CodeShow code={consoleInfo} language='text' height={height} theme="vs-dark"
editorDidMountHandle={editorDidMountHandle}/>
</Scrollbars> </Scrollbars>
</div>) </div>)
}; };
const StudioData = (props: any) => {
const {height, isActive} = props;
const [panes, setPanes] = useState<[{ title: string, key: string, content: Component }]>([]);
const addTab = () => {
let title: string
Modal.confirm({
title: 'Please enter table name',
content: <Input onChange={e => title = e.target.value}/>,
onOk() {
const activeKey = `${panes.length + 1}`;
const newPanes = [...panes];
newPanes.push({
title: title,
content: <DatePage height={height} title={title} stompClient={stompClientUtil.stompClient}/>,
key: activeKey
});
setPanes(newPanes);
}
});
};
useEffect(() => {
stompClientUtil.connect();
}, [isActive])
useEffect(()=>{
return ()=>{
stompClientUtil.disconnect();
}
}, [])
return (<>
<Tabs type="editable-card" onEdit={(targetKey, action) => {
if (action === 'add') {
addTab();
} else if (action === 'remove') {
const newPanes = panes.filter((pane) => pane.key !== targetKey);
setPanes(newPanes);
}
}}>
{panes.map((pane) => (
<TabPane tab={pane.title} key={pane.key}>
{pane.content}
</TabPane>
))}
</Tabs>
</>);
};
export default connect(({Studio}: { Studio: StateType }) => ({ export default connect(({Studio}: { Studio: StateType }) => ({
current: Studio.current, current: Studio.current,
}))(StudioData); }))(StudioData);
...@@ -18,35 +18,36 @@ ...@@ -18,35 +18,36 @@
*/ */
import { Empty, Tabs } from "antd"; import {Button, Empty, Tabs} from "antd";
import { import {
ApartmentOutlined, ApartmentOutlined,
BarChartOutlined, BarChartOutlined,
CalendarOutlined, CalendarOutlined,
CodeOutlined, CodeOutlined,
DesktopOutlined, PrinterOutlined, DesktopOutlined,
PrinterOutlined,
TableOutlined TableOutlined
} from "@ant-design/icons"; } from "@ant-design/icons";
import { StateType } from "@/pages/DataStudio/model"; import {StateType} from "@/pages/DataStudio/model";
import { connect } from "umi"; import {connect} from "umi";
import StudioMsg from "./StudioMsg"; import StudioMsg from "./StudioMsg";
import StudioTable from "./StudioTable"; import StudioTable from "./StudioTable";
import StudioHistory from "./StudioHistory"; import StudioHistory from "./StudioHistory";
import StudioData from "./StudioData" import StudioData from "./StudioData"
import StudioCA from "./StudioCA"; import StudioCA from "./StudioCA";
import StudioProcess from "./StudioProcess"; import StudioProcess from "./StudioProcess";
import { Scrollbars } from 'react-custom-scrollbars'; import {Scrollbars} from 'react-custom-scrollbars';
import Chart from "@/components/Chart"; import Chart from "@/components/Chart";
import React, { useState } from "react"; import React, {useState} from "react";
import { l } from "@/utils/intl"; import {l} from "@/utils/intl";
const { TabPane } = Tabs;
const StudioConsole = (props: any) => { const {TabPane} = Tabs;
const StudioConsole = (props: any) => {
const { height, current } = props; const {height, current} = props;
let consoleHeight = (height - 37.6); let consoleHeight = (height - 37.6);
const [activeKey, setActiveKey] = useState<string>("StudioMsg"); const [activeKey, setActiveKey] = useState<string>("StudioMsg");
...@@ -55,103 +56,104 @@ const StudioConsole = (props: any) => { ...@@ -55,103 +56,104 @@ const StudioConsole = (props: any) => {
} }
return ( return (
<Tabs defaultActiveKey="StudioMsg" size="small" tabPosition="top" style={{ <Tabs defaultActiveKey="StudioMsg" size="small" tabPosition="top" style={{
border: "1px solid #f0f0f0", height: height, margin: "0 32px" border: "1px solid #f0f0f0", height: height, margin: "0 32px"
}} onChange={onTabsChange}> }} onChange={onTabsChange}>
<TabPane <TabPane
tab={ tab={
<span> <span>
<CodeOutlined /> <CodeOutlined/>
{l('pages.datastudio.label.info')} {l('pages.datastudio.label.info')}
</span> </span>
} }
key="StudioMsg" key="StudioMsg"
> >
<Scrollbars style={{ height: consoleHeight }}> <Scrollbars style={{height: consoleHeight}}>
<StudioMsg height={consoleHeight} isActive={activeKey === "StudioMsg"} /> <StudioMsg height={consoleHeight} isActive={activeKey === "StudioMsg"}/>
</Scrollbars> </Scrollbars>
</TabPane> </TabPane>
<TabPane <TabPane
tab={ tab={
<span> <span>
<TableOutlined /> <TableOutlined/>
{l('pages.datastudio.label.result')} {l('pages.datastudio.label.result')}
</span> </span>
} }
key="StudioTable" key="StudioTable"
> >
<Scrollbars style={{ height: consoleHeight }}> <Scrollbars style={{height: consoleHeight}}>
{current ? <StudioTable /> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />} {current ? <StudioTable/> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE}/>}
</Scrollbars> </Scrollbars>
</TabPane> </TabPane>
<TabPane <TabPane
tab={ tab={
<span> <span>
<BarChartOutlined /> <BarChartOutlined/>
BI BI
</span> </span>
} }
key="StudioChart" key="StudioChart"
> >
<Scrollbars style={{ height: consoleHeight }}> <Scrollbars style={{height: consoleHeight}}>
{current ? <Chart height={consoleHeight} /> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />} {current ? <Chart height={consoleHeight}/> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE}/>}
</Scrollbars> </Scrollbars>
</TabPane> </TabPane>
<TabPane <TabPane
tab={ tab={
<span> <span>
<ApartmentOutlined /> <ApartmentOutlined/>
{l('pages.datastudio.label.lineage')} {l('pages.datastudio.label.lineage')}
</span> </span>
} }
key="StudioConsanguinity" key="StudioConsanguinity"
> >
<Scrollbars style={{ height: consoleHeight }}> <Scrollbars style={{height: consoleHeight}}>
{current ? <StudioCA /> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />} {current ? <StudioCA/> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE}/>}
</Scrollbars> </Scrollbars>
</TabPane> </TabPane>
<TabPane <TabPane
tab={ tab={
<span> <span>
<DesktopOutlined /> <DesktopOutlined/>
{l('pages.datastudio.label.process')} {l('pages.datastudio.label.process')}
</span> </span>
} }
key="StudioProcess" key="StudioProcess"
> >
<Scrollbars style={{ height: consoleHeight }}> <Scrollbars style={{height: consoleHeight}}>
<StudioProcess /> <StudioProcess/>
</Scrollbars> </Scrollbars>
</TabPane> </TabPane>
<TabPane <TabPane
tab={ tab={
<span> <span>
<CalendarOutlined /> <CalendarOutlined/>
{l('pages.datastudio.label.history')} {l('pages.datastudio.label.history')}
</span> </span>
} }
key="StudioHistory" key="StudioHistory"
> >
<Scrollbars style={{ height: consoleHeight }}> <Scrollbars style={{height: consoleHeight}}>
<StudioHistory /> <StudioHistory/>
</Scrollbars> </Scrollbars>
</TabPane> </TabPane>
<TabPane <TabPane
tab={ tab={
<span> <span>
<PrinterOutlined /> <PrinterOutlined/>
{l('pages.datastudio.label.data')} {l('pages.datastudio.label.data')}
</span> </span>
} }
key="StudioData" key="StudioData"
> >
<StudioData height={consoleHeight} isActive={activeKey === "StudioData"} /> <StudioData height={consoleHeight} isActive={activeKey === "StudioData"}/>
</TabPane> </TabPane>
</Tabs> </Tabs>
); );
}; };
export default connect(({ Studio }: { Studio: StateType }) => ({ export default connect(({Studio}: { Studio: StateType }) => ({
sql: Studio.sql, sql: Studio.sql,
current: Studio.current, current: Studio.current,
}))(StudioConsole); }))(StudioConsole);
...@@ -4,13 +4,11 @@ import Stomp, { Subscription } from "stompjs"; ...@@ -4,13 +4,11 @@ import Stomp, { Subscription } from "stompjs";
class StompClientUtil { class StompClientUtil {
stompClient: Stomp.Client; stompClient: Stomp.Client;
connectStatus: boolean; connectStatus: boolean;
subScription: Subscription;
constructor() { constructor() {
const baseUrl = "ws://127.0.0.1:8888/stomp"; const baseUrl = "ws://127.0.0.1:8888/stomp";
const socket = new WebSocket(baseUrl); const socket = new WebSocket(baseUrl);
this.stompClient = Stomp.over(socket); this.stompClient = Stomp.over(socket);
this.connectStatus = false; this.connectStatus = false;
this.subScription = { id: "", unsubscribe: () => { } };
this.connect(); this.connect();
} }
...@@ -28,7 +26,7 @@ class StompClientUtil { ...@@ -28,7 +26,7 @@ class StompClientUtil {
); );
} }
close() { disconnect() {
if (this.stompClient) { if (this.stompClient) {
this.stompClient.disconnect(() => { this.stompClient.disconnect(() => {
console.log("============connect release============"); console.log("============connect release============");
...@@ -36,10 +34,5 @@ class StompClientUtil { ...@@ -36,10 +34,5 @@ class StompClientUtil {
}); });
} }
} }
unsubscribe() {
this.subScription.unsubscribe()
this.subScription = { id: "", unsubscribe: () => { } };
}
} }
export default new StompClientUtil() export default new StompClientUtil()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment