-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
274 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/page/Datasource/Datasource/NewDatasourceDrawer/Form/ProjectItem/ProjectSelect.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <Select value={value} onChange={_onChange} options={options} {...rest} />; | ||
} |
103 changes: 103 additions & 0 deletions
103
src/page/Datasource/Datasource/NewDatasourceDrawer/Form/ProjectItem/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { listProjects } from '@/common/network/project'; | ||
import { useRequest } from 'ahooks'; | ||
import { Alert, Form, Space, Tooltip } from 'antd'; | ||
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 {} | ||
|
||
const ProjectItem: React.FC<IProps> = function () { | ||
const context = useContext(DatasourceFormContext); | ||
const projectId = Form.useWatch('projectId', context.form); | ||
const { data, loading } = useRequest(listProjects, { | ||
defaultParams: [null, 1, 9999, false], | ||
}); | ||
const extra = useMemo(() => { | ||
if ( | ||
!context?.isEdit || | ||
!context?.originDatasource?.projectId || | ||
context?.originDatasource?.projectId === projectId | ||
) { | ||
return null; | ||
} | ||
const icon = <ExclamationCircleFilled />; | ||
if (projectId) { | ||
return ( | ||
<Alert | ||
showIcon | ||
icon={icon} | ||
type="error" | ||
message="修改项目后,此数据源下的所有数据库将绑定新的项目" | ||
/> | ||
); | ||
} | ||
return ( | ||
<Alert | ||
showIcon | ||
icon={icon} | ||
type="error" | ||
message="不绑定项目后,此数据源下的所有数据库将从原项目中移出" | ||
/> | ||
); | ||
}, [context?.isEdit, context?.originDatasource, projectId]); | ||
const options = useMemo(() => { | ||
const base = []; | ||
if (context?.isEdit && context?.originDatasource?.projectId) { | ||
base.push({ | ||
label: context?.originDatasource?.projectName, | ||
value: context?.originDatasource?.projectId, | ||
}); | ||
} | ||
return base | ||
.concat( | ||
data?.contents?.map((item) => { | ||
if (item.id === context?.originDatasource?.projectId) { | ||
return null; | ||
} | ||
let disabledInfo: string = null; | ||
if ( | ||
!item.currentUserResourceRoles?.includes(ProjectRole.DBA) && | ||
!item.currentUserResourceRoles?.includes(ProjectRole.OWNER) | ||
) { | ||
disabledInfo = '非项目管理员或 DBA,无法将数据源加入此项目'; | ||
} | ||
return { | ||
label: ( | ||
<Tooltip title={disabledInfo}> | ||
<div>{item.name}</div> | ||
</Tooltip> | ||
), | ||
value: item.id, | ||
disabled: !!disabledInfo, | ||
}; | ||
}), | ||
) | ||
.filter(Boolean); | ||
}, [data, context?.originDatasource, context?.isEdit]); | ||
return ( | ||
<Space direction="vertical" size={1}> | ||
<Form.Item | ||
name={'projectId'} | ||
label="项目" | ||
requiredMark={false} | ||
extra={'绑定项目后,数据源内的所有数据库将移入此项目'} | ||
> | ||
<ProjectSelect | ||
loading={loading} | ||
options={options} | ||
showSearch | ||
optionFilterProp="children" | ||
style={{ | ||
width: 208, | ||
}} | ||
/> | ||
</Form.Item> | ||
{extra} | ||
</Space> | ||
); | ||
}; | ||
|
||
export default ProjectItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.