Unverified Commit af6a010b authored by Licho's avatar Licho Committed by GitHub

refactor: pluck url and add STUDIO_MODEL_SYNC (#2228)

* refactor: pluck url and add STUDIO_MODEL_SYNC * refactor Signed-off-by: 's avatarLicho <lecho.sun@gmail.com> * refactor: pluck url and add STUDIO_MODEL_SYNC * refactor: extract modal type string map to function --------- Signed-off-by: 's avatarLicho <lecho.sun@gmail.com>
parent 83fb5103
......@@ -22,15 +22,14 @@ import {ProForm, ProFormText} from "@ant-design/pro-components";
import {l} from "@/utils/intl";
const FolderForm = () => {
return <>
return (
<ProFormText
name="name"
label={l('datastudio.project.create.folder.name')}
placeholder={l('datastudio.project.create.folder.name.placeholder')}
rules={[ {required: true, message: l('datastudio.project.create.folder.name.placeholder')} ]}
/>
</>
/>)
};
export default FolderForm;
\ No newline at end of file
export default FolderForm;
......@@ -39,11 +39,7 @@ type JobModalProps = {
const JobModal: React.FC<JobModalProps> = (props) => {
const {onCancel, onSubmit, modalVisible, title, values} = props;
const [jobType, setJobType] = React.useState<string>(values.type || '');
const [form] = Form.useForm<Catalogue>();
/**
......@@ -72,7 +68,6 @@ const JobModal: React.FC<JobModalProps> = (props) => {
formContext.resetForm();
};
/**
* form values change
* @param changedValues
......@@ -82,7 +77,6 @@ const JobModal: React.FC<JobModalProps> = (props) => {
if (allValues.type) setJobType(allValues.type);
}
/**
* submit form
*/
......@@ -93,7 +87,6 @@ const JobModal: React.FC<JobModalProps> = (props) => {
onSubmit({...values, ...formData} as Catalogue);
};
const renderForm = () => {
return <>
<ProFormSelect
......@@ -153,4 +146,4 @@ const JobModal: React.FC<JobModalProps> = (props) => {
</>
};
export default JobModal
\ No newline at end of file
export default JobModal
......@@ -64,7 +64,7 @@ const JobTree: React.FC<TreeProps & connect> = (props) => {
value = String(value).trim();
const expandList: any[] = generateList(data, []);
let expandedKeys: any = expandList.map((item: any) => {
if (item && item.name.indexOf(value) > -1) {
if (item?.name.indexOf(value) > -1) {
return getParentKey(item.key, data);
}
return null;
......
......@@ -22,11 +22,12 @@ import {Space} from "antd";
import Title from "@/components/Front/Title";
import {l} from "@/utils/intl";
import {connect} from "@umijs/max";
import {StateType} from "@/pages/DataStudio/model";
import {StateType, STUDIO_MODEL_ASYNC} from "@/pages/DataStudio/model";
import {Catalogue} from "@/types/Studio/data";
import {handleAddOrUpdate} from "@/services/BusinessCrud";
import {BtnRoute} from "@/pages/DataStudio/route";
import FolderModal from "@/pages/DataStudio/LeftContainer/Project/FolderModal";
import {API_CONSTANTS} from "@/services/constants";
const ProjectTitle: React.FC<StateType & connect> = (props) => {
......@@ -53,13 +54,13 @@ const ProjectTitle: React.FC<StateType & connect> = (props) => {
* @returns {Promise<void>}
*/
const handleSubmit = async (values: Catalogue) => {
await handleAddOrUpdate('/api/catalogue/saveOrUpdateCatalogue', {
await handleAddOrUpdate(API_CONSTANTS.SAVE_OR_UPDATE_CATALOGUE_URL, {
...values,
isLeaf: false,
parentId: 0,
}, ()=>{
handleCancelCreate();
dispatch({type: 'Studio/queryProject'});
dispatch({type: STUDIO_MODEL_ASYNC.queryProject});
});
};
......@@ -96,4 +97,4 @@ const ProjectTitle: React.FC<StateType & connect> = (props) => {
export default connect(({Studio}: { Studio: StateType }) => ({
leftContainer: Studio.leftContainer,
}))(ProjectTitle);
\ No newline at end of file
}))(ProjectTitle);
......@@ -57,7 +57,7 @@ export const buildProjectTree = (data: Catalogue[], searchValue: string = '', pa
label: searchTreeNode(item.name, searchValue),
icon: (item.type && item.children.length === 0) && getTabIcon(item.type,20),
value: item.id,
path: path || [],
path: path ?? [],
type: item.type,
title: <>{searchTreeNode(item.name, searchValue)}</>,
fullInfo: item,
......@@ -75,4 +75,4 @@ export const isUDF = (jobType: string) => {
export const buildUDFTree = (data: []) => {
}
\ No newline at end of file
}
......@@ -21,7 +21,7 @@
import React, {Key, useEffect, useState} from "react";
import JobTree from "@/pages/DataStudio/LeftContainer/Project/JobTree";
import {connect} from "umi";
import {StateType} from "@/pages/DataStudio/model";
import {StateType, STUDIO_MODEL, STUDIO_MODEL_ASYNC} from "@/pages/DataStudio/model";
import {getTaskDetails} from "@/pages/DataStudio/LeftContainer/Project/service";
import RightContextMenu from "@/components/RightContextMenu";
import {MenuInfo} from "rc-menu/es/interface";
......@@ -33,7 +33,9 @@ import {Modal, Typography} from "antd";
import {l} from "@/utils/intl";
import FolderModal from "@/pages/DataStudio/LeftContainer/Project/FolderModal";
import JobModal from "@/pages/DataStudio/LeftContainer/Project/JobModal";
import {SuccessMessage} from "@/utils/messages";
import {
API_CONSTANTS
} from "@/services/constants";
const {Text} = Typography;
......@@ -43,7 +45,7 @@ const Project: React.FC = (props: connect) => {
const [rightActiveKey, setRightActiveKey] = useState<string>('');
const [cutId , setCutId] = useState<number>();
const [contextMenu, setContext] = useState<{
const [contextMenu, setContextMenu] = useState<{
visible: boolean;
position: any;
item: MenuItemType[];
......@@ -82,11 +84,12 @@ const Project: React.FC = (props: connect) => {
isCut: false,
})
useEffect(() => {
setContext((prevState) => ({
setContextMenu((prevState) => ({
...prevState,
item: prevState.isLeaf ? JOB_RIGHT_MENU(modalAllVisible.isCut && cutId !== undefined) : FOLDER_RIGHT_MENU(modalAllVisible.isCut && cutId !== undefined)
item: prevState.isLeaf ?
JOB_RIGHT_MENU(modalAllVisible.isCut && cutId !== undefined) :
FOLDER_RIGHT_MENU(modalAllVisible.isCut && cutId !== undefined)
}))
}, [modalAllVisible.isCut,cutId])
......@@ -98,7 +101,7 @@ const Project: React.FC = (props: connect) => {
const handleRightClick = (info: any) => {
const {node: {isLeaf, key, fullInfo}, node, event} = info;
// 设置右键菜单
setContext((prevState) => ({
setContextMenu((prevState) => ({
...prevState,
visible: true,
position: {
......@@ -122,33 +125,35 @@ const Project: React.FC = (props: connect) => {
const onNodeClick = (info: any) => {
// 选中的key
const {node: {isLeaf, name, type, parentId, path, key, taskId}} = info;
setContext((prevState) => ({
setContextMenu((prevState) => ({
...prevState,
visible: false,
selectedKeys: [key],
}));
if (isLeaf) {
// const queryParams = {id: selectDatabaseId , schemaName, tableName};
getTaskDetails(taskId).then(res => {
path.pop()
dispatch({
type: "Studio/addTab",
payload: {
icon: type,
id: parentId + name,
breadcrumbLabel: path.join("/"),
label: name,
params: {taskId: taskId, taskData: {...res, useResult: true, maxRowNum: 100}},
type: "project",
subType: type.toLowerCase()
}
})
})
}
if (!isLeaf) {
return;
}
getTaskDetails(taskId).then(res => {
path.pop()
dispatch({
type: STUDIO_MODEL.addTab,
payload: {
icon: type,
id: parentId + name,
breadcrumbLabel: path.join("/"),
label: name,
params: {taskId: taskId, taskData: {...res, useResult: true, maxRowNum: 100}},
type: "project",
subType: type.toLowerCase()
}
})
})
};
const handleContextCancel = () => {
setContext((prevState) => ({
setContextMenu((prevState) => ({
...prevState,
visible: false,
}));
......@@ -168,24 +173,26 @@ const Project: React.FC = (props: connect) => {
* @returns {Promise<void>}
*/
const handleSubmit = async (values: Catalogue) => {
let options = {
const options = {
url: '',
isLeaf: modalAllVisible.isCreateSub ? false : modalAllVisible.value.isLeaf,
parentId: modalAllVisible.isCreateSub ? contextMenu.selectedKeys[0] : modalAllVisible.value.parentId,
}
if (rightActiveKey === 'createTask') {
options.url = '/api/catalogue/createTask'
options.url = API_CONSTANTS.CREATE_TASK_URL
options.parentId = modalAllVisible.isCreateTask && modalAllVisible.value.id
} else {
options.url = '/api/catalogue/saveOrUpdateCatalogue'
options.url = API_CONSTANTS.SAVE_OR_UPDATE_CATALOGUE_URL
}
await handleAddOrUpdate(options.url, {
...values,
isLeaf: options.isLeaf,
parentId: options.parentId,
}, () => {
setModalAllVisible((prevState) => ({...prevState, isCreateSub: false, isRename: false, isEdit: false,isCreateTask: false,isCut: false}));
dispatch({type: 'Studio/queryProject'});
dispatch({type: STUDIO_MODEL_ASYNC.queryProject});
if (modalAllVisible.isRename) {
// todo: 如果是重命名/修改(修改了名字), 则需要 更新 tab 的 label
......@@ -202,35 +209,35 @@ const Project: React.FC = (props: connect) => {
const handleDeleteSubmit = async () => {
const {key, isLeaf, name, type,taskId} = contextMenu.rightClickedNode;
handleContextCancel();
if (!isLeaf) {
await handleRemoveById('/api/catalogue/deleteCatalogueById', key, () => {
dispatch({type: 'Studio/queryProject'});
// TODO: 如果打开的 tag 中包含了这个 key 则更新 dav 的 tag 数据 删除此项 && 有一个 bug Dinky/src/pages/DataStudio/RightContainer/JobInfo/index.tsx:55 -> Cannot read properties of undefined (reading 'id')
});
} else {
const renderContent = () => {
return <>
<Text className={'needWrap'} type="danger">
{l('datastudio.project.delete.job.confirm')}
</Text>
</>
};
Modal.confirm({
title: l('datastudio.project.delete.job','',{type,name}),
width: '30%',
content: renderContent(),
okText: l('button.confirm'),
cancelText: l('button.cancel'),
onOk: async () => {
await handleRemoveById('/api/catalogue/deleteCatalogueById', key, () => {
// TODO: 如果打开的 tag 中包含了这个 key 则更新 dav 的 tag 数据 删除此项
dispatch({type: 'Studio/removeTag', payload: taskId});
dispatch({type: 'Studio/queryProject'});
});
},
});
}
if (!isLeaf) {
await handleRemoveById(API_CONSTANTS.DELETE_CATALOGUE_BY_ID_URL, key, () => {
dispatch({type: STUDIO_MODEL_ASYNC.queryProject});
// TODO: 如果打开的 tag 中包含了这个 key 则更新 dav 的 tag 数据 删除此项 && 有一个 bug Dinky/src/pages/DataStudio/RightContainer/JobInfo/index.tsx:55 -> Cannot read properties of undefined (reading 'id')
});
return;
}
const renderContent = () => {
return (
<Text className={'needWrap'} type="danger">
{l('datastudio.project.delete.job.confirm')}
</Text>);
};
Modal.confirm({
title: l('datastudio.project.delete.job', '', {type, name}),
width: '30%',
content: renderContent(),
okText: l('button.confirm'),
cancelText: l('button.cancel'),
onOk: async () => {
await handleRemoveById(API_CONSTANTS.DELETE_CATALOGUE_BY_ID_URL, key, () => {
// TODO: 如果打开的 tag 中包含了这个 key 则更新 dav 的 tag 数据 删除此项
dispatch({type: STUDIO_MODEL.removeTag, payload: taskId});
dispatch({type: STUDIO_MODEL_ASYNC.queryProject});
});
},
});
}
......@@ -264,10 +271,10 @@ const Project: React.FC = (props: connect) => {
* @returns {Promise<void>}
*/
const handleCopy = async () => {
await handleOption('/api/catalogue/copyTask', l('right.menu.copy'),{
await handleOption(API_CONSTANTS.COPY_TASK_URL, l('right.menu.copy'),{
...modalAllVisible.value,
},()=>{
dispatch({type: 'Studio/queryProject'});
dispatch({type: STUDIO_MODEL_ASYNC.queryProject});
});
handleContextCancel();
}
......@@ -287,11 +294,11 @@ const Project: React.FC = (props: connect) => {
* @returns {Promise<void>}
*/
const handlePaste = async () => {
await handlePutDataByParams('/api/catalogue/moveCatalogue', l('right.menu.paste'),{
await handlePutDataByParams(API_CONSTANTS.MOVE_CATALOGUE_URL, l('right.menu.paste'),{
originCatalogueId: cutId,
targetParentId: contextMenu.selectedKeys[0],
},()=>{
dispatch({type: 'Studio/queryProject'});
dispatch({type: STUDIO_MODEL_ASYNC.queryProject});
// 重置 cutId
setCutId(undefined);
setModalAllVisible(prevState => ({...prevState, isCut: false}));
......@@ -308,10 +315,10 @@ const Project: React.FC = (props: connect) => {
setRightActiveKey(node.key);
switch (node.key) {
case 'addSubFolder':
await handleCreateSubFolder();
handleCreateSubFolder();
break;
case 'createTask':
await handleCreateTask();
handleCreateTask();
break;
case 'delete':
await handleDeleteSubmit();
......@@ -320,7 +327,7 @@ const Project: React.FC = (props: connect) => {
await handleRename();
break;
case 'edit':
await handleEdit();
handleEdit();
break;
case 'exportJson':
// todo: 导出 json
......@@ -336,7 +343,7 @@ const Project: React.FC = (props: connect) => {
await handlePaste();
break;
default:
await handleContextCancel();
handleContextCancel();
break;
}
};
......@@ -348,7 +355,7 @@ const Project: React.FC = (props: connect) => {
onNodeClick={(info: any) => onNodeClick(info)} treeData={props.data}/>
<RightContextMenu
contextMenuPosition={contextMenu.position} open={contextMenu.visible}
openChange={() => setContext((prevState) => ({...prevState, visible: false}))} items={contextMenu.item}
openChange={() => setContextMenu((prevState) => ({...prevState, visible: false}))} items={contextMenu.item}
onClick={handleMenuClick}
/>
{/* added sub folder */}
......@@ -379,7 +386,7 @@ const Project: React.FC = (props: connect) => {
/>
{/* edit task */}
{
Object.keys(modalAllVisible.value).length > 0 && <>
Object.keys(modalAllVisible.value).length > 0 &&
<JobModal
title={l('button.edit')}
values={modalAllVisible.value}
......@@ -387,10 +394,7 @@ const Project: React.FC = (props: connect) => {
onCancel={() => setModalAllVisible((prevState) => ({...prevState, isEdit: false,value: {}}))}
onSubmit={handleSubmit}
/>
</>
}
</div>
)
};
......
......@@ -21,7 +21,7 @@ import {Tabs} from "antd";
import MovableSidebar, {MovableSidebarProps} from "@/components/Sidebar/MovableSidebar";
import React, {useState} from "react";
import {connect} from "@@/exports";
import {StateType, VIEW} from "@/pages/DataStudio/model";
import {StateType, STUDIO_MODEL, VIEW} from "@/pages/DataStudio/model";
import {BtnRoute, LeftSide} from "@/pages/DataStudio/route";
import useThemeValue from "@/hooks/useThemeValue";
import {CircleBtn, CircleButtonProps} from "@/components/CallBackButton/CircleBtn";
......@@ -41,7 +41,7 @@ const LeftContainer: React.FC<LeftContainerProps> = (props: any) => {
*/
const handleReSizeChange = (width: any) => {
dispatch({
type: 'Studio/updateLeftWidth',
type: STUDIO_MODEL.updateLeftWidth,
payload: width,
})
}
......@@ -51,7 +51,7 @@ const LeftContainer: React.FC<LeftContainerProps> = (props: any) => {
*/
const handleMinimize = () => {
dispatch({
type: 'Studio/updateSelectLeftKey',
type: STUDIO_MODEL.updateSelectLeftKey,
payload: "",
})
}
......
......@@ -5,6 +5,7 @@ import {QueryParams} from "@/pages/RegCenter/DataSource/components/DataSourceDet
import {l} from "@/utils/intl";
import {getFooterValue} from "@/pages/DataStudio/function";
import {getTaskData} from "@/pages/DataStudio/LeftContainer/Project/service";
import {createModelTypes} from "@/utils/modals";
/**
* 初始化布局宽高度
......@@ -237,6 +238,7 @@ export type StateType = {
bottomContainerContent: BottomContainerContent;
footContainer: FooterType;
};
export type ModelType = {
namespace: string;
state: StateType;
......@@ -274,44 +276,8 @@ export type ModelType = {
};
};
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,
namespace: 'Studio',
state: {
isFullScreen: false,
toolContentHeight: 0,
......@@ -815,4 +781,6 @@ const Model: ModelType = {
}
}
export const [STUDIO_MODEL, STUDIO_MODEL_ASYNC] = createModelTypes(Model);
export default Model;
......@@ -35,6 +35,7 @@ import {DangerDeleteIcon} from "@/components/Icons/CustomIcons";
import DescriptionsItem from "antd/es/descriptions/Item";
import AlertGroupForm from "@/pages/RegCenter/Alert/AlertGroup/components/AlertGroupForm";
import Pop from "@/components/Animation/Pop";
import {ALERT_MODEL_ASYNC} from "@/pages/RegCenter/Alert/AlertInstance/model";
const AlertGroupTableList: React.FC = (props: any) => {
/**
......@@ -256,7 +257,7 @@ const AlertGroupTableList: React.FC = (props: any) => {
const mapDispatchToProps = (dispatch: Dispatch) => ({
queryInstance: () => dispatch({
type: "Alert/queryInstance",
type: ALERT_MODEL_ASYNC.queryInstance,
payload: {},
}),
});
......
......@@ -21,6 +21,7 @@ import AlertInstanceList from '@/pages/RegCenter/Alert/AlertInstance/components/
import {PageContainer} from '@ant-design/pro-components';
import Scale from '@/components/Animation/Scale';
export {ALERT_MODEL, ALERT_MODEL_ASYNC} from '@/pages/RegCenter/Alert/AlertInstance/model';
export default () => {
return <Scale>
......
......@@ -20,6 +20,9 @@ import {Reducer} from "umi";
import {Alert} from "@/types/RegCenter/data.d";
import {showAlertInstance} from "@/pages/RegCenter/Alert/AlertGroup/service";
import {Effect} from "@@/plugin-dva/types";
import {createModelTypes} from "@/utils/modals";
export type AlertStateType = {
instance:Alert.AlertInstance[],
group:Alert.AlertGroup[]
......@@ -29,6 +32,7 @@ export type AlertModelType = {
namespace: string;
state: AlertStateType;
effects: {
queryInstance: Effect;
};
reducers: {
saveInstance: Reducer<AlertStateType>;
......@@ -66,4 +70,6 @@ const AlertModel: AlertModelType = {
},
};
export const [ALERT_MODEL, ALERT_MODEL_ASYNC] = createModelTypes(AlertModel);
export default AlertModel;
......@@ -251,6 +251,12 @@ export const API_CONSTANTS = {
RESOURCE_RENAME:'/api/resource/rename',
RESOURCE_UPLOAD:'/api/resource/uploadFile',
// catalog
DELETE_CATALOGUE_BY_ID_URL: '/api/catalogue/deleteCatalogueById',
CREATE_TASK_URL: '/api/catalogue/createTask',
SAVE_OR_UPDATE_CATALOGUE_URL: '/api/catalogue/saveOrUpdateCatalogue',
COPY_TASK_URL: '/api/catalogue/copyTask',
MOVE_CATALOGUE_URL: '/api/catalogue/moveCatalogue',
};
......
......@@ -47,3 +47,16 @@ export const ErrorModelWithCode = (title: any = l('global.error'), content: stri
/>
)
}
export const createModelTypes = (target: any) => {
type type = typeof target;
const MODEL_SYNC: {[K in keyof type['reducers']]: string} = Object.fromEntries(
new Map<keyof type['reducers'], string>(Object.keys(target['reducers']).map((obj: any) => [obj, `${target.namespace}/${obj}`])));
const MODEL_ASYNC: {[K in keyof type['effects']]: string} = Object.fromEntries(
new Map<keyof type['effects'], string>(Object.keys(target['effects']).map((obj: any) => [obj, `${target.namespace}/${obj}`])));
return [MODEL_SYNC, MODEL_ASYNC];
};
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