Skip to content

Commit

Permalink
fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
HSunboy committed Nov 20, 2023
2 parents 2ca2350 + 6df9e7b commit 6303008
Show file tree
Hide file tree
Showing 13 changed files with 274 additions and 44 deletions.
3 changes: 2 additions & 1 deletion src/common/network/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ function generateConnectionParams(formData: Partial<IConnectionFormData>, 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 },
/**
* 逻辑同 pwd
*/
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 || {},
Expand Down
4 changes: 2 additions & 2 deletions src/component/Action/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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]);

Expand Down
2 changes: 2 additions & 0 deletions src/d.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,8 @@ export interface IConnection {
jdbcUrlParameters?: Record<string, string>;
sessionInitScript?: string;
defaultSchema?: string;
projectId?: number;
readonly projectName?: string;
}

export interface IConnectionLabel {
Expand Down
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} />;
}
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;
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { testConnection } from '@/common/network/connection';
import { listEnvironments } from '@/common/network/env';
import { IDataSourceType, IDatasource } from '@/d.ts/datasource';
import { AccountType, ConnectType, ConnectionMode, IConnectionTestErrorType } from '@/d.ts';
import { AccountType, ConnectType, IConnectionTestErrorType } from '@/d.ts';
import { haveOCP } from '@/util/env';
import { formatMessage } from '@/util/intl';
import { useRequest } from 'ahooks';
Expand All @@ -27,10 +27,7 @@ import { forwardRef, useImperativeHandle, useState } from 'react';
import Account from './Account';
import AddressItems from './AddressItems';
import DatasourceFormContext from './context';
import DBTypeItem from './DBTypeItem';
import ParseURLItem from './ParseURLItem';
import SSLItem from './SSLItem';
import SysForm from './SysForm';
import { ConnectTypeText } from '@/constant/label';
import {
getAllConnectTypes,
Expand All @@ -39,8 +36,9 @@ import {
getDsByConnectType,
} from '@/common/datasource';
import ExtraConfig from './ExtraConfig';
import JDBCParamsItem from './JDBCParamsItem';
import RiskLevelLabel from '@/component/RiskLevelLabel';
import ProjectItem from './ProjectItem';
import login from '@/store/login';
const Option = Select.Option;
export interface IFormRef {
form: FormInstance<IDatasource>;
Expand Down Expand Up @@ -292,6 +290,7 @@ export default forwardRef<IFormRef, IProps>(function DatasourceForm(
})}
</Select>
</Form.Item>
{!login.isPrivateSpace() && <ProjectItem />}
{!haveOCP() && <ExtraConfig />}
</>
);
Expand Down
10 changes: 9 additions & 1 deletion src/page/Datasource/Datasource/NewDatasourceDrawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 10 additions & 2 deletions src/page/Datasource/Info/ChangeProjectModal/ProjectSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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 (
Expand All @@ -55,6 +62,7 @@ export default function ProjectSelect({ projects, value, currentDatabase, onChan
</Select>
<Checkbox
checked={_isNull}
disabled={disabled}
onChange={(e) => (e.target.checked ? onChange(null) : onChange(undefined))}
>
{
Expand Down
21 changes: 19 additions & 2 deletions src/page/Datasource/Info/NewDataBaseButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>(false);
const [form] = Form.useForm<
Pick<IDatabase, 'name' | 'collationName' | 'charsetName'> & { projectId: number }
Expand All @@ -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:
Expand Down Expand Up @@ -152,7 +165,11 @@ export default function NewDataBaseButton({ dataSourceId, onSuccess, mode }: IPr
name={'projectId'}
label={formatMessage({ id: 'odc.Info.NewDataBaseButton.Project' })} /*所属项目*/
>
<ProjectSelect projects={project?.contents} currentDatabase={null} />
<ProjectSelect
disabled={!!projectId}
projects={project?.contents}
currentDatabase={null}
/>
</Form.Item>
</Form>
</Modal>
Expand Down
Loading

0 comments on commit 6303008

Please sign in to comment.