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

refactor: replace all model type string, add generic define, fix cannot jump (#2232)

* 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 * chore * fix: IDE jump problem * refactor: change all model type string to variable * refactor: rename --------- Signed-off-by: 's avatarLicho <lecho.sun@gmail.com>
parent 37a9a8d8
import React, {useEffect, useState} from "react";
import MovableSidebar from "@/components/Sidebar/MovableSidebar";
import {l} from "@/utils/intl";
import {StateType, VIEW} from "@/pages/DataStudio/model";
import {StateType, STUDIO_MODEL, VIEW} from "@/pages/DataStudio/model";
import {ConfigProvider, Space, Tabs} from "antd";
import {LeftBottomMoreTabs, LeftBottomSide} from "@/pages/DataStudio/route";
import {connect} from "@@/exports";
......@@ -22,7 +22,7 @@ const BottomContainer: React.FC<BottomContainerProps> = (props: any) => {
*/
const handleMinimize = () => {
dispatch({
type: 'Studio/updateSelectBottomKey',
type: STUDIO_MODEL.updateSelectBottomKey,
payload: "",
})
}
......@@ -33,7 +33,7 @@ const BottomContainer: React.FC<BottomContainerProps> = (props: any) => {
*/
const updateBottomHeight = (height: number) => {
dispatch({
type: "Studio/updateBottomHeight",
type: STUDIO_MODEL.updateBottomHeight,
payload: height,
})
}
......@@ -44,14 +44,14 @@ const BottomContainer: React.FC<BottomContainerProps> = (props: any) => {
*/
const updateCenterContentHeight = (height: number) => {
dispatch({
type: "Studio/updateCenterContentHeight",
type: STUDIO_MODEL.updateCenterContentHeight,
payload: height,
})
}
const updateSelectBottomSubKey = (key: string) => {
dispatch({
type: "Studio/updateSelectBottomSubKey",
type: STUDIO_MODEL.updateSelectBottomSubKey,
payload: key,
})
}
......@@ -62,7 +62,7 @@ const BottomContainer: React.FC<BottomContainerProps> = (props: any) => {
*/
const updateToolContentHeight = (height: number) => {
dispatch({
type: "Studio/updateToolContentHeight",
type: STUDIO_MODEL.updateToolContentHeight,
payload: height,
})
}
......
import {connect} from "@umijs/max";
import { StateType} from "../../model";
import {StateType, STUDIO_MODEL} from "../../model";
import {Spin, Tag} from "antd";
import React, {useEffect, useState} from "react";
import {
......@@ -105,7 +105,7 @@ const MetaData = (props: any) => {
const handleTreeNodeClick = async (keys: Key[] ,info: any) => {
// 选中的key
dispatch({
type: "Studio/updateDatabaseSelectKey",
type: STUDIO_MODEL.updateDatabaseSelectKey,
payload: keys
})
......@@ -113,7 +113,7 @@ const MetaData = (props: any) => {
if (isLeaf) {
const queryParams = {id: selectDatabaseId , schemaName, tableName};
dispatch({
type: "Studio/addTab",
type: STUDIO_MODEL.addTab,
payload: {
icon: selectDb.type,
id: selectDatabaseId + schemaName + tableName,
......@@ -132,7 +132,7 @@ const MetaData = (props: any) => {
*/
const handleSelectDataBaseId = (databaseId: number) => {
dispatch({
type: "Studio/updateSelectDatabaseId",
type: STUDIO_MODEL.updateSelectDatabaseId,
payload: databaseId
})
onChangeDataBase(databaseId);
......@@ -144,7 +144,7 @@ const MetaData = (props: any) => {
*/
const handleTreeExpand = (expandedKeys: Key[]) => {
dispatch({
type: "Studio/updateDatabaseExpandKey",
type: STUDIO_MODEL.updateDatabaseExpandKey,
payload: expandedKeys
})
}
......
import React from "react";
import CodeEdit from "@/components/CustomEditor/CodeEdit";
import {connect} from "@@/exports";
import {StateType} from "@/pages/DataStudio/model";
import {StateType, STUDIO_MODEL} from "@/pages/DataStudio/model";
import {getCurrentData} from "@/pages/DataStudio/function";
import {convertCodeEditTheme} from "@/utils/function";
import {editor} from "monaco-editor";
......@@ -61,7 +61,7 @@ const CodeEditor: React.FC<EditorProps & any > = (props) => {
editor.onDidChangeCursorPosition((e) => {
props.footContainer.codePosition=[e.position.lineNumber,e.position.column]
dispatch({
type: "Studio/saveFooterValue",
type: STUDIO_MODEL.saveFooterValue,
payload: {...props.footContainer},
});
});
......@@ -69,7 +69,7 @@ const CodeEditor: React.FC<EditorProps & any > = (props) => {
onChange={(v,d) => {
current.statement = v;
dispatch({
type: "Studio/saveTabs",
type: STUDIO_MODEL.saveTabs,
payload: {...props.tabs},
});
}}
......@@ -80,7 +80,7 @@ const CodeEditor: React.FC<EditorProps & any > = (props) => {
{/* onChange={(v,d) => {*/}
{/* current.statement = v;*/}
{/* dispatch({*/}
{/* type: "Studio/saveTabs",*/}
{/* type: STUDIO_MODEL.saveTabs,*/}
{/* payload: {...props.tabs},*/}
{/* });*/}
......
......@@ -20,7 +20,7 @@
import {InfoCircleOutlined} from "@ant-design/icons";
import {l} from "@/utils/intl";
import {connect} from "umi";
import {StateType} from "@/pages/DataStudio/model";
import {StateType, STUDIO_MODEL} from "@/pages/DataStudio/model";
import {useForm} from "antd/es/form/Form";
import {getCurrentData} from "@/pages/DataStudio/function";
import {SWITCH_OPTIONS} from "@/services/constants";
......@@ -44,7 +44,7 @@ const ExecuteConfig = (props: any) => {
}
}
dispatch({
type: "Studio/saveTabs",
type: STUDIO_MODEL.saveTabs,
payload: {...props.tabs},
});
};
......
......@@ -22,7 +22,7 @@ import {Badge, Space, Typography} from "antd";
import {l} from "@/utils/intl";
import {RUN_MODE, SWITCH_OPTIONS} from "@/services/constants";
import {connect} from "umi";
import {SessionType, StateType} from "@/pages/DataStudio/model";
import {SessionType, StateType, STUDIO_MODEL} from "@/pages/DataStudio/model";
import {AlertStateType} from "@/pages/RegCenter/Alert/AlertInstance/model";
import {getCurrentData} from "@/pages/DataStudio/function";
import {useForm} from "antd/es/form/Form";
......@@ -79,7 +79,7 @@ const JobConfig = (props: any) => {
}
}
dispatch({
type: "Studio/saveTabs",
type: STUDIO_MODEL.saveTabs,
payload: {...props.tabs},
});
};
......
......@@ -23,7 +23,7 @@ import TextArea from "antd/es/input/TextArea";
import {l} from "@/utils/intl";
import Paragraph from "antd/es/typography/Paragraph";
import {connect} from "umi";
import { StateType } from "@/pages/DataStudio/model";
import {StateType, STUDIO_MODEL} from "@/pages/DataStudio/model";
import React from "react";
import {getCurrentData} from "@/pages/DataStudio/function";
import {useForm} from "antd/es/form/Form";
......@@ -43,7 +43,7 @@ const JobInfo = (props: any) => {
}
}
dispatch({
type: "Studio/saveTabs",
type: STUDIO_MODEL.saveTabs,
payload: {...props.tabs},
});
};
......
......@@ -20,72 +20,72 @@
import {Dispatch} from "@@/plugin-dva/types";
import {Cluster, DataSources} from "@/types/RegCenter/data";
import {DataStudioParams, EnvType, JobRunningMsgType, TabsItemType} from "@/pages/DataStudio/model";
import {DataStudioParams, EnvType, JobRunningMsgType, STUDIO_MODEL, TabsItemType} from "@/pages/DataStudio/model";
export const mapDispatchToProps = (dispatch: Dispatch) => ({
updateToolContentHeight: (key: number) => dispatch({
type: "Studio/updateToolContentHeight",
type: STUDIO_MODEL.updateToolContentHeight,
payload: key,
}),
updateCenterContentHeight: (key: number) => dispatch({
type: "Studio/updateCenterContentHeight",
type: STUDIO_MODEL.updateCenterContentHeight,
payload: key,
}),
updateSelectLeftKey: (key: string) => dispatch({
type: "Studio/updateSelectLeftKey",
type: STUDIO_MODEL.updateSelectLeftKey,
payload: key,
}),
updateLeftWidth: (width: number) => dispatch({
type: "Studio/updateLeftWidth",
type: STUDIO_MODEL.updateLeftWidth,
payload: width,
}), updateSelectRightKey: (key: string) => dispatch({
type: "Studio/updateSelectRightKey",
type: STUDIO_MODEL.updateSelectRightKey,
payload: key,
}),
updateRightWidth: (width: number) => dispatch({
type: "Studio/updateRightWidth",
type: STUDIO_MODEL.updateRightWidth,
payload: width,
}), updateSelectBottomKey: (key: string) => dispatch({
type: "Studio/updateSelectBottomKey",
type: STUDIO_MODEL.updateSelectBottomKey,
payload: key,
}), updateSelectBottomSubKey: (key: string) => dispatch({
type: "Studio/updateSelectBottomSubKey",
type: STUDIO_MODEL.updateSelectBottomSubKey,
payload: key,
}),
updateBottomHeight: (height: number) => dispatch({
type: "Studio/updateBottomHeight",
type: STUDIO_MODEL.updateBottomHeight,
payload: height,
}),
saveDataBase: (data: DataSources.DataSource[]) => dispatch({
type: "Studio/saveDataBase",
type: STUDIO_MODEL.saveDataBase,
payload: data,
}),
saveProject: (data: any[]) => dispatch({
type: "Studio/saveProject",
type: STUDIO_MODEL.saveProject,
payload: data,
}),
updateBottomConsole: (data: string) => dispatch({
type: "Studio/updateBottomConsole",
type: STUDIO_MODEL.updateBottomConsole,
payload: data,
}),
saveSession: (data: Cluster.Instance[]) => dispatch({
type: "Studio/saveSession",
type: STUDIO_MODEL.saveSession,
payload: data,
}),
saveEnv: (data: EnvType[]) => dispatch({
type: "Studio/saveEnv",
type: STUDIO_MODEL.saveEnv,
payload: data,
}),
saveTabs: (data: TabsItemType[]) => dispatch({
type: "Studio/saveTabs",
type: STUDIO_MODEL.saveTabs,
payload: data,
}),
saveClusterConfiguration: (data: Cluster.Config[]) => dispatch({
type: "Studio/saveClusterConfiguration",
type: STUDIO_MODEL.saveClusterConfiguration,
payload: data,
}),
updateJobRunningMsg: (data: JobRunningMsgType) => dispatch({
type: "Studio/updateJobRunningMsg",
type: STUDIO_MODEL.updateJobRunningMsg,
payload: data,
}),
......
......@@ -29,7 +29,7 @@ import {getDataByIdReturnResult} from '@/services/BusinessCrud';
import {Key, ProCard} from '@ant-design/pro-components';
import {QueryParams} from '@/pages/RegCenter/DataSource/components/DataSourceDetail/RightTagsRouter/data';
import {connect} from "@@/exports";
import {StateType} from "@/pages/DataStudio/model";
import {StateType, STUDIO_MODEL} from "@/pages/DataStudio/model";
const DataSourceDetail = (props : any) => {
const navigate = useNavigate();
......@@ -84,13 +84,13 @@ const DataSourceDetail = (props : any) => {
const {node: {isLeaf, parentId: schemaName, name: tableName, fullInfo}} = info;
// 选中的key
dispatch({
type: "Studio/updateDatabaseSelectKey",
type: STUDIO_MODEL.updateDatabaseSelectKey,
payload: keys
})
if (isLeaf) {
const queryParams = {id: selectDatabaseId , schemaName, tableName};
dispatch({
type: "Studio/addTab",
type: STUDIO_MODEL.addTab,
payload: {
icon: selectDb.type,
id: selectDatabaseId + schemaName + tableName,
......@@ -125,7 +125,7 @@ const DataSourceDetail = (props : any) => {
*/
const handleTreeExpand = (expandedKeys: Key[]) => {
dispatch({
type: "Studio/updateDatabaseExpandKey",
type: STUDIO_MODEL.updateDatabaseExpandKey,
payload: expandedKeys
})
}
......
......@@ -48,13 +48,18 @@ 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}`])));
// @ts-ignore
export const createModelTypes = <T extends any>(target: T): [{[K in keyof T['reducers']]: string}, {[K in keyof T['effects']]: string}] => {
type TargetType = typeof target;
// @ts-ignore
const MODEL_SYNC: {[K in keyof TargetType['reducers']]: string} = Object.fromEntries(// @ts-ignore
new Map<keyof TargetType['reducers'], string>(Object.keys(target['reducers']).map((obj: string) => [obj, `${target.namespace}/${obj}`])));
// @ts-ignore
const MODEL_ASYNC: {[K in keyof TargetType['effects']]: string} = Object.fromEntries(// @ts-ignore
new Map<keyof TargetType['effects'], string>(Object.keys(target['effects']).map((obj: string) => [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