From b8c1469afcd3b9c720b2f9b25dbc88489b89d6b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=93=E5=BA=B7?= Date: Tue, 14 Nov 2023 15:47:58 +0800 Subject: [PATCH 1/5] support bind project --- src/common/network/connection.ts | 1 + src/component/Action/Group.tsx | 4 +- src/d.ts/index.ts | 2 + .../Form/ProjectItem/ProjectSelect.tsx | 17 ++++ .../Form/ProjectItem/index.tsx | 83 +++++++++++++++++++ .../NewDatasourceDrawer/Form/index.tsx | 9 +- .../Datasource/NewDatasourceDrawer/index.tsx | 10 ++- src/page/Datasource/Info/index.tsx | 60 ++++++++++---- 8 files changed, 164 insertions(+), 22 deletions(-) create mode 100644 src/page/Datasource/Datasource/NewDatasourceDrawer/Form/ProjectItem/ProjectSelect.tsx create mode 100644 src/page/Datasource/Datasource/NewDatasourceDrawer/Form/ProjectItem/index.tsx diff --git a/src/common/network/connection.ts b/src/common/network/connection.ts index 750f40736..a142846df 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 }, /** 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..7a55d9f86 --- /dev/null +++ b/src/page/Datasource/Datasource/NewDatasourceDrawer/Form/ProjectItem/ProjectSelect.tsx @@ -0,0 +1,17 @@ +import { Select, SelectProps } from 'antd'; + +export default function ProjectSelect({ value, onChange, options, ...rest }: SelectProps) { + value = value || -999; + options = (options || []).concat({ + label: '不绑定项目', + value: -999, + }); + 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/index.tsx b/src/page/Datasource/Info/index.tsx index 2e1f4227f..b44c58525 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 { @@ -165,6 +166,50 @@ const Info: React.FC = ({ id, datasource }) => { title: formatMessage({ id: 'odc.Datasource.Info.Project' }), //所属项目 dataIndex: ['project', 'name'], width: 160, + render(value, record, index) { + const bindProjectName = record.dataSource?.projectName; + let tip = null; + if (bindProjectName) { + tip = `当前数据源所属项目 ${bindProjectName},无法修改。可通过编辑数据源修改所属项目`; + } else if (!canUpdate) { + tip = '无当前数据源权限'; + } + return ( + + ); + }, }, { title: formatMessage({ id: 'odc.Datasource.Info.LastSynchronizationTime' }), //最近一次同步时间 @@ -181,19 +226,6 @@ const Info: React.FC = ({ id, datasource }) => { render(_, record) { return ( - {canUpdate && ( - { - setVisible(true); - setDatabase(record); - }} - key={'transfer'} - > - {formatMessage({ id: 'odc.Datasource.Info.TransferProject' }) /*转移项目*/} - - )} - {canDelete && ( Date: Wed, 15 Nov 2023 15:11:30 +0800 Subject: [PATCH 2/5] support bind datasource --- .../Form/ProjectItem/ProjectSelect.tsx | 12 +++++--- .../Form/ProjectItem/index.tsx | 28 ++++++++++++++++--- .../Info/ChangeProjectModal/ProjectSelect.tsx | 12 ++++++-- .../Info/NewDataBaseButton/index.tsx | 21 ++++++++++++-- src/page/Datasource/Info/index.tsx | 2 ++ .../Database/AddDataBaseButton/index.tsx | 20 ++++++++----- src/page/Project/Database/index.tsx | 13 +++++++-- 7 files changed, 87 insertions(+), 21 deletions(-) diff --git a/src/page/Datasource/Datasource/NewDatasourceDrawer/Form/ProjectItem/ProjectSelect.tsx b/src/page/Datasource/Datasource/NewDatasourceDrawer/Form/ProjectItem/ProjectSelect.tsx index 7a55d9f86..6a6342b76 100644 --- a/src/page/Datasource/Datasource/NewDatasourceDrawer/Form/ProjectItem/ProjectSelect.tsx +++ b/src/page/Datasource/Datasource/NewDatasourceDrawer/Form/ProjectItem/ProjectSelect.tsx @@ -2,10 +2,14 @@ import { Select, SelectProps } from 'antd'; export default function ProjectSelect({ value, onChange, options, ...rest }: SelectProps) { value = value || -999; - options = (options || []).concat({ - label: '不绑定项目', - value: -999, - }); + options = [] + .concat([ + { + label: '不绑定项目', + value: -999, + }, + ]) + .concat(options || []); function _onChange(v, option) { if (v === -999) { onChange(null, option); diff --git a/src/page/Datasource/Datasource/NewDatasourceDrawer/Form/ProjectItem/index.tsx b/src/page/Datasource/Datasource/NewDatasourceDrawer/Form/ProjectItem/index.tsx index a6ec28d94..2ab3eab0f 100644 --- a/src/page/Datasource/Datasource/NewDatasourceDrawer/Form/ProjectItem/index.tsx +++ b/src/page/Datasource/Datasource/NewDatasourceDrawer/Form/ProjectItem/index.tsx @@ -5,6 +5,7 @@ import React, { useContext, useMemo } from 'react'; import DatasourceFormContext from '../context'; import ProjectSelect from './ProjectSelect'; import { ProjectRole } from '@/d.ts/project'; +import { ExclamationCircleFilled } from '@ant-design/icons'; interface IProps {} @@ -15,13 +16,32 @@ const ProjectItem: React.FC = function () { defaultParams: [null, 1, 9999, false], }); const extra = useMemo(() => { - if (!context?.isEdit || !context?.originDatasource?.projectId) { + if ( + !context?.isEdit || + !context?.originDatasource?.projectId || + context?.originDatasource?.projectId === projectId + ) { return null; } + const icon = ; if (projectId) { - return ; + return ( + + ); } - return ; + return ( + + ); }, [context?.isEdit, context?.originDatasource, projectId]); const options = useMemo(() => { const base = []; @@ -58,7 +78,7 @@ const ProjectItem: React.FC = function () { .filter(Boolean); }, [data, context?.originDatasource, context?.isEdit]); return ( - + 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 b44c58525..5a5e0215d 100644 --- a/src/page/Datasource/Info/index.tsx +++ b/src/page/Datasource/Info/index.tsx @@ -106,6 +106,8 @@ const Info: React.FC = ({ id, datasource }) => { mode={datasource?.dialectType} onSuccess={() => reload()} dataSourceId={id} + projectId={datasource?.projectId} + projectName={datasource?.projectName} />