diff --git a/src/page/Datasource/Datasource/Content/List/MoreBtn/index.tsx b/src/page/Datasource/Datasource/Content/List/MoreBtn/index.tsx index 6f4de15e8..7927dd7c9 100644 --- a/src/page/Datasource/Datasource/Content/List/MoreBtn/index.tsx +++ b/src/page/Datasource/Datasource/Content/List/MoreBtn/index.tsx @@ -20,6 +20,7 @@ import { ModalStore } from '@/store/modal'; import { formatMessage } from '@/util/intl'; import { getFormatDateTime } from '@/util/utils'; import { + CopyOutlined, DeleteOutlined, EditOutlined, EllipsisOutlined, @@ -39,6 +40,7 @@ enum Actions { EDIT = 'edit', COPY = 'copy', REMOVE = 'remove', + CLONE = 'clone', } const MoreBtn: React.FC = function ({ connection, modalStore }) { const context = useContext(ParamContext); @@ -103,6 +105,13 @@ const MoreBtn: React.FC = function ({ connection, modalStore }) { icon: , } : null, + connection.permittedActions?.includes(actionTypes.update) + ? { + label: '克隆', + key: Actions.CLONE, + icon: , + } + : null, connection.permittedActions?.includes(actionTypes.delete) ? { label: formatMessage({ @@ -146,6 +155,10 @@ const MoreBtn: React.FC = function ({ connection, modalStore }) { remove(); return; } + case Actions.CLONE: { + context.setCopyDatasourceId?.(connection?.id); + return; + } } }, }} diff --git a/src/page/Datasource/Datasource/NewDatasourceDrawer/index.tsx b/src/page/Datasource/Datasource/NewDatasourceDrawer/index.tsx index 62d4eaf5a..a46f86f10 100644 --- a/src/page/Datasource/Datasource/NewDatasourceDrawer/index.tsx +++ b/src/page/Datasource/Datasource/NewDatasourceDrawer/index.tsx @@ -26,9 +26,9 @@ import { formatMessage } from '@/util/intl'; import { useRequest } from 'ahooks'; import { Button, Drawer, Input, message, Modal, Space, Spin } from 'antd'; import copy from 'copy-to-clipboard'; -import { useEffect, useRef } from 'react'; +import { useEffect, useMemo, useRef } from 'react'; import DatasourceForm, { IFormRef } from './Form'; -import { ConnectType } from '@/d.ts'; +import { ConnectType, IConnection } from '@/d.ts'; interface IProps { visible: boolean; @@ -37,6 +37,7 @@ interface IProps { id?: number; disableTheme?: boolean; type?: ConnectType; + isCopy?: boolean; close: () => void; onSuccess: () => void; } @@ -44,6 +45,7 @@ interface IProps { export default function NewDatasourceDrawer({ visible, isEdit, + isCopy, type, id, disableTheme, @@ -56,12 +58,22 @@ export default function NewDatasourceDrawer({ manual: true, }); + function getOriginDatasource(data: IConnection, isCopy: boolean) { + return isCopy + ? { ...data, id: null, creatorId: null, name: null, password: '', sysTenantPassword: '' } + : data; + } + + const originDatasource = useMemo(() => { + return getOriginDatasource(data, isCopy); + }, [data, isCopy]); + async function getDataSource(id: number) { const data = await run(id); if (!data) { return; } - formRef.current?.form?.setFieldsValue(data); + formRef.current?.form?.setFieldsValue(getOriginDatasource(data, isCopy)); } useEffect(() => { @@ -194,8 +206,8 @@ export default function NewDatasourceDrawer({ void; reloadTable?: () => Promise; editDatasource?: (id: number) => void; + setCopyDatasourceId?: (id: number) => void; } const ParamContext: React.Context = React.createContext({ diff --git a/src/page/Datasource/Datasource/index.tsx b/src/page/Datasource/Datasource/index.tsx index a3c002f5f..7f8090b13 100644 --- a/src/page/Datasource/Datasource/index.tsx +++ b/src/page/Datasource/Datasource/index.tsx @@ -31,6 +31,7 @@ const Datasource: React.FC = function ({ modalStore }) { const [sortType, setSortType] = useState(null); const [connectType, setConnectType] = useState([]); const [editDatasourceId, setEditDatasourceId] = useState(null); + const [copyDatasourceId, setCopyDatasourceId] = useState(null); const contentRef = useRef(); const _searchValue = useMemo(() => { return { @@ -57,6 +58,7 @@ const Datasource: React.FC = function ({ modalStore }) { editDatasource(id: number) { setEditDatasourceId(id); }, + setCopyDatasourceId, }} >
@@ -72,6 +74,18 @@ const Datasource: React.FC = function ({ modalStore }) { contentRef.current?.reload(); }} /> + setCopyDatasourceId(null)} + onSuccess={() => { + contentRef.current?.reload(); + }} + />
); diff --git a/src/page/Workspace/SideBar/ResourceTree/SelectPanel/Datasource/index.tsx b/src/page/Workspace/SideBar/ResourceTree/SelectPanel/Datasource/index.tsx index 3c008b636..4a4111acf 100644 --- a/src/page/Workspace/SideBar/ResourceTree/SelectPanel/Datasource/index.tsx +++ b/src/page/Workspace/SideBar/ResourceTree/SelectPanel/Datasource/index.tsx @@ -69,6 +69,7 @@ interface IProps { export default forwardRef(function DatasourceTree({ filters, closeSelectPanel }: IProps, ref) { const [editDatasourceId, setEditDatasourceId] = useState(null); + const [copyDatasourceId, setCopyDatasourceId] = useState(null); const [addDSVisiable, setAddDSVisiable] = useState(false); const [searchKey, setSearchKey] = useState(''); const [wrapperHeight, setWrapperHeight] = useState(0); @@ -246,6 +247,14 @@ export default forwardRef(function DatasourceTree({ filters, closeSelectPanel }: trigger={login.isPrivateSpace() ? ['contextMenu'] : []} menu={{ items: [ + { + label: '克隆', + key: 'clone', + onClick: (e) => { + e.domEvent?.stopPropagation(); + setCopyDatasourceId(toInteger(node.key)); + }, + }, { label: formatMessage({ id: 'odc.ResourceTree.Datasource.Edit', @@ -287,6 +296,14 @@ export default forwardRef(function DatasourceTree({ filters, closeSelectPanel }: {login.isPrivateSpace() && (
+ { + setCopyDatasourceId(toInteger(node.key)); + }} + key={'clone'} + > + 克隆 + { setEditDatasourceId(node.key); @@ -351,6 +368,18 @@ export default forwardRef(function DatasourceTree({ filters, closeSelectPanel }: context?.reloadDatasourceList(); }} /> + { + setCopyDatasourceId(null); + }} + onSuccess={() => { + context?.reloadDatasourceList(); + }} + />
} bottomLoading={false}