mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2026-03-13 09:02:05 +08:00
refactor-workspace-tabs
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
## 3.0.12
|
||||
|
||||
`2023-11-13`
|
||||
|
||||
**更新日志**
|
||||
|
||||
- 🐞【Fixed】Copy as insert first row lost problem
|
||||
|
||||
|
||||
## 3.0.11
|
||||
|
||||
`2023-11-08`
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
## 3.0.12
|
||||
|
||||
`2023-11-13`
|
||||
|
||||
**更新日志**
|
||||
|
||||
- 🐞【修复】复制为insert第一行丢失问题
|
||||
|
||||
|
||||
## 3.0.11
|
||||
|
||||
`2023-11-10`
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
@import '../../styles/var.less';
|
||||
|
||||
.box {
|
||||
.sqlExecute {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,90 +1,92 @@
|
||||
import React, { memo, useRef } from 'react';
|
||||
import { connect } from 'umi';
|
||||
import React, { memo, useRef, createContext } from 'react';
|
||||
import styles from './index.less';
|
||||
import classnames from 'classnames';
|
||||
import DraggableContainer from '@/components/DraggableContainer';
|
||||
import Console, { IConsoleRef } from '@/components/Console';
|
||||
import ConsoleEditor, { IConsoleRef } from '@/components/ConsoleEditor';
|
||||
import SearchResult, { ISearchResultRef } from '@/components/SearchResult';
|
||||
import { DatabaseTypeCode, ConsoleStatus } from '@/constants';
|
||||
import { IWorkspaceModelState, IWorkspaceModelType } from '@/models/workspace';
|
||||
import { IAIState } from '@/models/ai';
|
||||
import { DatabaseTypeCode } from '@/constants';
|
||||
import { useUpdateEffect } from '@/hooks/useUpdateEffect';
|
||||
interface IProps {
|
||||
className?: string;
|
||||
isActive: boolean;
|
||||
workspaceModel: IWorkspaceModelState;
|
||||
aiModel: IAIState;
|
||||
dispatch: any;
|
||||
data: {
|
||||
boundInfo: {
|
||||
databaseName: string;
|
||||
dataSourceId: number;
|
||||
type: DatabaseTypeCode;
|
||||
schemaName?: string;
|
||||
consoleId: number;
|
||||
consoleName: string;
|
||||
initDDL: string;
|
||||
status?: ConsoleStatus;
|
||||
};
|
||||
initDDL: string;
|
||||
consoleId: number;
|
||||
}
|
||||
|
||||
interface IContext {
|
||||
boundInfo: {
|
||||
databaseName: string;
|
||||
dataSourceId: number;
|
||||
type: DatabaseTypeCode;
|
||||
schemaName?: string;
|
||||
};
|
||||
consoleId: number;
|
||||
}
|
||||
|
||||
export const SQLExecuteContext = createContext<IContext>({} as any);
|
||||
|
||||
const SQLExecute = memo<IProps>((props) => {
|
||||
const { data, workspaceModel, aiModel, isActive, dispatch } = props;
|
||||
const { boundInfo, initDDL } = props;
|
||||
const draggableRef = useRef<any>();
|
||||
const { curTableList, curWorkspaceParams } = workspaceModel;
|
||||
// const [sql, setSql] = useState<string>('');
|
||||
const searchResultRef = useRef<ISearchResultRef>(null);
|
||||
const consoleRef = useRef<IConsoleRef>(null);
|
||||
|
||||
useUpdateEffect(() => {
|
||||
consoleRef.current?.editorRef?.setValue(data.initDDL, 'cover');
|
||||
}, [data.initDDL]);
|
||||
consoleRef.current?.editorRef?.setValue(initDDL, 'cover');
|
||||
}, [initDDL]);
|
||||
|
||||
return (
|
||||
<div className={classnames(styles.box)}>
|
||||
<DraggableContainer layout="column" className={styles.boxRightCenter}>
|
||||
<div ref={draggableRef} className={styles.boxRightConsole}>
|
||||
<Console
|
||||
ref={consoleRef}
|
||||
source="workspace"
|
||||
defaultValue={data.initDDL}
|
||||
isActive={isActive}
|
||||
executeParams={{ ...data }}
|
||||
hasAiChat={true}
|
||||
hasAi2Lang={true}
|
||||
onExecuteSQL={(sql) => {
|
||||
searchResultRef.current?.handleExecuteSQL(sql);
|
||||
}}
|
||||
onConsoleSave={() => {
|
||||
dispatch({
|
||||
type: 'workspace/fetchGetSavedConsole',
|
||||
payload: {
|
||||
status: ConsoleStatus.RELEASE,
|
||||
orderByDesc: true,
|
||||
...curWorkspaceParams,
|
||||
},
|
||||
callback: (res: any) => {
|
||||
dispatch({
|
||||
type: 'workspace/setConsoleList',
|
||||
payload: res.data,
|
||||
});
|
||||
},
|
||||
});
|
||||
}}
|
||||
tables={curTableList || []}
|
||||
remainingUse={aiModel.remainingUse}
|
||||
/>
|
||||
</div>
|
||||
<div className={styles.boxRightResult}>
|
||||
<SearchResult ref={searchResultRef} executeSqlParams={data} />
|
||||
</div>
|
||||
</DraggableContainer>
|
||||
</div>
|
||||
<SQLExecuteContext.Provider
|
||||
value={{
|
||||
boundInfo,
|
||||
consoleId: props.consoleId,
|
||||
}}
|
||||
>
|
||||
<div className={classnames(styles.sqlExecute)}>
|
||||
<DraggableContainer layout="column" className={styles.boxRightCenter}>
|
||||
<div ref={draggableRef} className={styles.boxRightConsole}>
|
||||
<ConsoleEditor
|
||||
ref={consoleRef}
|
||||
source="workspace"
|
||||
defaultValue={initDDL}
|
||||
executeParams={boundInfo}
|
||||
hasAiChat={true}
|
||||
hasAi2Lang={true}
|
||||
onExecuteSQL={(sql) => {
|
||||
searchResultRef.current?.handleExecuteSQL(sql);
|
||||
}}
|
||||
// isActive={isActive}
|
||||
// onConsoleSave={() => {
|
||||
// dispatch({
|
||||
// type: 'workspace/fetchGetSavedConsole',
|
||||
// payload: {
|
||||
// status: ConsoleStatus.RELEASE,
|
||||
// orderByDesc: true,
|
||||
// ...curWorkspaceParams,
|
||||
// },
|
||||
// callback: (res: any) => {
|
||||
// dispatch({
|
||||
// type: 'workspace/setConsoleList',
|
||||
// payload: res.data,
|
||||
// });
|
||||
// },
|
||||
// });
|
||||
// }}
|
||||
// tables={curTableList || []}
|
||||
// remainingUse={aiModel.remainingUse}
|
||||
/>
|
||||
</div>
|
||||
<div className={styles.boxRightResult}>
|
||||
<SearchResult ref={searchResultRef} executeSqlParams={boundInfo} />
|
||||
</div>
|
||||
</DraggableContainer>
|
||||
</div>
|
||||
</SQLExecuteContext.Provider>
|
||||
);
|
||||
});
|
||||
|
||||
const dvaModel = connect(({ workspace, ai }: { workspace: IWorkspaceModelType; ai: IAIState }) => ({
|
||||
workspaceModel: workspace,
|
||||
aiModel: ai,
|
||||
}));
|
||||
|
||||
export default dvaModel(SQLExecute);
|
||||
export default SQLExecute;
|
||||
|
||||
@@ -7,7 +7,7 @@ import styles from './index.less';
|
||||
// ----- components -----
|
||||
import { dataSourceFormConfigs } from '@/components/ConnectionEdit/config/dataSource';
|
||||
import { IConnectionConfig } from '@/components/ConnectionEdit/config/types';
|
||||
import MonacoEditor, { IExportRefFunction } from '@/components/Console/MonacoEditor';
|
||||
import MonacoEditor, { IExportRefFunction } from '@/components/ConsoleEditor/MonacoEditor';
|
||||
import MenuLabel from '@/components/MenuLabel';
|
||||
|
||||
// ----- constants -----
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IEditorOptions } from '@/components/Console/MonacoEditor';
|
||||
import { IEditorOptions } from '@/components/ConsoleEditor/MonacoEditor';
|
||||
|
||||
export const editorDefaultOptions: IEditorOptions = {
|
||||
fontFamily: `"Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace`,
|
||||
@@ -582,7 +582,6 @@ function Console(props: IProps, ref: ForwardedRef<IConsoleRef>) {
|
||||
</Spin>
|
||||
</Drawer>
|
||||
</Spin>
|
||||
|
||||
<div className={styles.consoleOptionsWrapper}>
|
||||
<div className={styles.consoleOptionsLeft}>
|
||||
<Button type="primary" className={styles.runButton} onClick={() => executeSQL()}>
|
||||
@@ -2,7 +2,7 @@ import React, { useCallback, forwardRef, ForwardedRef, useImperativeHandle, useM
|
||||
import styles from './index.less';
|
||||
import classnames from 'classnames';
|
||||
import { Form, Input, Modal } from 'antd';
|
||||
import MonacoEditor, { IExportRefFunction } from '@/components/Console/MonacoEditor';
|
||||
import MonacoEditor, { IExportRefFunction } from '@/components/ConsoleEditor/MonacoEditor';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import sqlService from '@/service/sql';
|
||||
import i18n from '@/i18n';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { memo, useEffect, useRef, useState, ForwardedRef } from 'react';
|
||||
import styles from './index.less';
|
||||
import classnames from 'classnames';
|
||||
import MonacoEditor, { IExportRefFunction, IRangeType } from '@/components/Console/MonacoEditor';
|
||||
import MonacoEditor, { IExportRefFunction, IRangeType } from '@/components/ConsoleEditor/MonacoEditor';
|
||||
import { Modal } from 'antd'
|
||||
|
||||
interface IProps {
|
||||
|
||||
@@ -2,7 +2,7 @@ import React, { memo, useRef, useState, useMemo, useEffect } from 'react';
|
||||
import styles from './index.less';
|
||||
import classnames from 'classnames';
|
||||
import Iconfont from '@/components/Iconfont';
|
||||
import MonacoEditor, { IExportRefFunction } from '@/components/Console/MonacoEditor';
|
||||
import MonacoEditor, { IExportRefFunction } from '@/components/ConsoleEditor/MonacoEditor';
|
||||
import i18n from '@/i18n';
|
||||
import { Button } from 'antd';
|
||||
import { formatSql } from '@/utils/sql';
|
||||
|
||||
@@ -33,7 +33,7 @@ import { DownOutlined } from '@ant-design/icons';
|
||||
import { copy, tableCopy } from '@/utils';
|
||||
import Iconfont from '../../../Iconfont';
|
||||
import StateIndicator from '../../../StateIndicator';
|
||||
import MonacoEditor from '../../../Console/MonacoEditor';
|
||||
import MonacoEditor from '../../../ConsoleEditor/MonacoEditor';
|
||||
import MyPagination from '../Pagination';
|
||||
import StatusBar from '../StatusBar';
|
||||
import RightClickMenu, { AllSupportedMenusType } from '../RightClickMenu';
|
||||
@@ -768,7 +768,6 @@ export default function TableBox(props: ITableProps) {
|
||||
const newRowDatas = tableData.filter((item) => rowIds.includes(item[colNoCode]!));
|
||||
const newRowDatasList = newRowDatas.map((item) => {
|
||||
const _item = lodash.cloneDeep(item);
|
||||
delete _item[colNoCode];
|
||||
return Object.keys(_item).map((i) => _item[i]);
|
||||
});
|
||||
const _updateDatas = newRowDatasList.map((item, index) => {
|
||||
@@ -791,7 +790,6 @@ export default function TableBox(props: ITableProps) {
|
||||
const newRowDatas = tableData.filter((item) => rowIds.includes(item[colNoCode]!));
|
||||
const newRowDatasList = newRowDatas.map((item) => {
|
||||
const _item = lodash.cloneDeep(item);
|
||||
delete _item[colNoCode];
|
||||
return Object.keys(_item).map((i) => _item[i]);
|
||||
});
|
||||
const _updateDatas = newRowDatasList.map((item, index) => {
|
||||
|
||||
51
chat2db-client/src/hooks/useCreateConsole.ts
Normal file
51
chat2db-client/src/hooks/useCreateConsole.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { setWorkspaceTabList, useConsoleStore, setActiveConsoleId } from '@/store/console';
|
||||
import { ConsoleStatus, ConsoleOpenedStatus, WorkspaceTabType, DatabaseTypeCode } from '@/constants'
|
||||
import historyService from '@/service/history';
|
||||
|
||||
interface ICreateConsoleParams {
|
||||
name?: string;
|
||||
ddl?: string;
|
||||
dataSourceId?: number;
|
||||
databaseName?: string;
|
||||
schemaName?: string;
|
||||
type?: DatabaseTypeCode;
|
||||
operationType?: string;
|
||||
}
|
||||
|
||||
function useCreateConsole() {
|
||||
const { workspaceTabList } = useConsoleStore(state => {
|
||||
return {
|
||||
workspaceTabList: state.workspaceTabList,
|
||||
}
|
||||
});
|
||||
|
||||
const createConsole = (params: ICreateConsoleParams) => {
|
||||
const newConsole = {
|
||||
...params,
|
||||
name: params.name || 'create console',
|
||||
ddl: params.ddl || '',
|
||||
status: ConsoleStatus.DRAFT,
|
||||
tabOpened: ConsoleOpenedStatus.IS_OPEN,
|
||||
operationType: WorkspaceTabType.CONSOLE,
|
||||
};
|
||||
historyService.createConsole(newConsole).then((res) => {
|
||||
const newList = [
|
||||
...(workspaceTabList||[]),
|
||||
{
|
||||
id: res,
|
||||
title: newConsole.name,
|
||||
type: newConsole.operationType,
|
||||
uniqueData: newConsole,
|
||||
},
|
||||
];
|
||||
setWorkspaceTabList(newList);
|
||||
setActiveConsoleId(res);
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
createConsole
|
||||
}
|
||||
}
|
||||
|
||||
export default useCreateConsole;
|
||||
@@ -1,21 +0,0 @@
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import { useConsoleStore, getSavedConsoleList } from '@/store/console';
|
||||
|
||||
const useGetConsoleList = () => {
|
||||
const { consoleList } = useConsoleStore((state) => {
|
||||
return {
|
||||
consoleList: state.consoleList,
|
||||
};
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
getSavedConsoleList();
|
||||
}, []);
|
||||
|
||||
return {
|
||||
consoleList,
|
||||
}
|
||||
};
|
||||
|
||||
export default useGetConsoleList;
|
||||
@@ -10,7 +10,7 @@ import { MoreOutlined } from '@ant-design/icons';
|
||||
import { Button, Cascader, Dropdown, Form, MenuProps, message, notification, Select, Spin } from 'antd';
|
||||
import { deleteChart, getChartById, updateChart } from '@/service/dashboard';
|
||||
import { data } from '../../../../../mock/sqlResult.json';
|
||||
import Console from '@/components/Console';
|
||||
import Console from '@/components/ConsoleEditor';
|
||||
import Iconfont from '@/components/Iconfont';
|
||||
import sqlService, { IExecuteSqlParams, MetaSchemaVO } from '@/service/sql';
|
||||
import { Option } from '@/typings/common';
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
@import '../../../../../styles/var.less';
|
||||
|
||||
.tabBox {
|
||||
height: 100%;
|
||||
}
|
||||
@@ -1,51 +1,80 @@
|
||||
import React, { memo, useEffect, useState, useMemo, Fragment, useRef } from 'react';
|
||||
import i18n from '@/i18n';
|
||||
import classnames from 'classnames';
|
||||
import React, { memo, useEffect, useMemo, Fragment } from 'react';
|
||||
import styles from './index.less';
|
||||
|
||||
// ----- constants -----
|
||||
import { WorkspaceTabType, workspaceTabConfig } from '@/constants';
|
||||
import { IWorkspaceTab } from '@/typings';
|
||||
// import WorkspaceExtend from '../WorkspaceExtend';
|
||||
|
||||
// ---- hooks -----
|
||||
import useCreateConsole from '@/hooks/useCreateConsole';
|
||||
|
||||
// ----- components -----
|
||||
import Tabs, { ITabItem } from '@/components/Tabs';
|
||||
import SearchResult from '@/components/SearchResult';
|
||||
import DatabaseTableEditor from '@/blocks/DatabaseTableEditor';
|
||||
import SQLExecute from '@/blocks/SQLExecute';
|
||||
|
||||
// ----- hooks -----
|
||||
import useGetConsoleList from '@/hooks/useGetConsoleList';
|
||||
// ---- store -----
|
||||
import { useConsoleStore, getSavedConsoleList, setActiveConsoleId, setWorkspaceTabList } from '@/store/console';
|
||||
import { useWorkspaceStore } from '@/store/workspace';
|
||||
|
||||
// ---- store -----
|
||||
import { useConsoleStore } from '@/store/console';
|
||||
import { State } from '@/components/StateIndicator';
|
||||
// ----- services -----
|
||||
import historyService from '@/service/history';
|
||||
|
||||
import indexedDB from '@/indexedDB';
|
||||
|
||||
const WorkspaceTabs = memo(() => {
|
||||
// 获取console
|
||||
const { consoleList } = useGetConsoleList();
|
||||
|
||||
const { activeConsoleId } = useConsoleStore(state=> {
|
||||
const { activeConsoleId, consoleList, workspaceTabList } = useConsoleStore((state) => {
|
||||
return {
|
||||
activeConsoleId: state.activeConsoleId
|
||||
}
|
||||
consoleList: state.consoleList,
|
||||
activeConsoleId: state.activeConsoleId,
|
||||
workspaceTabList: state.workspaceTabList,
|
||||
};
|
||||
});
|
||||
|
||||
const workspaceTabItems: ITabItem[] = useMemo(() => {
|
||||
return (
|
||||
const currentConnectionDetails = useWorkspaceStore((state) => state.currentConnectionDetails);
|
||||
|
||||
const { createConsole } = useCreateConsole();
|
||||
|
||||
// 获取console
|
||||
useEffect(() => {
|
||||
getSavedConsoleList();
|
||||
}, []);
|
||||
|
||||
// consoleList 先转换为通用的 workspaceTabList
|
||||
useEffect(() => {
|
||||
const _workspaceTabItems =
|
||||
consoleList?.map((item) => {
|
||||
return {
|
||||
prefixIcon: workspaceTabConfig[item.type]?.icon,
|
||||
label: item.name,
|
||||
key: item.id,
|
||||
// editableName: item.type === WorkspaceTabType.CONSOLE,
|
||||
id: item.id,
|
||||
type: item.operationType,
|
||||
title: item.name,
|
||||
uniqueData: {},
|
||||
};
|
||||
}) || []
|
||||
);
|
||||
}) || [];
|
||||
setWorkspaceTabList(_workspaceTabItems);
|
||||
}, [consoleList]);
|
||||
|
||||
// 关闭tab
|
||||
const closeWindowTab = (key: number) => {
|
||||
const p: any = {
|
||||
id: key,
|
||||
tabOpened: 'n',
|
||||
};
|
||||
|
||||
historyService.updateSavedConsole(p).then(() => {
|
||||
indexedDB.deleteData('chat2db', 'workspaceConsoleDDL', key);
|
||||
});
|
||||
};
|
||||
|
||||
// 删除 新增tab
|
||||
const onEdit = (action: 'add' | 'remove', data: ITabItem[]) => {
|
||||
const handelTabsEdit = (action: 'add' | 'remove', data: ITabItem[]) => {
|
||||
if (action === 'remove') {
|
||||
setWorkspaceTabList(
|
||||
workspaceTabList.filter((t) => {
|
||||
workspaceTabList?.filter((t) => {
|
||||
return data.findIndex((item) => item.key === t.id) === -1;
|
||||
}),
|
||||
}) || [],
|
||||
);
|
||||
data.forEach((item) => {
|
||||
const editData = workspaceTabList?.find((t) => t.id === item.key);
|
||||
@@ -56,21 +85,113 @@ const WorkspaceTabs = memo(() => {
|
||||
) {
|
||||
closeWindowTab(item.key as number);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
if (action === 'add') {
|
||||
addConsole();
|
||||
createConsole({
|
||||
dataSourceId: currentConnectionDetails?.id,
|
||||
type: currentConnectionDetails?.type,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function onTabChange(key: string | number | null) {
|
||||
// 切换tab
|
||||
const onTabChange = (key: string | null) => {
|
||||
setActiveConsoleId(key);
|
||||
}
|
||||
};
|
||||
|
||||
// 编辑名称
|
||||
const editableNameOnBlur = (t: ITabItem) => {
|
||||
const _params: any = {
|
||||
id: t.key,
|
||||
name: t.label,
|
||||
};
|
||||
historyService.updateSavedConsole(_params);
|
||||
};
|
||||
|
||||
// 修改tab详情
|
||||
const changeTabDetails = (data: IWorkspaceTab) => {
|
||||
const list =
|
||||
workspaceTabList?.map((t) => {
|
||||
if (t.id === data.id) {
|
||||
return data;
|
||||
}
|
||||
return t;
|
||||
}) || [];
|
||||
setWorkspaceTabList(list);
|
||||
};
|
||||
|
||||
const renderSQLExecute = (item: IWorkspaceTab) => {
|
||||
const { uniqueData } = item;
|
||||
return (
|
||||
<SQLExecute
|
||||
boundInfo={{
|
||||
dataSourceId: uniqueData.dataSourceId,
|
||||
databaseName: uniqueData.databaseName,
|
||||
type: uniqueData.databaseType,
|
||||
schemaName: uniqueData?.schemaName,
|
||||
}}
|
||||
initDDL={uniqueData.ddl}
|
||||
consoleId={item.id as number}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const renderTableEditor = (item: IWorkspaceTab) => {
|
||||
const { uniqueData } = item;
|
||||
return (
|
||||
<DatabaseTableEditor
|
||||
tabDetails={item}
|
||||
changeTabDetails={changeTabDetails}
|
||||
dataSourceId={uniqueData.dataSourceId}
|
||||
databaseName={uniqueData.databaseName!}
|
||||
databaseType={uniqueData?.databaseType}
|
||||
schemaName={uniqueData?.schemaName}
|
||||
tableName={uniqueData.tableName}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const renderSearchResult = (item: IWorkspaceTab) => {
|
||||
const { uniqueData } = item;
|
||||
return <SearchResult sql={uniqueData.sql} executeSqlParams={uniqueData} />;
|
||||
};
|
||||
|
||||
const workspaceTabConnectionMap = (item: IWorkspaceTab) => {
|
||||
switch (item.type) {
|
||||
case WorkspaceTabType.CONSOLE:
|
||||
case WorkspaceTabType.FUNCTION:
|
||||
case WorkspaceTabType.PROCEDURE:
|
||||
case WorkspaceTabType.TRIGGER:
|
||||
case WorkspaceTabType.VIEW:
|
||||
return renderSQLExecute(item);
|
||||
case WorkspaceTabType.EditTable:
|
||||
case WorkspaceTabType.CreateTable:
|
||||
return renderTableEditor(item);
|
||||
case WorkspaceTabType.EditTableData:
|
||||
return renderSearchResult(item);
|
||||
default:
|
||||
return <div>未知类型</div>;
|
||||
}
|
||||
};
|
||||
|
||||
const workspaceTabItems = useMemo(() => {
|
||||
return workspaceTabList?.map((item) => {
|
||||
return {
|
||||
prefixIcon: workspaceTabConfig[item.type]?.icon,
|
||||
label: item.title,
|
||||
key: item.id,
|
||||
editableName: item.type === WorkspaceTabType.CONSOLE,
|
||||
children: <Fragment key={item.id}>{workspaceTabConnectionMap(item)}</Fragment>,
|
||||
};
|
||||
});
|
||||
}, [workspaceTabList]);
|
||||
|
||||
return (
|
||||
<Tabs
|
||||
onChange={onTabChange}
|
||||
onEdit={onEdit as any}
|
||||
className={styles.tabBox}
|
||||
onChange={onTabChange as any}
|
||||
onEdit={handelTabsEdit as any}
|
||||
activeKey={activeConsoleId}
|
||||
editableNameOnBlur={editableNameOnBlur}
|
||||
items={workspaceTabItems}
|
||||
|
||||
@@ -7,7 +7,7 @@ import DraggableContainer from '@/components/DraggableContainer';
|
||||
import WorkspaceLeft from './components/WorkspaceLeft';
|
||||
import NewWorkspaceRight from './components/NewWorkspaceRight';
|
||||
|
||||
import useMonacoTheme from '@/components/Console/MonacoEditor/useMonacoTheme';
|
||||
import useMonacoTheme from '@/components/ConsoleEditor/MonacoEditor/useMonacoTheme';
|
||||
|
||||
import styles from './index.less';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import MonacoEditor from '@/components/Console/MonacoEditor';
|
||||
import MonacoEditor from '@/components/ConsoleEditor/MonacoEditor';
|
||||
import { Button } from 'antd';
|
||||
import React, { useState } from 'react';
|
||||
import styles from './index.less';
|
||||
|
||||
@@ -82,7 +82,7 @@ export interface IHistoryRecord {
|
||||
gmtCreate: string;
|
||||
}
|
||||
|
||||
const saveConsole = createRequest<ICreateConsole, number>('/api/operation/saved/create', { method: 'post' });
|
||||
const createConsole = createRequest<ICreateConsole, number>('/api/operation/saved/create', { method: 'post' });
|
||||
|
||||
// orderByDesc true 降序
|
||||
const getWindowTab = createRequest<{ id: number, orderByDesc: boolean }, number>('/api/operation/saved/:id', { method: 'get' });
|
||||
@@ -101,7 +101,7 @@ export default {
|
||||
getSavedConsoleList,
|
||||
updateSavedConsole,
|
||||
getHistoryList,
|
||||
saveConsole,
|
||||
createConsole,
|
||||
deleteSavedConsole,
|
||||
createHistory,
|
||||
getWindowTab
|
||||
|
||||
@@ -5,16 +5,19 @@
|
||||
import { create, UseBoundStore, StoreApi } from 'zustand';
|
||||
import { devtools } from 'zustand/middleware';
|
||||
import { IConsole } from '@/typings/console';
|
||||
import { IWorkspaceTab } from '@/typings/workspace';
|
||||
import historyService from '@/service/history';
|
||||
|
||||
export interface IConsoleStore {
|
||||
consoleList: IConsole[] | null;
|
||||
activeConsoleId: string | null;
|
||||
activeConsoleId: string | number | null;
|
||||
workspaceTabList: IWorkspaceTab[] | null;
|
||||
}
|
||||
|
||||
const initConsoleStore = {
|
||||
consoleList: null,
|
||||
activeConsoleId: null
|
||||
activeConsoleId: null,
|
||||
workspaceTabList: null,
|
||||
}
|
||||
|
||||
export const useConsoleStore: UseBoundStore<StoreApi<IConsoleStore>> = create(
|
||||
@@ -31,6 +34,10 @@ export const getSavedConsoleList = () => {
|
||||
});
|
||||
}
|
||||
|
||||
export const setActiveConsoleId = (id: string) => {
|
||||
export const setActiveConsoleId = (id: IConsoleStore['activeConsoleId']) => {
|
||||
useConsoleStore.setState({ activeConsoleId: id });
|
||||
}
|
||||
|
||||
export const setWorkspaceTabList = (items: IConsoleStore['workspaceTabList']) => {
|
||||
useConsoleStore.setState({ workspaceTabList: items });
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ export interface ICommonStore {
|
||||
setCurrentConnectionDetails: (connectionDetails: Partial<IConnectionDetails> | null) => void;
|
||||
}
|
||||
|
||||
|
||||
export const commonStore = (set): ICommonStore => ({
|
||||
currentConnectionDetails: null,
|
||||
setCurrentConnectionDetails: (connectionDetails: ICommonStore['currentConnectionDetails']) =>
|
||||
|
||||
@@ -29,11 +29,11 @@ export interface IConsole {
|
||||
id: number; // consoleId
|
||||
name: string; // 控制台名称
|
||||
ddl: string; // 控制台内的sql
|
||||
dataSourceId: number; // 数据源id
|
||||
dataSourceName: string; // 数据源名称
|
||||
dataSourceId?: number; // 数据源id
|
||||
dataSourceName?: string; // 数据源名称
|
||||
databaseName?: string; // 数据库名称
|
||||
schemaName?: string; // schema名称
|
||||
type: DatabaseTypeCode; // 数据库类型
|
||||
type?: DatabaseTypeCode; // 数据库类型
|
||||
status: ConsoleStatus; // 控制台状态
|
||||
connectable: boolean; // 是否可连接
|
||||
tabOpened?: ConsoleOpenedStatus; // 控制台tab是否打开
|
||||
|
||||
@@ -23,6 +23,26 @@ public class OperationUpdateRequest {
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 数据源连接ID
|
||||
*/
|
||||
private Long dataSourceId;
|
||||
|
||||
/**
|
||||
* db名称
|
||||
*/
|
||||
private String databaseName;
|
||||
|
||||
/**
|
||||
* 表所在空间
|
||||
*/
|
||||
private String schemaName;
|
||||
|
||||
/**
|
||||
* 数据库类型
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* ddl内容
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user