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