Unverified Commit 5fbaeab2 authored by Licho's avatar Licho Committed by GitHub

refactor: tab type and update method (#2244)

parent 2c644be3
...@@ -121,9 +121,11 @@ const Result = (props: any) => { ...@@ -121,9 +121,11 @@ const Result = (props: any) => {
if (!currentTabs) { if (!currentTabs) {
return; return;
} }
if (currentTabs.type !== TabsPageType.project) { if (currentTabs.type !== TabsPageType.project) {
return; return;
} }
if ((currentTabs?.params as DataStudioParams).resultData && !isRefresh) { if ((currentTabs?.params as DataStudioParams).resultData && !isRefresh) {
setData((currentTabs?.params as DataStudioParams).resultData); setData((currentTabs?.params as DataStudioParams).resultData);
} else { } else {
......
...@@ -111,8 +111,6 @@ const FooterContainer: React.FC<FooterContainerProps & StateType> = (props) => { ...@@ -111,8 +111,6 @@ const FooterContainer: React.FC<FooterContainerProps & StateType> = (props) => {
/** /**
* render footer right info * render footer right info
* @param {ButtonRoute[]} routes
* @returns {JSX.Element[]}
*/ */
const renderFooterRightInfo = (routes: ButtonRoute[]) => { const renderFooterRightInfo = (routes: ButtonRoute[]) => {
return routes return routes
......
...@@ -52,32 +52,24 @@ const MiddleContainer = (props: any) => { ...@@ -52,32 +52,24 @@ const MiddleContainer = (props: any) => {
const [includeTab, setIncludeTab] = useState({}); const [includeTab, setIncludeTab] = useState({});
const updateRightKey = (key: string) => { const updateRightKey = (key: string) => {
let oldPane: TabsItemType; const oldPane = panes.find((pane: TabsItemType) => pane.key === activeKey);
let newPane: TabsItemType; const newPane = panes.find((pane: TabsItemType) => pane.key === key);
panes.forEach((pane: TabsItemType) => {
if (pane.key === key) {
newPane = pane;
}
if (pane.key === activeKey) {
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)) {
oldRightSideAvailableKey.push(x.key); oldRightSideAvailableKey.push(x.key);
}
if (x.isShow(newPane.type, newPane.subType)) {
newRightSideAvailableKey.push(x.key); newRightSideAvailableKey.push(x.key);
return;
} }
} else {
if (x.isShow(oldPane.type, oldPane.subType)) {
oldRightSideAvailableKey.push(x.key); oldRightSideAvailableKey.push(x.key);
}
if (x.isShow(newPane.type, newPane.subType)) {
newRightSideAvailableKey.push(x.key); newRightSideAvailableKey.push(x.key);
} }
}); });
...@@ -109,20 +101,9 @@ const MiddleContainer = (props: any) => { ...@@ -109,20 +101,9 @@ const MiddleContainer = (props: any) => {
payload: selectKey, payload: selectKey,
}); });
}; };
/**
* 更新当前激活的tab
* @param {string} key
* @param eInfo
*/
const updateActiveKey = (key: string, eInfo: any) => {
if (key === activeKey) {
return;
}
const { const updateActiveKey = (key: string, value: string) => {
target: { innerText }, if (key === activeKey) {
} = eInfo;
if (!innerText) {
return; return;
} }
...@@ -135,12 +116,12 @@ const MiddleContainer = (props: any) => { ...@@ -135,12 +116,12 @@ const MiddleContainer = (props: any) => {
}); });
// 替换掉 . 为 /, 因为再 tree 里选中的 key 是 / 分割的 // 替换掉 . 为 /, 因为再 tree 里选中的 key 是 / 分割的
const replaceLabel = innerText.toString().replace('.', '/'); const name = value.toString().replace('.', '/');
dispatch({ dispatch({
type: STUDIO_MODEL.updateDatabaseSelectKey, type: STUDIO_MODEL.updateDatabaseSelectKey,
payload: [replaceLabel], payload: [name],
}); });
}; }
/** /**
* 关闭所有标签 * 关闭所有标签
...@@ -165,20 +146,11 @@ const MiddleContainer = (props: any) => { ...@@ -165,20 +146,11 @@ const MiddleContainer = (props: any) => {
/** /**
* the right click event * the right click event
* @param info
* @param item
*/ */
const handleRightClick = (info: any, item: any) => { const handleRightClick = (info: React.MouseEvent<HTMLDivElement>, item: TabsItemType) => {
// 阻止默认右键事件 // 阻止默认右键事件
info.preventDefault(); info.preventDefault();
updateActiveKey(item.key, info); updateActiveKey(item.key, item.label);
// 替换掉 . 为 /, 因为再 tree 里选中的 key 是 / 分割的
const replaceLabel = item.label.toString().replace('.', '/');
dispatch({
type: STUDIO_MODEL.updateDatabaseSelectKey,
payload: [replaceLabel],
});
// 设置选中的值 // 设置选中的值
setIncludeTab(item); setIncludeTab(item);
...@@ -212,7 +184,6 @@ const MiddleContainer = (props: any) => { ...@@ -212,7 +184,6 @@ const MiddleContainer = (props: any) => {
/** /**
* 右键菜单 * 右键菜单
* @returns {JSX.Element}
*/ */
const renderRightClickMenu = () => { const renderRightClickMenu = () => {
return ( return (
...@@ -262,9 +233,7 @@ const MiddleContainer = (props: any) => { ...@@ -262,9 +233,7 @@ const MiddleContainer = (props: any) => {
key: item.key, key: item.key,
label: ( label: (
<Space <Space
onClick={() => onClick={(e) => updateActiveKey(item.key, item.label) }
updateActiveKey(item.key, { target: { innerText: item.label } })
}
size={0} size={0}
onContextMenu={(e) => handleRightClick(e, item)} onContextMenu={(e) => handleRightClick(e, item)}
key={item.key} key={item.key}
...@@ -303,7 +272,6 @@ const MiddleContainer = (props: any) => { ...@@ -303,7 +272,6 @@ const MiddleContainer = (props: any) => {
/** /**
* render middle content * render middle content
* @returns {JSX.Element}
*/ */
const renderMiddleContent = () => { const renderMiddleContent = () => {
if (tabItems?.length === 0) { if (tabItems?.length === 0) {
...@@ -320,7 +288,6 @@ const MiddleContainer = (props: any) => { ...@@ -320,7 +288,6 @@ const MiddleContainer = (props: any) => {
} }
return ( return (
<>
<ConfigProvider <ConfigProvider
theme={{ theme={{
components: { components: {
...@@ -329,21 +296,18 @@ const MiddleContainer = (props: any) => { ...@@ -329,21 +296,18 @@ const MiddleContainer = (props: any) => {
borderRadiusLG: 0, borderRadiusLG: 0,
}, },
}, },
}} }}>
>
<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, tabItems[active].label)}}
activeKey={activeKey} activeKey={activeKey}
type="editable-card" type="editable-card"
onEdit={closeTab} onEdit={closeTab}
items={tabItems} items={tabItems}/>
/>
{renderRightClickMenu()} {renderRightClickMenu()}
</ConfigProvider> </ConfigProvider>
</>
); );
}; };
......
...@@ -105,6 +105,9 @@ export enum TabsPageType { ...@@ -105,6 +105,9 @@ export enum TabsPageType {
None = '', None = '',
metadata = 'metadata', metadata = 'metadata',
project = 'project', project = 'project',
}
export enum TabsPageSubType {
flinkSql = 'flinksql', flinkSql = 'flinksql',
} }
...@@ -112,9 +115,9 @@ export type TabsItemType = { ...@@ -112,9 +115,9 @@ export type TabsItemType = {
id: string; id: string;
label: string; label: string;
breadcrumbLabel: string; breadcrumbLabel: string;
params: number | string | object | MetadataParams | DataStudioParams; params: MetadataParams | DataStudioParams;
type: TabsPageType; type: TabsPageType;
subType?: TabsPageType; subType?: TabsPageSubType;
key: string; key: string;
value: string; value: string;
icon: any; icon: any;
...@@ -442,25 +445,21 @@ const Model: ModelType = { ...@@ -442,25 +445,21 @@ const Model: ModelType = {
let toolContentHeight = 0; let toolContentHeight = 0;
if (payload === '') { if (payload === '') {
centerContentHeight = centerContentHeight =
(state.centerContentHeight as number) + state.centerContentHeight + (state.bottomContainer.height as number);
(state.bottomContainer.height as number);
toolContentHeight = toolContentHeight =
(state.toolContentHeight as number) + state.toolContentHeight + (state.bottomContainer.height as number);
(state.bottomContainer.height as number);
console.log(2); console.log(2);
} else if ( } else if (
state.bottomContainer.selectKey !== '' && state.bottomContainer.selectKey !== '' &&
payload !== state.bottomContainer.selectKey payload !== state.bottomContainer.selectKey
) { ) {
centerContentHeight = state.centerContentHeight as number; centerContentHeight = state.centerContentHeight;
toolContentHeight = state.toolContentHeight as number; toolContentHeight = state.toolContentHeight;
} else { } else {
centerContentHeight = centerContentHeight =
(state.centerContentHeight as number) - state.centerContentHeight - (state.bottomContainer.height as number);
(state.bottomContainer.height as number);
toolContentHeight = toolContentHeight =
(state.toolContentHeight as number) - state.toolContentHeight - (state.bottomContainer.height as number);
(state.bottomContainer.height as number);
console.log(3); console.log(3);
} }
......
...@@ -22,7 +22,7 @@ import Console from '@/pages/DataStudio/BottomContainer/Console'; ...@@ -22,7 +22,7 @@ import Console from '@/pages/DataStudio/BottomContainer/Console';
import Result from '@/pages/DataStudio/BottomContainer/Result'; import Result from '@/pages/DataStudio/BottomContainer/Result';
import MetaData from '@/pages/DataStudio/LeftContainer/MetaData'; import MetaData from '@/pages/DataStudio/LeftContainer/MetaData';
import Project from '@/pages/DataStudio/LeftContainer/Project'; import Project from '@/pages/DataStudio/LeftContainer/Project';
import { TabsPageType } from '@/pages/DataStudio/model'; import {TabsPageSubType, TabsPageType} from '@/pages/DataStudio/model';
import ExecuteConfig from '@/pages/DataStudio/RightContainer/ExecuteConfig'; import ExecuteConfig from '@/pages/DataStudio/RightContainer/ExecuteConfig';
import HistoryVersion from '@/pages/DataStudio/RightContainer/HistoryVersion'; import HistoryVersion from '@/pages/DataStudio/RightContainer/HistoryVersion';
import JobConfig from '@/pages/DataStudio/RightContainer/JobConfig'; import JobConfig from '@/pages/DataStudio/RightContainer/JobConfig';
...@@ -81,7 +81,7 @@ export const RightSide: TabProp[] = [ ...@@ -81,7 +81,7 @@ export const RightSide: TabProp[] = [
label: l('menu.datastudio.jobConfig'), label: l('menu.datastudio.jobConfig'),
children: <JobConfig />, children: <JobConfig />,
isShow: (type, subType) => isShow: (type, subType) =>
type === TabsPageType.project && TabsPageType.flinkSql === subType, type === TabsPageType.project && TabsPageSubType.flinkSql === subType,
}, },
{ {
key: 'menu.datastudio.executeConfig', key: 'menu.datastudio.executeConfig',
...@@ -89,7 +89,7 @@ export const RightSide: TabProp[] = [ ...@@ -89,7 +89,7 @@ export const RightSide: TabProp[] = [
label: l('menu.datastudio.executeConfig'), label: l('menu.datastudio.executeConfig'),
children: <ExecuteConfig />, children: <ExecuteConfig />,
isShow: (type, subType) => isShow: (type, subType) =>
type === TabsPageType.project && TabsPageType.flinkSql === subType, type === TabsPageType.project && TabsPageSubType.flinkSql === subType,
}, },
{ {
key: 'menu.datastudio.savePoint', key: 'menu.datastudio.savePoint',
...@@ -97,7 +97,7 @@ export const RightSide: TabProp[] = [ ...@@ -97,7 +97,7 @@ export const RightSide: TabProp[] = [
label: l('menu.datastudio.savePoint'), label: l('menu.datastudio.savePoint'),
children: <SavePoints />, children: <SavePoints />,
isShow: (type, subType) => isShow: (type, subType) =>
type === TabsPageType.project && TabsPageType.flinkSql === subType, type === TabsPageType.project && TabsPageSubType.flinkSql === subType,
}, },
{ {
key: 'menu.datastudio.historyVision', key: 'menu.datastudio.historyVision',
...@@ -105,7 +105,7 @@ export const RightSide: TabProp[] = [ ...@@ -105,7 +105,7 @@ export const RightSide: TabProp[] = [
label: l('menu.datastudio.historyVision'), label: l('menu.datastudio.historyVision'),
children: <HistoryVersion />, children: <HistoryVersion />,
isShow: (type, subType) => isShow: (type, subType) =>
type === TabsPageType.project && TabsPageType.flinkSql === subType, type === TabsPageType.project && TabsPageSubType.flinkSql === subType,
}, },
{ {
key: 'menu.datastudio.jobInfo', key: 'menu.datastudio.jobInfo',
...@@ -262,5 +262,5 @@ export type TabProp = { ...@@ -262,5 +262,5 @@ export type TabProp = {
icon: ReactNode; icon: ReactNode;
label: string; label: string;
children: ReactNode; children: ReactNode;
isShow?: (type: TabsPageType, subType?: string) => boolean; isShow?: (type: TabsPageType, subType?: TabsPageSubType) => boolean;
}; };
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