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