Unverified Commit 9a3cb09e authored by Licho's avatar Licho Committed by GitHub

feat: add explain error line for some (#2657)

* feat: add explain error line for some Signed-off-by: 's avatarlicho <lecho.sun@gmail.com> * Spotless Apply --------- Signed-off-by: 's avatarlicho <lecho.sun@gmail.com> Co-authored-by: 's avatarleechor <leechor@users.noreply.github.com>
parent 4a932b74
...@@ -59,6 +59,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; ...@@ -59,6 +59,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.text.StrFormatter;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -209,7 +210,10 @@ public class Explainer { ...@@ -209,7 +210,10 @@ public class Explainer {
} }
executor.executeSql(item.getValue()); executor.executeSql(item.getValue());
} catch (Exception e) { } catch (Exception e) {
String error = LogUtil.getError(e); String error = StrFormatter.format(
"Exception in executing FlinkSQL:\n{}\n{}",
SqlUtil.addLineNumber(item.getValue()),
e.getMessage());
record.setError(error); record.setError(error);
record.setExplainTrue(false); record.setExplainTrue(false);
record.setExplainTime(LocalDateTime.now()); record.setExplainTime(LocalDateTime.now());
...@@ -264,7 +268,10 @@ public class Explainer { ...@@ -264,7 +268,10 @@ public class Explainer {
record.setParseTrue(true); record.setParseTrue(true);
record.setExplainTrue(true); record.setExplainTrue(true);
} catch (Exception e) { } catch (Exception e) {
String error = LogUtil.getError(e); String error = StrFormatter.format(
"Exception in executing FlinkSQL:\n{}\n{}",
SqlUtil.addLineNumber(item.getValue()),
e.getMessage());
record.setError(error); record.setError(error);
record.setParseTrue(false); record.setParseTrue(false);
record.setExplainTrue(false); record.setExplainTrue(false);
...@@ -292,7 +299,10 @@ public class Explainer { ...@@ -292,7 +299,10 @@ public class Explainer {
record.setType("DATASTREAM"); record.setType("DATASTREAM");
record.setParseTrue(true); record.setParseTrue(true);
} catch (Exception e) { } catch (Exception e) {
String error = LogUtil.getError(e); String error = StrFormatter.format(
"Exception in executing FlinkSQL:\n{}\n{}",
SqlUtil.addLineNumber(item.getValue()),
e.getMessage());
record.setError(error); record.setError(error);
record.setExplainTrue(false); record.setExplainTrue(false);
record.setExplainTime(LocalDateTime.now()); record.setExplainTime(LocalDateTime.now());
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
import CodeShow from '@/components/CustomEditor/CodeShow'; import CodeShow from '@/components/CustomEditor/CodeShow';
import { SseData } from '@/models/Sse'; import { SseData } from '@/models/Sse';
import {DataStudioTabsItemType, StateType, VIEW} from '@/pages/DataStudio/model'; import { DataStudioTabsItemType, StateType, VIEW } from '@/pages/DataStudio/model';
import { SSE_TOPIC } from '@/pages/DevOps/constants'; import { SSE_TOPIC } from '@/pages/DevOps/constants';
import { API_CONSTANTS } from '@/services/endpoints'; import { API_CONSTANTS } from '@/services/endpoints';
import { parseMilliSecondStr } from '@/utils/function'; import { parseMilliSecondStr } from '@/utils/function';
......
...@@ -17,21 +17,21 @@ ...@@ -17,21 +17,21 @@
* *
*/ */
import {getFooterValue, isDataStudioTabsItemType} from '@/pages/DataStudio/function'; import { getFooterValue, isDataStudioTabsItemType } from '@/pages/DataStudio/function';
import {getTaskData} from '@/pages/DataStudio/LeftContainer/Project/service'; import { getTaskData } from '@/pages/DataStudio/LeftContainer/Project/service';
import { import {
getFlinkConfigs, getFlinkConfigs,
querySuggessionData querySuggessionData
} from '@/pages/DataStudio/RightContainer/JobConfig/service'; } from '@/pages/DataStudio/RightContainer/JobConfig/service';
import {QueryParams} from '@/pages/RegCenter/DataSource/components/DataSourceDetail/RightTagsRouter/data'; import { QueryParams } from '@/pages/RegCenter/DataSource/components/DataSourceDetail/RightTagsRouter/data';
import {SuggestionInfo} from '@/types/Public/data'; import { SuggestionInfo } from '@/types/Public/data';
import {Cluster, DataSources} from '@/types/RegCenter/data'; import { Cluster, DataSources } from '@/types/RegCenter/data';
import {l} from '@/utils/intl'; import { l } from '@/utils/intl';
import {createModelTypes} from '@/utils/modelUtils'; import { createModelTypes } from '@/utils/modelUtils';
import {Effect, Reducer} from '@@/plugin-dva/types'; import { Effect, Reducer } from '@@/plugin-dva/types';
import {Monaco} from '@monaco-editor/react'; import { Monaco } from '@monaco-editor/react';
import {DefaultOptionType} from 'antd/es/select'; import { DefaultOptionType } from 'antd/es/select';
import {editor} from 'monaco-editor'; import { editor } from 'monaco-editor';
import React from 'react'; import React from 'react';
import ICodeEditor = editor.ICodeEditor; import ICodeEditor = editor.ICodeEditor;
...@@ -39,829 +39,835 @@ import ICodeEditor = editor.ICodeEditor; ...@@ -39,829 +39,835 @@ import ICodeEditor = editor.ICodeEditor;
* 初始化布局宽高度 * 初始化布局宽高度
*/ */
export const VIEW = { export const VIEW = {
headerHeight: 32, headerHeight: 32,
headerNavHeight: 56, headerNavHeight: 56,
footerHeight: 25, footerHeight: 25,
sideWidth: 40, sideWidth: 40,
leftToolWidth: 180, leftToolWidth: 180,
marginTop: 84, marginTop: 84,
topHeight: 35.6, topHeight: 35.6,
bottomHeight: 100, bottomHeight: 100,
rightMargin: 32, rightMargin: 32,
leftMargin: 36, leftMargin: 36,
midMargin: 44, midMargin: 44,
otherHeight: 0, otherHeight: 0,
paddingInline: 50 paddingInline: 50
}; };
export type SqlMetaData = { export type SqlMetaData = {
statement?: string; statement?: string;
metaData?: MetaData[]; metaData?: MetaData[];
}; };
export type MetaData = { export type MetaData = {
table: string; table: string;
connector: string; connector: string;
columns: Column[]; columns: Column[];
}; };
export type Column = { export type Column = {
name: string; name: string;
type: string; type: string;
}; };
type TargetKey = React.MouseEvent | React.KeyboardEvent | number; type TargetKey = React.MouseEvent | React.KeyboardEvent | number;
export type EnvType = { export type EnvType = {
id?: number; id?: number;
name?: string; name?: string;
fragment?: boolean; fragment?: boolean;
}; };
export type TaskType = { export type TaskType = {
id?: number; id?: number;
catalogueId?: number; catalogueId?: number;
name?: string; name?: string;
dialect?: string; dialect?: string;
type?: string; type?: string;
checkPoint?: number; checkPoint?: number;
savePointStrategy?: number; savePointStrategy?: number;
savePointPath?: string; savePointPath?: string;
parallelism?: number; parallelism?: number;
fragment?: boolean; fragment?: boolean;
statementSet?: boolean; statementSet?: boolean;
batchModel?: boolean; batchModel?: boolean;
config?: []; config?: [];
clusterId?: any; clusterId?: any;
clusterName?: string; clusterName?: string;
clusterConfigurationId?: number; clusterConfigurationId?: number;
clusterConfigurationName?: string; clusterConfigurationName?: string;
databaseId?: number; databaseId?: number;
databaseName?: string; databaseName?: string;
envId?: number; envId?: number;
jobInstanceId?: number; jobInstanceId?: number;
note?: string; note?: string;
enabled?: boolean; enabled?: boolean;
createTime?: Date; createTime?: Date;
updateTime?: Date; updateTime?: Date;
statement?: string; statement?: string;
session: string; session: string;
maxRowNum: number; maxRowNum: number;
jobName: string; jobName: string;
useChangeLog: boolean; useChangeLog: boolean;
useAutoCancel: boolean; useAutoCancel: boolean;
}; };
export type ConsoleType = { export type ConsoleType = {
// eslint-disable-next-line @typescript-eslint/ban-types // eslint-disable-next-line @typescript-eslint/ban-types
result: {}; result: {};
// eslint-disable-next-line @typescript-eslint/ban-types // eslint-disable-next-line @typescript-eslint/ban-types
chart: {}; chart: {};
}; };
export type MetadataParams = { export type MetadataParams = {
queryParams: QueryParams; queryParams: QueryParams;
// eslint-disable-next-line @typescript-eslint/ban-types // eslint-disable-next-line @typescript-eslint/ban-types
tableInfo: {}; tableInfo: {};
}; };
export type TaskDataBaseType = { export type TaskDataBaseType = {
id: number; id: number;
name: string; name: string;
statement: string; statement: string;
dialect: string; dialect: string;
step: number; step: number;
// Only common sql has(只有普通sql才有) // Only common sql has(只有普通sql才有)
databaseId?: number; databaseId?: number;
envId?: number; envId?: number;
}; };
export type TaskDataType = TaskDataBaseType & Record<string, any>; export type TaskDataType = TaskDataBaseType & Record<string, any>;
export type DataStudioParams = { export type DataStudioParams = {
taskId: number; taskId: number;
taskData: TaskDataType; taskData: TaskDataType;
}; };
export enum TabsPageType { export enum TabsPageType {
None = '', None = '',
metadata = 'metadata', metadata = 'metadata',
project = 'project' project = 'project'
} }
export enum TabsPageSubType { export enum TabsPageSubType {
flinkSql = 'FlinkSql', flinkSql = 'FlinkSql',
flinkJar = 'FlinkJar', flinkJar = 'FlinkJar',
None = '' None = ''
} }
export interface TabsItemType { export interface TabsItemType {
id: string; id: string;
label: string; label: string;
breadcrumbLabel: string; breadcrumbLabel: string;
type: TabsPageType; type: TabsPageType;
subType?: TabsPageSubType; subType?: TabsPageSubType;
key: string; key: string;
treeKey: number; treeKey: number;
value: string; value: string;
icon: any; icon: any;
closable: boolean; closable: boolean;
path: string[]; path: string[];
monacoInstance: React.RefObject<Monaco | undefined>; monacoInstance: React.RefObject<Monaco | undefined>;
console: ConsoleType; console: ConsoleType;
isModified: boolean; isModified: boolean;
} }
export interface MetadataTabsItemType extends TabsItemType { export interface MetadataTabsItemType extends TabsItemType {
params: MetadataParams; params: MetadataParams;
sqlMetaData?: SqlMetaData; sqlMetaData?: SqlMetaData;
metaStore?: MetaStoreCatalogType[]; metaStore?: MetaStoreCatalogType[];
} }
export interface DataStudioTabsItemType extends TabsItemType { export interface DataStudioTabsItemType extends TabsItemType {
task?: TaskType; task?: TaskType;
monaco?: ICodeEditor; monaco?: ICodeEditor;
params: DataStudioParams; params: DataStudioParams;
} }
export type TabsType = { export type TabsType = {
activeKey: string; activeKey: string;
activeBreadcrumbTitle: string; activeBreadcrumbTitle: string;
panes: TabsItemType[]; panes: TabsItemType[];
}; };
export type ConnectorType = { export type ConnectorType = {
tableName: string; tableName: string;
}; };
export type MetaStoreCatalogType = { export type MetaStoreCatalogType = {
name: string; name: string;
databases: MetaStoreDataBaseType[]; databases: MetaStoreDataBaseType[];
}; };
export type MetaStoreDataBaseType = { export type MetaStoreDataBaseType = {
name: string; name: string;
tables: MetaStoreTableType[]; tables: MetaStoreTableType[];
views: string[]; views: string[];
functions: string[]; functions: string[];
userFunctions: string[]; userFunctions: string[];
modules: string[]; modules: string[];
}; };
export type MetaStoreTableType = { export type MetaStoreTableType = {
name: string; name: string;
columns: MetaStoreColumnType[]; columns: MetaStoreColumnType[];
}; };
export type MetaStoreColumnType = { export type MetaStoreColumnType = {
name: string; name: string;
type: string; type: string;
}; };
export type Container = { export type Container = {
selectKey: string; selectKey: string;
selectSubKey: { [c: string]: string }; selectSubKey: { [c: string]: string };
height: number | string; height: number | string;
width: number | string; width: number | string;
maxWidth?: number | string; maxWidth?: number | string;
}; };
export type BottomContainerContent = { export type BottomContainerContent = {
console: string; console: string;
}; };
export type SessionType = { export type SessionType = {
session?: string; session?: string;
sessionConfig?: { sessionConfig?: {
type?: string; type?: string;
clusterId?: number; clusterId?: number;
clusterName?: string; clusterName?: string;
address?: string; address?: string;
}; };
createUser?: string; createUser?: string;
createTime?: string; createTime?: string;
connectors: ConnectorType[]; connectors: ConnectorType[];
}; };
/** /**
* job running type msg * job running type msg
*/ */
export type JobRunningMsgType = { export type JobRunningMsgType = {
taskId: number | null; taskId: number | null;
jobName: string; jobName: string;
jobState: string; jobState: string;
runningLog: string; runningLog: string;
}; };
/** /**
* footer * footer
*/ */
export type FooterType = { export type FooterType = {
codePosition: [number, number]; codePosition: [number, number];
space: number; space: number;
codeEncoding: string; codeEncoding: string;
lineSeparator: string; lineSeparator: string;
codeType: string; codeType: string;
memDetails: string; memDetails: string;
jobRunningMsg: JobRunningMsgType; jobRunningMsg: JobRunningMsgType;
}; };
/** /**
* state type overview * state type overview
*/ */
export type StateType = { export type StateType = {
isFullScreen: boolean; isFullScreen: boolean;
toolContentHeight: number; toolContentHeight: number;
centerContentHeight: number; centerContentHeight: number;
leftContainer: Container; leftContainer: Container;
rightContainer: Container; rightContainer: Container;
bottomContainer: Container; bottomContainer: Container;
database: { database: {
dbData: DataSources.DataSource[]; dbData: DataSources.DataSource[];
selectDatabaseId: number | null; selectDatabaseId: number | null;
expandKeys: []; expandKeys: [];
selectKey: []; selectKey: [];
}; };
project: { project: {
data: any[]; data: any[];
// selectId: number | null; // selectId: number | null;
expandKeys: []; expandKeys: [];
selectKey: []; selectKey: [];
}; };
sessionCluster: Cluster.Instance[]; sessionCluster: Cluster.Instance[];
clusterConfiguration: Cluster.Config[]; clusterConfiguration: Cluster.Config[];
flinkConfigOptions: DefaultOptionType[]; flinkConfigOptions: DefaultOptionType[];
env: EnvType[]; env: EnvType[];
tabs: TabsType; tabs: TabsType;
bottomContainerContent: BottomContainerContent; bottomContainerContent: BottomContainerContent;
footContainer: FooterType; footContainer: FooterType;
suggestions: SuggestionInfo[]; suggestions: SuggestionInfo[];
}; };
export type ModelType = { export type ModelType = {
namespace: string; namespace: string;
state: StateType; state: StateType;
effects: { effects: {
queryProject: Effect; queryProject: Effect;
queryFlinkConfigOptions: Effect; queryFlinkConfigOptions: Effect;
querySuggestions: Effect; querySuggestions: Effect;
}; };
reducers: { reducers: {
updateToolContentHeight: Reducer<StateType>; updateToolContentHeight: Reducer<StateType>;
updateCenterContentHeight: Reducer<StateType>; updateCenterContentHeight: Reducer<StateType>;
updateSelectLeftKey: Reducer<StateType>; updateSelectLeftKey: Reducer<StateType>;
updateLeftWidth: Reducer<StateType>; updateLeftWidth: Reducer<StateType>;
updateSelectRightKey: Reducer<StateType>; updateSelectRightKey: Reducer<StateType>;
updateRightWidth: Reducer<StateType>; updateRightWidth: Reducer<StateType>;
updateSelectBottomKey: Reducer<StateType>; updateSelectBottomKey: Reducer<StateType>;
updateSelectBottomSubKey: Reducer<StateType>; updateSelectBottomSubKey: Reducer<StateType>;
updateBottomHeight: Reducer<StateType>; updateBottomHeight: Reducer<StateType>;
saveDataBase: Reducer<StateType>; saveDataBase: Reducer<StateType>;
saveProject: Reducer<StateType>; saveProject: Reducer<StateType>;
updateProjectExpandKey: Reducer<StateType>; updateProjectExpandKey: Reducer<StateType>;
updateProjectSelectKey: Reducer<StateType>; updateProjectSelectKey: Reducer<StateType>;
updateTabsActiveKey: Reducer<StateType>; updateTabsActiveKey: Reducer<StateType>;
closeTab: Reducer<StateType>; closeTab: Reducer<StateType>;
removeTag: Reducer<StateType>; removeTag: Reducer<StateType>;
addTab: Reducer<StateType>; addTab: Reducer<StateType>;
saveTabs: Reducer<StateType>; saveTabs: Reducer<StateType>;
closeAllTabs: Reducer<StateType>; closeAllTabs: Reducer<StateType>;
closeOtherTabs: Reducer<StateType>; closeOtherTabs: Reducer<StateType>;
updateSelectDatabaseId: Reducer<StateType>; updateSelectDatabaseId: Reducer<StateType>;
updateDatabaseExpandKey: Reducer<StateType>; updateDatabaseExpandKey: Reducer<StateType>;
updateDatabaseSelectKey: Reducer<StateType>; updateDatabaseSelectKey: Reducer<StateType>;
updateBottomConsole: Reducer<StateType>; updateBottomConsole: Reducer<StateType>;
saveSession: Reducer<StateType>; saveSession: Reducer<StateType>;
saveClusterConfiguration: Reducer<StateType>; saveClusterConfiguration: Reducer<StateType>;
saveEnv: Reducer<StateType>; saveEnv: Reducer<StateType>;
saveFooterValue: Reducer<StateType>; saveFooterValue: Reducer<StateType>;
updateJobRunningMsg: Reducer<StateType>; updateJobRunningMsg: Reducer<StateType>;
saveFlinkConfigOptions: Reducer<StateType>; saveFlinkConfigOptions: Reducer<StateType>;
updateSuggestions: Reducer<StateType>; updateSuggestions: Reducer<StateType>;
}; };
}; };
const Model: ModelType = { const Model: ModelType = {
namespace: 'Studio', namespace: 'Studio',
state: { state: {
isFullScreen: false, isFullScreen: false,
toolContentHeight: 0, toolContentHeight: 0,
centerContentHeight: 0, centerContentHeight: 0,
leftContainer: {
selectKey: 'menu.datastudio.project',
selectSubKey: {},
height: '100%',
width: 260
},
rightContainer: {
selectKey: '',
selectSubKey: {},
height: '100%',
width: 260
},
bottomContainer: {
selectKey: 'menu.datastudio.console',
selectSubKey: {},
height: 180,
width: '100%'
},
database: {
dbData: [],
selectDatabaseId: null,
expandKeys: [],
selectKey: []
},
project: {
data: [],
expandKeys: [],
selectKey: []
},
tabs: {
activeBreadcrumbTitle: '',
activeKey: '0',
panes: []
},
bottomContainerContent: {
console: ''
},
sessionCluster: [],
clusterConfiguration: [],
flinkConfigOptions: [],
env: [],
footContainer: {
codePosition: [1, 1],
space: 2,
codeEncoding: 'UTF-8',
lineSeparator: 'LF',
codeType: '',
memDetails: '100/500M',
jobRunningMsg: {
taskId: null,
jobName: '',
jobState: '',
runningLog: ''
}
},
suggestions: []
},
effects: {
*queryProject({ payload }, { call, put }) {
const response: [] = yield call(getTaskData, payload);
yield put({
type: 'saveProject',
payload: response
});
},
*queryFlinkConfigOptions({ payload }, { call, put }) {
const response: [] = yield call(getFlinkConfigs, payload);
yield put({
type: 'saveFlinkConfigOptions',
payload: response
});
},
*querySuggestions({ payload }, { call, put }) {
const response: SuggestionInfo[] = yield call(querySuggessionData, payload);
yield put({
type: 'updateSuggestions',
payload: response
});
}
},
reducers: {
/**
* 更新工具栏高度
*/
updateToolContentHeight(state, { payload }) {
if (payload != state.toolContentHeight) {
return {
...state,
toolContentHeight: payload
};
}
return state;
},
/**
* 更新中间内容高度
*/
updateCenterContentHeight(state, { payload }) {
if (payload != state.centerContentHeight) {
return {
...state,
centerContentHeight: payload
};
}
return state;
},
/**
* 更新左侧选中key
*/
updateSelectLeftKey(state, { payload }) {
return {
...state,
leftContainer: { leftContainer: {
selectKey: 'menu.datastudio.project', ...state.leftContainer,
selectSubKey: {}, selectKey: payload,
height: '100%', label: payload.trim() === '' ? '' : l(payload)
width: 260 }
}, };
},
/**
* 更新左侧宽度
*/
updateLeftWidth(state, { payload }) {
return {
...state,
leftContainer: {
...state.leftContainer,
width: payload
}
};
},
/**
* 更新右侧选中key
*/
updateSelectRightKey(state, { payload }) {
return {
...state,
rightContainer: { rightContainer: {
selectKey: '', ...state.rightContainer,
selectSubKey: {}, selectKey: payload
height: '100%', }
width: 260 };
}, },
/**
* 更新右侧选中key
*/
updateRightWidth(state, { payload }) {
return {
...state,
rightContainer: {
...state.rightContainer,
width: payload
}
};
},
/**
* 更新底部选中key
*/
updateSelectBottomKey(state, { payload }) {
let centerContentHeight = 0;
let toolContentHeight = 0;
if (payload === '') {
centerContentHeight = state.centerContentHeight + (state.bottomContainer.height as number);
toolContentHeight = state.toolContentHeight + (state.bottomContainer.height as number);
} else if (state.bottomContainer.selectKey !== '') {
centerContentHeight = state.centerContentHeight;
toolContentHeight = state.toolContentHeight;
} else {
centerContentHeight = state.centerContentHeight - (state.bottomContainer.height as number);
toolContentHeight = state.toolContentHeight - (state.bottomContainer.height as number);
}
return {
...state,
centerContentHeight: centerContentHeight,
toolContentHeight: toolContentHeight,
bottomContainer: { bottomContainer: {
selectKey: 'menu.datastudio.console', ...state.bottomContainer,
selectSubKey: {}, selectKey: payload
height: 180,
width: '100%'
},
database: {
dbData: [],
selectDatabaseId: null,
expandKeys: [],
selectKey: []
},
project: {
data: [],
expandKeys: [],
selectKey: []
},
tabs: {
activeBreadcrumbTitle: '',
activeKey: '0',
panes: []
},
bottomContainerContent: {
console: ''
},
sessionCluster: [],
clusterConfiguration: [],
flinkConfigOptions: [],
env: [],
footContainer: {
codePosition: [1, 1],
space: 2,
codeEncoding: 'UTF-8',
lineSeparator: 'LF',
codeType: '',
memDetails: '100/500M',
jobRunningMsg: {
taskId: null,
jobName: '',
jobState: '',
runningLog: ''
}
},
suggestions: []
},
effects: {
* queryProject({payload}, {call, put}) {
const response: [] = yield call(getTaskData, payload);
yield put({
type: 'saveProject',
payload: response
});
},
* queryFlinkConfigOptions({payload}, {call, put}) {
const response: [] = yield call(getFlinkConfigs, payload);
yield put({
type: 'saveFlinkConfigOptions',
payload: response
});
},
* querySuggestions({payload}, {call, put}) {
const response: SuggestionInfo[] = yield call(querySuggessionData, payload);
yield put({
type: 'updateSuggestions',
payload: response
});
} }
};
},
updateSelectBottomSubKey(state, { payload }) {
return {
...state,
bottomContainer: {
...state.bottomContainer,
selectSubKey: {
...state.bottomContainer.selectSubKey,
[state.bottomContainer.selectKey]: payload
}
}
};
},
/**
* 更新底部高度
*/
updateBottomHeight(state, { payload }) {
if (payload != state.bottomContainer.height) {
return {
...state,
bottomContainer: {
...state.bottomContainer,
height: payload
}
};
}
return state;
},
/**
* 更新数据库列表
*/
saveDataBase(state, { payload }) {
return {
...state,
database: { ...state.database, dbData: payload }
};
},
saveProject(state, { payload }) {
return {
...state,
project: { ...state.project, data: payload }
};
}, },
reducers: {
/**
* 更新工具栏高度
*/
updateToolContentHeight(state, {payload}) {
if (payload != state.toolContentHeight) {
return {
...state,
toolContentHeight: payload
};
}
return state;
},
/**
* 更新中间内容高度
*/
updateCenterContentHeight(state, {payload}) {
if (payload != state.centerContentHeight) {
return {
...state,
centerContentHeight: payload
};
}
return state;
},
/**
* 更新左侧选中key
*/
updateSelectLeftKey(state, {payload}) {
return {
...state,
leftContainer: {
...state.leftContainer,
selectKey: payload,
label: payload.trim() === '' ? '' : l(payload)
}
};
},
/**
* 更新左侧宽度
*/
updateLeftWidth(state, {payload}) {
return {
...state,
leftContainer: {
...state.leftContainer,
width: payload
}
};
},
/**
* 更新右侧选中key
*/
updateSelectRightKey(state, {payload}) {
return {
...state,
rightContainer: {
...state.rightContainer,
selectKey: payload
}
};
},
/**
* 更新右侧选中key
*/
updateRightWidth(state, {payload}) {
return {
...state,
rightContainer: {
...state.rightContainer,
width: payload
}
};
},
/**
* 更新底部选中key
*/
updateSelectBottomKey(state, {payload}) {
let centerContentHeight = 0;
let toolContentHeight = 0;
if (payload === '') {
centerContentHeight = state.centerContentHeight + (state.bottomContainer.height as number);
toolContentHeight = state.toolContentHeight + (state.bottomContainer.height as number);
} else if (state.bottomContainer.selectKey !== '') {
centerContentHeight = state.centerContentHeight;
toolContentHeight = state.toolContentHeight;
} else {
centerContentHeight = state.centerContentHeight - (state.bottomContainer.height as number);
toolContentHeight = state.toolContentHeight - (state.bottomContainer.height as number);
}
return { updateProjectExpandKey(state, { payload }) {
...state, return {
centerContentHeight: centerContentHeight, ...state,
toolContentHeight: toolContentHeight, project: { ...state.project, expandKeys: payload }
bottomContainer: { };
...state.bottomContainer, },
selectKey: payload updateProjectSelectKey(state, { payload }) {
} return {
}; ...state,
}, project: { ...state.project, selectKey: payload }
updateSelectBottomSubKey(state, {payload}) { };
return { },
...state,
bottomContainer: {
...state.bottomContainer,
selectSubKey: {
...state.bottomContainer.selectSubKey,
[state.bottomContainer.selectKey]: payload
}
}
};
},
/**
* 更新底部高度
*/
updateBottomHeight(state, {payload}) {
if (payload != state.bottomContainer.height) {
return {
...state,
bottomContainer: {
...state.bottomContainer,
height: payload
}
};
}
return state;
},
/**
* 更新数据库列表
*/
saveDataBase(state, {payload}) {
return {
...state,
database: {...state.database, dbData: payload}
};
},
saveProject(state, {payload}) {
return {
...state,
project: {...state.project, data: payload}
};
},
updateProjectExpandKey(state, {payload}) { /**
return { * flink config options
...state, */
project: {...state.project, expandKeys: payload} saveFlinkConfigOptions(state, { payload }) {
}; return {
}, ...state,
updateProjectSelectKey(state, {payload}) { flinkConfigOptions: payload
return { };
...state, },
project: {...state.project, selectKey: payload} /**
}; * 更新tabs activeKey
*/
updateTabsActiveKey(state, { payload }) {
const itemTypes = state.tabs.panes.filter((x) => x.key === payload);
if (itemTypes.length === 1) {
let footerValue: object = getFooterValue(state.tabs.panes, payload);
const itemType = itemTypes[0];
return {
...state,
tabs: {
...state.tabs,
activeKey: payload,
activeBreadcrumbTitle: [itemType.type, itemType.breadcrumbLabel, itemType.label].join(
'/'
)
},
footContainer: {
...state.footContainer,
...footerValue
}
};
}
return {
...state,
tabs: {
...state.tabs,
activeKey: payload
}, },
rightContainer: {
...state.rightContainer,
selectKey: ''
}
};
},
/**
* 移除标签
*/
removeTag(state, { payload }) {
const needRemoveKey = payload;
const {
tabs: { panes, activeKey }
} = state;
const index = panes.findIndex((item, index) => {
if (isDataStudioTabsItemType(item)) {
return item.params.taskId === needRemoveKey;
}
return false;
});
// 关闭 传过来的key
if (index !== -1) {
panes.splice(index, 1);
}
const newActiveKey = activeKey === needRemoveKey ? panes[panes.length - 1].key : activeKey;
return {
...state,
tabs: {
...state.tabs,
panes: panes,
activeKey: newActiveKey
}
};
},
/** /**
* flink config options * 关闭tab
*/ */
saveFlinkConfigOptions(state, {payload}) { closeTab(state, { payload }) {
return { const needCloseKey = (payload as TargetKey).toString();
...state, const {
flinkConfigOptions: payload tabs: { panes, activeKey }
}; } = state;
}, // close self
/** if (needCloseKey === activeKey) {
* 更新tabs activeKey for (const [index, pane] of panes.entries()) {
*/ if (pane.key === needCloseKey) {
updateTabsActiveKey(state, {payload}) { const nextPane = panes[(index + 1) % panes.length];
const itemTypes = state.tabs.panes.filter((x) => x.key === payload); const height =
if (itemTypes.length === 1) { document.documentElement.clientHeight -
let footerValue: object = getFooterValue(state.tabs.panes, payload); VIEW.headerHeight -
const itemType = itemTypes[0]; VIEW.headerNavHeight -
return { VIEW.footerHeight -
...state, VIEW.otherHeight;
tabs: {
...state.tabs,
activeKey: payload,
activeBreadcrumbTitle: [itemType.type, itemType.breadcrumbLabel, itemType.label].join(
'/'
)
},
footContainer: {
...state.footContainer,
...footerValue
}
};
}
return { return {
...state, ...state,
tabs: { tabs: {
...state.tabs, panes: panes.filter((pane) => pane.key !== needCloseKey),
activeKey: payload activeKey: nextPane.key,
}, activeBreadcrumbTitle:
rightContainer: { panes.length < 2
...state.rightContainer, ? ''
selectKey: '' : [nextPane.type, nextPane.breadcrumbLabel, nextPane.label].join('/')
} },
footContainer: {
...state.footContainer,
...getFooterValue(panes, nextPane.key)
},
toolContentHeight:
panes.length < 2 ? height - VIEW.leftMargin : state.toolContentHeight,
centerContentHeight: panes.length < 2 ? height : state.toolContentHeight
}; };
}, }
/** }
* 移除标签 }
*/
removeTag(state, {payload}) {
const needRemoveKey = payload;
const {
tabs: {panes, activeKey}
} = state;
const index = panes.findIndex((item, index) => {
if (isDataStudioTabsItemType(item)) {
return item.params.taskId === needRemoveKey;
}
return false;
});
// 关闭 传过来的key
if (index !== -1) {
panes.splice(index, 1);
}
const newActiveKey = activeKey === needRemoveKey ? panes[panes.length - 1].key : activeKey;
return {
...state,
tabs: {
...state.tabs,
panes: panes,
activeKey: newActiveKey
}
};
},
/**
* 关闭tab
*/
closeTab(state, {payload}) {
const needCloseKey = (payload as TargetKey).toString();
const {
tabs: {panes, activeKey}
} = state;
// close self
if (needCloseKey === activeKey) {
for (const [index, pane] of panes.entries()) {
if (pane.key === needCloseKey) {
const nextPane = panes[(index + 1) % panes.length];
const height = document.documentElement.clientHeight - VIEW.headerHeight - VIEW.headerNavHeight - VIEW.footerHeight - VIEW.otherHeight;
return {
...state,
tabs: {
panes: panes.filter((pane) => pane.key !== needCloseKey),
activeKey: nextPane.key,
activeBreadcrumbTitle:
panes.length < 2
? ''
: [nextPane.type, nextPane.breadcrumbLabel, nextPane.label].join('/')
},
footContainer: {
...state.footContainer,
...getFooterValue(panes, nextPane.key)
},
toolContentHeight: panes.length < 2 ? height - VIEW.leftMargin : state.toolContentHeight,
centerContentHeight: panes.length < 2 ? height : state.toolContentHeight,
};
}
}
}
const newPanes = panes.filter((pane) => pane.key !== needCloseKey); const newPanes = panes.filter((pane) => pane.key !== needCloseKey);
return { return {
...state, ...state,
tabs: { tabs: {
panes: newPanes, panes: newPanes,
activeKey: activeKey, activeKey: activeKey,
activeBreadcrumbTitle: state.tabs.activeBreadcrumbTitle activeBreadcrumbTitle: state.tabs.activeBreadcrumbTitle
},
footContainer: {
...state.footContainer,
...getFooterValue(newPanes, activeKey)
}
};
}, },
footContainer: {
...state.footContainer,
...getFooterValue(newPanes, activeKey)
}
};
},
/** /**
* 添加tab 如果存在则不添加 * 添加tab 如果存在则不添加
*/ */
addTab(state, {payload}) { addTab(state, { payload }) {
const node = payload as TabsItemType; const node = payload as TabsItemType;
for (const item of state.tabs.panes) { for (const item of state.tabs.panes) {
if (item.id === node.id) { if (item.id === node.id) {
let footerValue: object = getFooterValue(state.tabs.panes, item.key); let footerValue: object = getFooterValue(state.tabs.panes, item.key);
return { return {
...state, ...state,
tabs: { tabs: {
...state.tabs, ...state.tabs,
activeKey: item.key activeKey: item.key
}, },
footContainer: { footContainer: {
...state.footContainer, ...state.footContainer,
...footerValue ...footerValue
}
};
}
} }
};
node.key = }
state.tabs.panes.length === 0 }
? '0'
: (parseInt(state.tabs.panes[state.tabs.panes.length - 1].key) + 1).toString(); node.key =
const panes = [...state.tabs.panes, node]; state.tabs.panes.length === 0
let footerValue: object = getFooterValue(panes, node.key); ? '0'
return { : (parseInt(state.tabs.panes[state.tabs.panes.length - 1].key) + 1).toString();
...state, const panes = [...state.tabs.panes, node];
tabs: { let footerValue: object = getFooterValue(panes, node.key);
panes: panes, return {
activeBreadcrumbTitle: [node.type, node.breadcrumbLabel, node.label].join('/'), ...state,
activeKey: node.key tabs: {
}, panes: panes,
footContainer: { activeBreadcrumbTitle: [node.type, node.breadcrumbLabel, node.label].join('/'),
...state.footContainer, activeKey: node.key
...footerValue
}
};
}, },
footContainer: {
...state.footContainer,
...footerValue
}
};
},
/** /**
* 关闭所有tab * 关闭所有tab
*/ */
closeAllTabs(state) { closeAllTabs(state) {
return { return {
...state, ...state,
tabs: { tabs: {
panes: [], panes: [],
activeKey: '', activeKey: '',
activeBreadcrumbTitle: '' activeBreadcrumbTitle: ''
} }
}; };
}, },
/** /**
* 关闭其他tab * 关闭其他tab
*/ */
closeOtherTabs(state, {payload}) { closeOtherTabs(state, { payload }) {
// 从 pans 中找到需要关闭的 tab // 从 pans 中找到需要关闭的 tab
const tabsItem = state.tabs.panes.find((pane) => pane.key === payload.key); const tabsItem = state.tabs.panes.find((pane) => pane.key === payload.key);
return { return {
...state, ...state,
tabs: { tabs: {
panes: tabsItem ? [tabsItem] : [], panes: tabsItem ? [tabsItem] : [],
activeKey: tabsItem?.key ?? '', activeKey: tabsItem?.key ?? '',
activeBreadcrumbTitle: tabsItem?.breadcrumbLabel ?? '' activeBreadcrumbTitle: tabsItem?.breadcrumbLabel ?? ''
} }
}; };
}, },
/** /**
* 更新选中数据库id * 更新选中数据库id
*/ */
updateSelectDatabaseId(state, {payload}) { updateSelectDatabaseId(state, { payload }) {
return { return {
...state, ...state,
database: {...state.database, selectDatabaseId: payload} database: { ...state.database, selectDatabaseId: payload }
}; };
}, },
/** /**
* 更新数据库展开key * 更新数据库展开key
* @param state * @param state
* @param payload * @param payload
* @returns {any} * @returns {any}
*/ */
updateDatabaseExpandKey(state, {payload}) { updateDatabaseExpandKey(state, { payload }) {
return { return {
...state, ...state,
database: {...state.database, expandKeys: payload} database: { ...state.database, expandKeys: payload }
}; };
}, },
/** /**
* 更新数据库选中key * 更新数据库选中key
*/ */
updateDatabaseSelectKey(state, {payload}) { updateDatabaseSelectKey(state, { payload }) {
return { return {
...state, ...state,
database: {...state.database, selectKeys: payload} database: { ...state.database, selectKeys: payload }
}; };
}, },
updateBottomConsole(state, {payload}) { updateBottomConsole(state, { payload }) {
return { return {
...state, ...state,
bottomContainerContent: { bottomContainerContent: {
...state.bottomContainerContent, ...state.bottomContainerContent,
console: payload console: payload
}
};
},
saveSession(state, {payload}) {
return {
...state,
sessionCluster: payload
};
},
saveEnv(state, {payload}) {
return {
...state,
env: payload
};
},
saveTabs(state, {payload}) {
return {
...state,
tabs: payload
};
},
saveClusterConfiguration(state, {payload}) {
return {
...state,
clusterConfiguration: payload
};
},
saveFooterValue(state, {payload}) {
return {
...state,
footContainer: payload
};
},
updateJobRunningMsg(state, {payload}) {
return {
...state,
footContainer: {
...state.footContainer,
jobRunningMsg: payload
}
};
},
updateSuggestions(state, {payload}) {
return {
...state,
suggestions: payload
};
} }
};
},
saveSession(state, { payload }) {
return {
...state,
sessionCluster: payload
};
},
saveEnv(state, { payload }) {
return {
...state,
env: payload
};
},
saveTabs(state, { payload }) {
return {
...state,
tabs: payload
};
},
saveClusterConfiguration(state, { payload }) {
return {
...state,
clusterConfiguration: payload
};
},
saveFooterValue(state, { payload }) {
return {
...state,
footContainer: payload
};
},
updateJobRunningMsg(state, { payload }) {
return {
...state,
footContainer: {
...state.footContainer,
jobRunningMsg: payload
}
};
},
updateSuggestions(state, { payload }) {
return {
...state,
suggestions: payload
};
} }
}
}; };
export const [STUDIO_MODEL, STUDIO_MODEL_ASYNC] = createModelTypes(Model); export const [STUDIO_MODEL, STUDIO_MODEL_ASYNC] = createModelTypes(Model);
......
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