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,14 +22,13 @@ import {ProForm, ProFormText} from "@ant-design/pro-components"; ...@@ -22,14 +22,13 @@ import {ProForm, ProFormText} from "@ant-design/pro-components";
import {l} from "@/utils/intl"; import {l} from "@/utils/intl";
const FolderForm = () => { const FolderForm = () => {
return <> return (
<ProFormText <ProFormText
name="name" name="name"
label={l('datastudio.project.create.folder.name')} label={l('datastudio.project.create.folder.name')}
placeholder={l('datastudio.project.create.folder.name.placeholder')} placeholder={l('datastudio.project.create.folder.name.placeholder')}
rules={[ {required: true, message: l('datastudio.project.create.folder.name.placeholder')} ]} rules={[ {required: true, message: l('datastudio.project.create.folder.name.placeholder')} ]}
/> />)
</>
}; };
......
...@@ -39,11 +39,7 @@ type JobModalProps = { ...@@ -39,11 +39,7 @@ type JobModalProps = {
const JobModal: React.FC<JobModalProps> = (props) => { const JobModal: React.FC<JobModalProps> = (props) => {
const {onCancel, onSubmit, modalVisible, title, values} = props; const {onCancel, onSubmit, modalVisible, title, values} = props;
const [jobType, setJobType] = React.useState<string>(values.type || ''); const [jobType, setJobType] = React.useState<string>(values.type || '');
const [form] = Form.useForm<Catalogue>(); const [form] = Form.useForm<Catalogue>();
/** /**
...@@ -72,7 +68,6 @@ const JobModal: React.FC<JobModalProps> = (props) => { ...@@ -72,7 +68,6 @@ const JobModal: React.FC<JobModalProps> = (props) => {
formContext.resetForm(); formContext.resetForm();
}; };
/** /**
* form values change * form values change
* @param changedValues * @param changedValues
...@@ -82,7 +77,6 @@ const JobModal: React.FC<JobModalProps> = (props) => { ...@@ -82,7 +77,6 @@ const JobModal: React.FC<JobModalProps> = (props) => {
if (allValues.type) setJobType(allValues.type); if (allValues.type) setJobType(allValues.type);
} }
/** /**
* submit form * submit form
*/ */
...@@ -93,7 +87,6 @@ const JobModal: React.FC<JobModalProps> = (props) => { ...@@ -93,7 +87,6 @@ const JobModal: React.FC<JobModalProps> = (props) => {
onSubmit({...values, ...formData} as Catalogue); onSubmit({...values, ...formData} as Catalogue);
}; };
const renderForm = () => { const renderForm = () => {
return <> return <>
<ProFormSelect <ProFormSelect
......
...@@ -64,7 +64,7 @@ const JobTree: React.FC<TreeProps & connect> = (props) => { ...@@ -64,7 +64,7 @@ const JobTree: React.FC<TreeProps & connect> = (props) => {
value = String(value).trim(); value = String(value).trim();
const expandList: any[] = generateList(data, []); const expandList: any[] = generateList(data, []);
let expandedKeys: any = expandList.map((item: any) => { 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 getParentKey(item.key, data);
} }
return null; return null;
......
...@@ -22,11 +22,12 @@ import {Space} from "antd"; ...@@ -22,11 +22,12 @@ import {Space} from "antd";
import Title from "@/components/Front/Title"; import Title from "@/components/Front/Title";
import {l} from "@/utils/intl"; import {l} from "@/utils/intl";
import {connect} from "@umijs/max"; 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 {Catalogue} from "@/types/Studio/data";
import {handleAddOrUpdate} from "@/services/BusinessCrud"; import {handleAddOrUpdate} from "@/services/BusinessCrud";
import {BtnRoute} from "@/pages/DataStudio/route"; import {BtnRoute} from "@/pages/DataStudio/route";
import FolderModal from "@/pages/DataStudio/LeftContainer/Project/FolderModal"; import FolderModal from "@/pages/DataStudio/LeftContainer/Project/FolderModal";
import {API_CONSTANTS} from "@/services/constants";
const ProjectTitle: React.FC<StateType & connect> = (props) => { const ProjectTitle: React.FC<StateType & connect> = (props) => {
...@@ -53,13 +54,13 @@ const ProjectTitle: React.FC<StateType & connect> = (props) => { ...@@ -53,13 +54,13 @@ const ProjectTitle: React.FC<StateType & connect> = (props) => {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
const handleSubmit = async (values: Catalogue) => { const handleSubmit = async (values: Catalogue) => {
await handleAddOrUpdate('/api/catalogue/saveOrUpdateCatalogue', { await handleAddOrUpdate(API_CONSTANTS.SAVE_OR_UPDATE_CATALOGUE_URL, {
...values, ...values,
isLeaf: false, isLeaf: false,
parentId: 0, parentId: 0,
}, ()=>{ }, ()=>{
handleCancelCreate(); handleCancelCreate();
dispatch({type: 'Studio/queryProject'}); dispatch({type: STUDIO_MODEL_ASYNC.queryProject});
}); });
}; };
......
...@@ -57,7 +57,7 @@ export const buildProjectTree = (data: Catalogue[], searchValue: string = '', pa ...@@ -57,7 +57,7 @@ export const buildProjectTree = (data: Catalogue[], searchValue: string = '', pa
label: searchTreeNode(item.name, searchValue), label: searchTreeNode(item.name, searchValue),
icon: (item.type && item.children.length === 0) && getTabIcon(item.type,20), icon: (item.type && item.children.length === 0) && getTabIcon(item.type,20),
value: item.id, value: item.id,
path: path || [], path: path ?? [],
type: item.type, type: item.type,
title: <>{searchTreeNode(item.name, searchValue)}</>, title: <>{searchTreeNode(item.name, searchValue)}</>,
fullInfo: item, fullInfo: item,
......
...@@ -21,7 +21,7 @@ import {Tabs} from "antd"; ...@@ -21,7 +21,7 @@ import {Tabs} from "antd";
import MovableSidebar, {MovableSidebarProps} from "@/components/Sidebar/MovableSidebar"; import MovableSidebar, {MovableSidebarProps} from "@/components/Sidebar/MovableSidebar";
import React, {useState} from "react"; import React, {useState} from "react";
import {connect} from "@@/exports"; 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 {BtnRoute, LeftSide} from "@/pages/DataStudio/route";
import useThemeValue from "@/hooks/useThemeValue"; import useThemeValue from "@/hooks/useThemeValue";
import {CircleBtn, CircleButtonProps} from "@/components/CallBackButton/CircleBtn"; import {CircleBtn, CircleButtonProps} from "@/components/CallBackButton/CircleBtn";
...@@ -41,7 +41,7 @@ const LeftContainer: React.FC<LeftContainerProps> = (props: any) => { ...@@ -41,7 +41,7 @@ const LeftContainer: React.FC<LeftContainerProps> = (props: any) => {
*/ */
const handleReSizeChange = (width: any) => { const handleReSizeChange = (width: any) => {
dispatch({ dispatch({
type: 'Studio/updateLeftWidth', type: STUDIO_MODEL.updateLeftWidth,
payload: width, payload: width,
}) })
} }
...@@ -51,7 +51,7 @@ const LeftContainer: React.FC<LeftContainerProps> = (props: any) => { ...@@ -51,7 +51,7 @@ const LeftContainer: React.FC<LeftContainerProps> = (props: any) => {
*/ */
const handleMinimize = () => { const handleMinimize = () => {
dispatch({ dispatch({
type: 'Studio/updateSelectLeftKey', type: STUDIO_MODEL.updateSelectLeftKey,
payload: "", payload: "",
}) })
} }
......
...@@ -5,6 +5,7 @@ import {QueryParams} from "@/pages/RegCenter/DataSource/components/DataSourceDet ...@@ -5,6 +5,7 @@ import {QueryParams} from "@/pages/RegCenter/DataSource/components/DataSourceDet
import {l} from "@/utils/intl"; import {l} from "@/utils/intl";
import {getFooterValue} from "@/pages/DataStudio/function"; import {getFooterValue} from "@/pages/DataStudio/function";
import {getTaskData} from "@/pages/DataStudio/LeftContainer/Project/service"; import {getTaskData} from "@/pages/DataStudio/LeftContainer/Project/service";
import {createModelTypes} from "@/utils/modals";
/** /**
* 初始化布局宽高度 * 初始化布局宽高度
...@@ -237,6 +238,7 @@ export type StateType = { ...@@ -237,6 +238,7 @@ export type StateType = {
bottomContainerContent: BottomContainerContent; bottomContainerContent: BottomContainerContent;
footContainer: FooterType; footContainer: FooterType;
}; };
export type ModelType = { export type ModelType = {
namespace: string; namespace: string;
state: StateType; state: StateType;
...@@ -274,44 +276,8 @@ export type ModelType = { ...@@ -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 = { const Model: ModelType = {
namespace: ModelTypeName, namespace: 'Studio',
state: { state: {
isFullScreen: false, isFullScreen: false,
toolContentHeight: 0, toolContentHeight: 0,
...@@ -815,4 +781,6 @@ const Model: ModelType = { ...@@ -815,4 +781,6 @@ const Model: ModelType = {
} }
} }
export const [STUDIO_MODEL, STUDIO_MODEL_ASYNC] = createModelTypes(Model);
export default Model; export default Model;
...@@ -35,6 +35,7 @@ import {DangerDeleteIcon} from "@/components/Icons/CustomIcons"; ...@@ -35,6 +35,7 @@ import {DangerDeleteIcon} from "@/components/Icons/CustomIcons";
import DescriptionsItem from "antd/es/descriptions/Item"; import DescriptionsItem from "antd/es/descriptions/Item";
import AlertGroupForm from "@/pages/RegCenter/Alert/AlertGroup/components/AlertGroupForm"; import AlertGroupForm from "@/pages/RegCenter/Alert/AlertGroup/components/AlertGroupForm";
import Pop from "@/components/Animation/Pop"; import Pop from "@/components/Animation/Pop";
import {ALERT_MODEL_ASYNC} from "@/pages/RegCenter/Alert/AlertInstance/model";
const AlertGroupTableList: React.FC = (props: any) => { const AlertGroupTableList: React.FC = (props: any) => {
/** /**
...@@ -256,7 +257,7 @@ const AlertGroupTableList: React.FC = (props: any) => { ...@@ -256,7 +257,7 @@ const AlertGroupTableList: React.FC = (props: any) => {
const mapDispatchToProps = (dispatch: Dispatch) => ({ const mapDispatchToProps = (dispatch: Dispatch) => ({
queryInstance: () => dispatch({ queryInstance: () => dispatch({
type: "Alert/queryInstance", type: ALERT_MODEL_ASYNC.queryInstance,
payload: {}, payload: {},
}), }),
}); });
......
...@@ -21,6 +21,7 @@ import AlertInstanceList from '@/pages/RegCenter/Alert/AlertInstance/components/ ...@@ -21,6 +21,7 @@ import AlertInstanceList from '@/pages/RegCenter/Alert/AlertInstance/components/
import {PageContainer} from '@ant-design/pro-components'; import {PageContainer} from '@ant-design/pro-components';
import Scale from '@/components/Animation/Scale'; import Scale from '@/components/Animation/Scale';
export {ALERT_MODEL, ALERT_MODEL_ASYNC} from '@/pages/RegCenter/Alert/AlertInstance/model';
export default () => { export default () => {
return <Scale> return <Scale>
......
...@@ -20,6 +20,9 @@ import {Reducer} from "umi"; ...@@ -20,6 +20,9 @@ import {Reducer} from "umi";
import {Alert} from "@/types/RegCenter/data.d"; import {Alert} from "@/types/RegCenter/data.d";
import {showAlertInstance} from "@/pages/RegCenter/Alert/AlertGroup/service"; import {showAlertInstance} from "@/pages/RegCenter/Alert/AlertGroup/service";
import {Effect} from "@@/plugin-dva/types";
import {createModelTypes} from "@/utils/modals";
export type AlertStateType = { export type AlertStateType = {
instance:Alert.AlertInstance[], instance:Alert.AlertInstance[],
group:Alert.AlertGroup[] group:Alert.AlertGroup[]
...@@ -29,6 +32,7 @@ export type AlertModelType = { ...@@ -29,6 +32,7 @@ export type AlertModelType = {
namespace: string; namespace: string;
state: AlertStateType; state: AlertStateType;
effects: { effects: {
queryInstance: Effect;
}; };
reducers: { reducers: {
saveInstance: Reducer<AlertStateType>; saveInstance: Reducer<AlertStateType>;
...@@ -66,4 +70,6 @@ const AlertModel: AlertModelType = { ...@@ -66,4 +70,6 @@ const AlertModel: AlertModelType = {
}, },
}; };
export const [ALERT_MODEL, ALERT_MODEL_ASYNC] = createModelTypes(AlertModel);
export default AlertModel; export default AlertModel;
...@@ -251,6 +251,12 @@ export const API_CONSTANTS = { ...@@ -251,6 +251,12 @@ export const API_CONSTANTS = {
RESOURCE_RENAME:'/api/resource/rename', RESOURCE_RENAME:'/api/resource/rename',
RESOURCE_UPLOAD:'/api/resource/uploadFile', 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 ...@@ -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