Unverified Commit 582c2263 authored by Licho's avatar Licho Committed by GitHub

Refactor middle container, make model type constant, and in ide could jump to reduce (#2227)

* refactor: add STUDIO_MODEL * refactor:
parent 70555c74
...@@ -41,15 +41,14 @@ const KeyBoard = () => { ...@@ -41,15 +41,14 @@ const KeyBoard = () => {
}); });
} }
return <> return(
<Typography style={{padding: '2px', textAlign: 'center', border: 'salmon'}}> <Typography style={{padding: '2px', textAlign: 'center', border: 'salmon'}}>
<br/> <br/>
<Title level={4}>{l('shortcut.title')}</Title> <Title level={4}>{l('shortcut.title')}</Title>
<Paragraph style={{padding: 0, margin: 0, textAlign: 'center', border: 'salmon'}} > <Paragraph style={{padding: 0, margin: 0, textAlign: 'center', border: 'salmon'}} >
{buildKeyBoard()} {buildKeyBoard()}
</Paragraph> </Paragraph>
</Typography> </Typography>);
</>;
}; };
export default KeyBoard; export default KeyBoard;
...@@ -43,14 +43,13 @@ const QuickGuide = () => { ...@@ -43,14 +43,13 @@ const QuickGuide = () => {
}); });
} }
return <> return (
<Typography style={{padding: '2px', textAlign: 'center', border: 'salmon'}}> <Typography style={{padding: '2px', textAlign: 'center', border: 'salmon'}}>
<Title level={4}>{l('datastudio.middle.qg')}</Title> <Title level={4}>{l('datastudio.middle.qg')}</Title>
<Paragraph style={{padding: 0, margin: 0, textAlign: 'center', border: 'salmon'}} > <Paragraph style={{padding: 0, margin: 0, textAlign: 'center', border: 'salmon'}} >
{buildQuickGuide()} {buildQuickGuide()}
</Paragraph> </Paragraph>
</Typography> </Typography>);
</>
}; };
......
...@@ -14,12 +14,12 @@ import { ...@@ -14,12 +14,12 @@ import {
} from "@/components/Icons/CodeLanguageIcon"; } from "@/components/Icons/CodeLanguageIcon";
import {ClickHouseIcons, DorisIcons, HiveIcons, MysqlIcons, OracleIcons, PhoenixIcons, import {ClickHouseIcons, DorisIcons, HiveIcons, MysqlIcons, OracleIcons, PhoenixIcons,
PostgresqlIcons, PrestoIcons, SqlServerIcons, StarRocksIcons} from "@/components/Icons/DBIcons"; PostgresqlIcons, PrestoIcons, SqlServerIcons, StarRocksIcons} from "@/components/Icons/DBIcons";
import {FolderOutlined} from "@ant-design/icons";
export const getTabIcon = (type: string, size?: number) => { export const getTabIcon = (type: string, size?: number) => {
if (!type){ if (!type){
return <FileIcon/>; return <FileIcon/>;
} }
switch (type.toLowerCase()) { switch (type.toLowerCase()) {
case DIALECT.JAVA: case DIALECT.JAVA:
return <JavaSvg/>; return <JavaSvg/>;
......
...@@ -18,7 +18,14 @@ ...@@ -18,7 +18,14 @@
import {ConfigProvider, Divider, Dropdown, Menu, Space, Tabs} from "antd"; import {ConfigProvider, Divider, Dropdown, Menu, Space, Tabs} from "antd";
import React, {useState} from "react"; import React, {useState} from "react";
import {connect} from "@@/exports"; import {connect} from "@@/exports";
import {DataStudioParams, MetadataParams, StateType, TabsItemType, TabsPageType} from "@/pages/DataStudio/model"; import {
DataStudioParams,
MetadataParams,
STUDIO_MODEL,
StateType,
TabsItemType,
TabsPageType
} from "@/pages/DataStudio/model";
import RightTagsRouter from "@/pages/RegCenter/DataSource/components/DataSourceDetail/RightTagsRouter"; import RightTagsRouter from "@/pages/RegCenter/DataSource/components/DataSourceDetail/RightTagsRouter";
import KeyBoard from "@/pages/DataStudio/MiddleContainer/KeyBoard"; import KeyBoard from "@/pages/DataStudio/MiddleContainer/KeyBoard";
import {MenuInfo} from "rc-menu/es/interface"; import {MenuInfo} from "rc-menu/es/interface";
...@@ -45,16 +52,20 @@ const MiddleContainer = (props: any) => { ...@@ -45,16 +52,20 @@ const MiddleContainer = (props: any) => {
const updateRightKey = (key:string) => { const updateRightKey = (key:string) => {
let oldPane:TabsItemType; let oldPane:TabsItemType;
let newPane:TabsItemType; let newPane:TabsItemType;
panes.forEach((pane: TabsItemType) => { panes.forEach((pane: TabsItemType) => {
if (pane.key === key) { if (pane.key === key) {
newPane = pane newPane = pane
} }
if (pane.key === activeKey) { if (pane.key === activeKey) {
oldPane = pane oldPane = pane
} }
}) })
let oldRightSideAvailableKey:string[]=[]; let oldRightSideAvailableKey:string[]=[];
let newRightSideAvailableKey:string[]=[]; let newRightSideAvailableKey:string[]=[];
RightSide.forEach(x=>{ RightSide.forEach(x=>{
if (x.isShow){ if (x.isShow){
if (x.isShow(oldPane.type, oldPane.subType)) { if (x.isShow(oldPane.type, oldPane.subType)) {
...@@ -67,27 +78,32 @@ const MiddleContainer = (props: any) => { ...@@ -67,27 +78,32 @@ const MiddleContainer = (props: any) => {
newRightSideAvailableKey.push(x.key) newRightSideAvailableKey.push(x.key)
} }
}); });
if (rightKey && !newRightSideAvailableKey.includes(rightKey)){
if (newRightSideAvailableKey.length===0){ if (!rightKey || newRightSideAvailableKey.includes(rightKey)) {
return;
}
if (newRightSideAvailableKey.length === 0) {
dispatch({ dispatch({
type: 'Studio/updateSelectRightKey', type: STUDIO_MODEL.updateSelectRightKey,
payload: '', payload: '',
}) })
return; return;
} }
const oldIndex = oldRightSideAvailableKey.findIndex((value)=>value===rightKey);
const oldIndex = oldRightSideAvailableKey.findIndex((value) => value === rightKey);
let selectKey: string; let selectKey: string;
if (oldIndex >= newRightSideAvailableKey.length) { if (oldIndex >= newRightSideAvailableKey.length) {
selectKey= newRightSideAvailableKey.pop() as string; selectKey = newRightSideAvailableKey.pop() as string;
}else { } else {
selectKey= newRightSideAvailableKey[oldIndex]; selectKey = newRightSideAvailableKey[oldIndex];
} }
dispatch({ dispatch({
type: 'Studio/updateSelectRightKey', type: STUDIO_MODEL.updateSelectRightKey,
payload: selectKey, payload: selectKey,
}) })
} }
}
/** /**
* 更新当前激活的tab * 更新当前激活的tab
* @param {string} key * @param {string} key
...@@ -97,41 +113,44 @@ const MiddleContainer = (props: any) => { ...@@ -97,41 +113,44 @@ const MiddleContainer = (props: any) => {
if (key === activeKey) { if (key === activeKey) {
return return
} }
const {target: {innerText}} = eInfo; const {target: {innerText}} = eInfo;
if (!innerText){ if (!innerText){
return; return;
} }
const replaceLabel = innerText.toString().replace('.', '/') // 替换掉 . 为 /, 因为再 tree 里选中的 key 是 / 分割的
setContextMenuVisible(false)
setContextMenuVisible(false)
updateRightKey(key); updateRightKey(key);
dispatch({ dispatch({
type: 'Studio/updateTabsActiveKey', type: STUDIO_MODEL.updateTabsActiveKey,
payload: key, payload: key,
}) })
// 替换掉 . 为 /, 因为再 tree 里选中的 key 是 / 分割的
const replaceLabel = innerText.toString().replace('.', '/')
dispatch({ dispatch({
type: 'Studio/updateDatabaseSelectKey', type: STUDIO_MODEL.updateDatabaseSelectKey,
payload: [replaceLabel], payload: [replaceLabel],
}) })
}; };
/** /**
* 关闭所有标签 * 关闭所有标签
*/ */
const handleCloseAllTabs = () => { const handleCloseAllTabs = () => {
dispatch({ dispatch({
type: 'Studio/closeAllTabs', type: STUDIO_MODEL.closeAllTabs,
}); });
setContextMenuVisible(false) setContextMenuVisible(false)
} }
/** /**
* 关闭其他标签 * 关闭其他标签
*/ */
const handleCloseOtherTabs = () => { const handleCloseOtherTabs = () => {
dispatch({ dispatch({
type: 'Studio/closeOtherTabs', type: STUDIO_MODEL.closeOtherTabs,
payload: includeTab, payload: includeTab,
}); });
setContextMenuVisible(false) setContextMenuVisible(false)
...@@ -143,23 +162,24 @@ const MiddleContainer = (props: any) => { ...@@ -143,23 +162,24 @@ const MiddleContainer = (props: any) => {
* @param item * @param item
*/ */
const handleRightClick = (info: any, item: any) => { const handleRightClick = (info: any, item: any) => {
info.preventDefault(); // 阻止默认右键事件 // 阻止默认右键事件
const {key, label} = item; info.preventDefault()
const replaceLabel = label.toString().replace('.', '/') // 替换掉 . 为 /, 因为再 tree 里选中的 key 是 / 分割的 updateActiveKey(item.key, info);
updateActiveKey(key, info);
// 替换掉 . 为 /, 因为再 tree 里选中的 key 是 / 分割的
const replaceLabel = item.label.toString().replace('.', '/')
dispatch({ dispatch({
type: 'Studio/updateDatabaseSelectKey', type: STUDIO_MODEL.updateDatabaseSelectKey,
payload: [replaceLabel], payload: [replaceLabel],
}) })
// 获取 选中的值
// 设置选中的值
setIncludeTab(item); setIncludeTab(item);
// 获取右键点击的位置
const {clientX, clientY} = info;
setContextMenuVisible(true) setContextMenuVisible(true)
setContextMenuPosition({ setContextMenuPosition({
position: 'fixed', cursor: 'context-menu', width: '10vw', zIndex: 9999, position: 'fixed', cursor: 'context-menu', width: '10vw', zIndex: 9999,
left: clientX + 10, // + 10 是为了让鼠标不至于在选中的节点上 && 不遮住当前鼠标位置 left: info.clientX + 10, // + 10 是为了让鼠标不至于在选中的节点上 && 不遮住当前鼠标位置
top: clientY + 10, // + 10 是为了让鼠标不至于在选中的节点上 && 不遮住当前鼠标位置 top: info.clientY + 10, // + 10 是为了让鼠标不至于在选中的节点上 && 不遮住当前鼠标位置
}); });
}; };
...@@ -180,37 +200,31 @@ const MiddleContainer = (props: any) => { ...@@ -180,37 +200,31 @@ const MiddleContainer = (props: any) => {
} }
}; };
/** /**
* 右键菜单 * 右键菜单
* @returns {JSX.Element} * @returns {JSX.Element}
*/ */
const renderRightClickMenu = () => { const renderRightClickMenu = () => {
// const menuList = <Menu onClick={handleMenuClick} items={STUDIO_TAG_RIGHT_CONTEXT_MENU}/> return <Dropdown
return <>
<Dropdown
arrow arrow
trigger={['contextMenu']} trigger={['contextMenu']}
overlayStyle={{...contextMenuPosition}} overlayStyle={{...contextMenuPosition}}
menu={{items: STUDIO_TAG_RIGHT_CONTEXT_MENU, onClick: handleMenuClick}} menu={{items: STUDIO_TAG_RIGHT_CONTEXT_MENU, onClick: handleMenuClick}}
open={contextMenuVisible} open={contextMenuVisible}
onOpenChange={setContextMenuVisible} onOpenChange={setContextMenuVisible}>
>
{/*占位*/} {/*占位*/}
<div style={{...contextMenuPosition}}/> <div style={{...contextMenuPosition}}/>
</Dropdown> </Dropdown>
</>
} }
/** /**
* render tabs * render tabs
*/ */
const tabItems = (panes).map((item: TabsItemType) => { const tabItems = panes.map((item: TabsItemType) => {
const renderContent = () => { const renderContent = () => {
switch (item.type) { switch (item.type) {
case TabsPageType.metadata: case TabsPageType.metadata:
let params: MetadataParams; const params = item.params as MetadataParams;
params = item.params as MetadataParams;
return <RightTagsRouter tableInfo={params.tableInfo} queryParams={params.queryParams}/> return <RightTagsRouter tableInfo={params.tableInfo} queryParams={params.queryParams}/>
case TabsPageType.project: case TabsPageType.project:
if (parseInt(activeKey) < 0) { if (parseInt(activeKey) < 0) {
...@@ -222,24 +236,22 @@ const MiddleContainer = (props: any) => { ...@@ -222,24 +236,22 @@ const MiddleContainer = (props: any) => {
return <></> return <></>
} }
} }
return { return {
key: item.key, key: item.key,
label: <> label:
<Space <Space onClick={() => updateActiveKey(item.key, {target: {innerText: item.label}})}
onClick={()=> updateActiveKey(item.key, {target: {innerText: item.label}})} size={0}
size={0} onContextMenu={(e) => handleRightClick(e, item)} onContextMenu={(e) => handleRightClick(e, item)}
key={item.key}>{getTabIcon(item.icon, 16)}{item.label}</Space> key={item.key}>{getTabIcon(item.icon, 16)}{item.label}
</>, </Space>,
children:<> children:
<ContentScroll height={activeKey === item.key ? props.centerContentHeight - 35 : 0}> <ContentScroll height={activeKey === item.key ? props.centerContentHeight - 35 : 0}>
{renderContent()} {renderContent()}
</ContentScroll> </ContentScroll>
</>
} }
}) })
/** /**
* 关闭tab * 关闭tab
* @param {TargetKey} targetKey * @param {TargetKey} targetKey
...@@ -247,17 +259,17 @@ const MiddleContainer = (props: any) => { ...@@ -247,17 +259,17 @@ const MiddleContainer = (props: any) => {
const closeTab = (targetKey: TargetKey) => { const closeTab = (targetKey: TargetKey) => {
if (panes.length === 1) { if (panes.length === 1) {
dispatch({ dispatch({
type: 'Studio/updateSelectRightKey', type: STUDIO_MODEL.updateSelectRightKey,
payload: "", payload: "",
}) })
} }
dispatch({ dispatch({
type: 'Studio/closeTab', type: STUDIO_MODEL.closeTab,
payload: targetKey, payload: targetKey,
}) })
}; };
/** /**
* render middle content * render middle content
* @returns {JSX.Element} * @returns {JSX.Element}
...@@ -269,7 +281,8 @@ const MiddleContainer = (props: any) => { ...@@ -269,7 +281,8 @@ const MiddleContainer = (props: any) => {
<Divider/><br/><br/><br/> <Divider/><br/><br/><br/>
<QuickGuide/> <QuickGuide/>
</> </>
} else { }
return <> return <>
<ConfigProvider theme={{ <ConfigProvider theme={{
components: { components: {
...@@ -281,7 +294,7 @@ const MiddleContainer = (props: any) => { ...@@ -281,7 +294,7 @@ const MiddleContainer = (props: any) => {
}}> }}>
<Tabs <Tabs
className={"data-studio-tabs"} className={"data-studio-tabs"}
tabBarStyle={{borderBlock: '1px solid ' + themeValue.borderColor}} tabBarStyle={{borderBlock: `1px solid ${themeValue.borderColor}`}}
hideAdd hideAdd
onTabClick={(active, e) => updateActiveKey(active, e)} onTabClick={(active, e) => updateActiveKey(active, e)}
activeKey={activeKey} activeKey={activeKey}
...@@ -291,16 +304,14 @@ const MiddleContainer = (props: any) => { ...@@ -291,16 +304,14 @@ const MiddleContainer = (props: any) => {
/> />
{renderRightClickMenu()} {renderRightClickMenu()}
</ConfigProvider> </ConfigProvider>
</> </>
} }
}
return <> return <>
{renderMiddleContent()} {renderMiddleContent()}
</> </>
} }
export default connect(({Studio}: { Studio: StateType }) => ({ export default connect(({Studio}: { Studio: StateType }) => ({
tabs: Studio.tabs, tabs: Studio.tabs,
centerContentHeight: Studio.centerContentHeight, centerContentHeight: Studio.centerContentHeight,
......
...@@ -273,9 +273,45 @@ export type ModelType = { ...@@ -273,9 +273,45 @@ export type ModelType = {
updateJobRunningMsg: Reducer<StateType>; updateJobRunningMsg: Reducer<StateType>;
}; };
}; };
const Model: ModelType = {
namespace: 'Studio', const ModelTypeName = 'Studio';
const getModelType = (name: string) => {
return `${ModelTypeName}/${name}`;
}
export const STUDIO_MODEL: {[K in keyof ModelType['reducers']]: string} = {
updateToolContentHeight: getModelType('updateToolContentHeight'),
updateCenterContentHeight: getModelType('updateCenterContentHeight'),
updateSelectLeftKey: getModelType('updateSelectLeftKey'),
updateLeftWidth: getModelType('updateLeftWidth'),
updateSelectRightKey: getModelType('updateSelectRightKey'),
updateRightWidth: getModelType('updateRightWidth'),
updateSelectBottomKey: getModelType('updateSelectBottomKey'),
updateSelectBottomSubKey: getModelType('updateSelectBottomSubKey'),
updateBottomHeight: getModelType('updateBottomHeight'),
saveDataBase: getModelType('saveDataBase'),
saveProject: getModelType('saveProject'),
updateTabsActiveKey: getModelType('updateTabsActiveKey'),
closeTab: getModelType('closeTab'),
removeTag: getModelType('removeTag'),
addTab: getModelType('addTab'),
saveTabs: getModelType('saveTabs'),
closeAllTabs: getModelType('closeAllTabs'),
closeOtherTabs: getModelType('closeOtherTabs'),
updateSelectDatabaseId: getModelType('updateSelectDatabaseId'),
updateDatabaseExpandKey: getModelType('updateDatabaseExpandKey'),
updateDatabaseSelectKey: getModelType('updateDatabaseSelectKey'),
updateBottomConsole: getModelType('updateBottomConsole'),
saveSession: getModelType('saveSession'),
saveClusterConfiguration: getModelType('saveClusterConfiguration'),
saveEnv: getModelType('saveEnv'),
saveFooterValue: getModelType('saveFooterValue'),
updateJobRunningMsg: getModelType('updateJobRunningMsg'),
};
const Model: ModelType = {
namespace: ModelTypeName,
state: { state: {
isFullScreen: false, isFullScreen: false,
toolContentHeight: 0, toolContentHeight: 0,
......
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