diff --git a/src/common/network/connection.ts b/src/common/network/connection.ts index 750f40736..c9effe20d 100644 --- a/src/common/network/connection.ts +++ b/src/common/network/connection.ts @@ -46,6 +46,7 @@ function generateConnectionParams(formData: Partial, isHide name: formData.name, username: formData.username, password: encrypt(formData.password), + projectId: formData?.projectId, sysTenantUsername: formData?.useSys ? formData.sysTenantUsername : null, sslConfig: formData.sslConfig || { enabled: false }, /** @@ -53,7 +54,7 @@ function generateConnectionParams(formData: Partial, isHide */ sysTenantPassword: formData?.useSys ? encrypt(formData.sysTenantPassword) : null, queryTimeoutSeconds: formData.queryTimeoutSeconds, - properties: formData.properties, + properties: formData.properties || null, passwordSaved: formData.passwordSaved, environmentId: formData.environmentId, jdbcUrlParameters: formData.jdbcUrlParameters || {}, diff --git a/src/component/Action/Group.tsx b/src/component/Action/Group.tsx index 8a0327c61..11f3bbe16 100644 --- a/src/component/Action/Group.tsx +++ b/src/component/Action/Group.tsx @@ -76,7 +76,7 @@ export default ({ }) : [children]; - const visibleActionsSort = visibleActions.slice(0); + const visibleActionsSort = visibleActions.slice(0).filter(Boolean); visibleActionsSort.sort((a, b) => { const orderA = getOrder(a.props); @@ -86,7 +86,7 @@ export default ({ }); const fixedSize = visibleActionsSort.filter( - (action) => action.props.type === 'primary' || action.props.fixed, + (action) => action?.props.type === 'primary' || action?.props.fixed, ).length; const realSize = max([fixedSize, size]); diff --git a/src/d.ts/index.ts b/src/d.ts/index.ts index 282973eab..4f7ba6c54 100644 --- a/src/d.ts/index.ts +++ b/src/d.ts/index.ts @@ -713,6 +713,8 @@ export interface IConnection { jdbcUrlParameters?: Record; sessionInitScript?: string; defaultSchema?: string; + projectId?: number; + readonly projectName?: string; } export interface IConnectionLabel { diff --git a/src/page/Datasource/Datasource/NewDatasourceDrawer/Form/ProjectItem/ProjectSelect.tsx b/src/page/Datasource/Datasource/NewDatasourceDrawer/Form/ProjectItem/ProjectSelect.tsx new file mode 100644 index 000000000..6a6342b76 --- /dev/null +++ b/src/page/Datasource/Datasource/NewDatasourceDrawer/Form/ProjectItem/ProjectSelect.tsx @@ -0,0 +1,21 @@ +import { Select, SelectProps } from 'antd'; + +export default function ProjectSelect({ value, onChange, options, ...rest }: SelectProps) { + value = value || -999; + options = [] + .concat([ + { + label: '不绑定项目', + value: -999, + }, + ]) + .concat(options || []); + function _onChange(v, option) { + if (v === -999) { + onChange(null, option); + } else { + onChange(v, option); + } + } + return + {!login.isPrivateSpace() && } {!haveOCP() && } ); diff --git a/src/page/Datasource/Datasource/NewDatasourceDrawer/index.tsx b/src/page/Datasource/Datasource/NewDatasourceDrawer/index.tsx index a46f86f10..cd1673d2a 100644 --- a/src/page/Datasource/Datasource/NewDatasourceDrawer/index.tsx +++ b/src/page/Datasource/Datasource/NewDatasourceDrawer/index.tsx @@ -60,7 +60,15 @@ export default function NewDatasourceDrawer({ function getOriginDatasource(data: IConnection, isCopy: boolean) { return isCopy - ? { ...data, id: null, creatorId: null, name: null, password: '', sysTenantPassword: '' } + ? { + ...data, + id: null, + creatorId: null, + name: null, + password: '', + sysTenantPassword: '', + projectId: null, + } : data; } diff --git a/src/page/Datasource/Info/ChangeProjectModal/ProjectSelect.tsx b/src/page/Datasource/Info/ChangeProjectModal/ProjectSelect.tsx index 6a158ac45..5e0dbc2a7 100644 --- a/src/page/Datasource/Info/ChangeProjectModal/ProjectSelect.tsx +++ b/src/page/Datasource/Info/ChangeProjectModal/ProjectSelect.tsx @@ -23,11 +23,18 @@ import { isNull } from 'lodash'; interface IProps { value?: any; onChange?: (v: any) => void; + disabled?: boolean; projects: IProject[]; currentDatabase: IDatabase; } -export default function ProjectSelect({ projects, value, currentDatabase, onChange }: IProps) { +export default function ProjectSelect({ + projects, + value, + disabled, + currentDatabase, + onChange, +}: IProps) { const isProjectNotFound = !projects?.find((item) => item.id === currentDatabase?.project?.id); const _isNull = isNull(value); return ( @@ -38,7 +45,7 @@ export default function ProjectSelect({ projects, value, currentDatabase, onChan onChange={(v) => { onChange(v); }} - disabled={_isNull} + disabled={_isNull || disabled} > {projects?.map((item) => { return ( @@ -55,6 +62,7 @@ export default function ProjectSelect({ projects, value, currentDatabase, onChan (e.target.checked ? onChange(null) : onChange(undefined))} > { diff --git a/src/page/Datasource/Info/NewDataBaseButton/index.tsx b/src/page/Datasource/Info/NewDataBaseButton/index.tsx index 1d9a7362b..39ac11cba 100644 --- a/src/page/Datasource/Info/NewDataBaseButton/index.tsx +++ b/src/page/Datasource/Info/NewDataBaseButton/index.tsx @@ -27,11 +27,19 @@ import ProjectSelect from '../ChangeProjectModal/ProjectSelect'; interface IProps { dataSourceId: string; + projectId: number; + projectName: string; onSuccess: () => void; mode: ConnectionMode; } -export default function NewDataBaseButton({ dataSourceId, onSuccess, mode }: IProps) { +export default function NewDataBaseButton({ + dataSourceId, + projectId, + projectName, + onSuccess, + mode, +}: IProps) { const [open, setOpen] = useState(false); const [form] = Form.useForm< Pick & { projectId: number } @@ -53,6 +61,11 @@ export default function NewDataBaseButton({ dataSourceId, onSuccess, mode }: IPr useEffect(() => { if (open) { form.resetFields(); + if (projectId) { + form.setFieldsValue({ + projectId: projectId, + }); + } } switch (mode) { case ConnectionMode.OB_MYSQL: @@ -152,7 +165,11 @@ export default function NewDataBaseButton({ dataSourceId, onSuccess, mode }: IPr name={'projectId'} label={formatMessage({ id: 'odc.Info.NewDataBaseButton.Project' })} /*所属项目*/ > - + diff --git a/src/page/Datasource/Info/index.tsx b/src/page/Datasource/Info/index.tsx index 2e1f4227f..5a5e0215d 100644 --- a/src/page/Datasource/Info/index.tsx +++ b/src/page/Datasource/Info/index.tsx @@ -27,9 +27,10 @@ import { IDatasource } from '@/d.ts/datasource'; import { formatMessage } from '@/util/intl'; import { getLocalFormatDateTime } from '@/util/utils'; import { useRequest } from 'ahooks'; -import { Button, Input, message, Popconfirm, Space } from 'antd'; +import { Button, Input, message, Popconfirm, Space, Tooltip } from 'antd'; import { toInteger } from 'lodash'; import React, { useRef, useState } from 'react'; +import Icon, { EditOutlined } from '@ant-design/icons'; import ChangeProjectModal from './ChangeProjectModal'; import NewDataBaseButton from './NewDataBaseButton'; interface IProps { @@ -105,6 +106,8 @@ const Info: React.FC = ({ id, datasource }) => { mode={datasource?.dialectType} onSuccess={() => reload()} dataSourceId={id} + projectId={datasource?.projectId} + projectName={datasource?.projectName} />