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 {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