Skip to content

Commit 128b0a2

Browse files
committed
Merge Samba and S3 auth with other fields
1 parent 5e01d94 commit 128b0a2

File tree

6 files changed

+51
-89
lines changed

6 files changed

+51
-89
lines changed

src/entities/connection/ui/ConnectionTypeForm/components/ConnectionAuthBasic/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
22
import { Form, Input } from 'antd';
33
import { useTranslation } from 'react-i18next';
44

@@ -8,9 +8,14 @@ export const ConnectionAuthBasic = () => {
88
const { t } = useTranslation('auth');
99
const { isRequired } = useSensitiveFields();
1010

11+
// Reset auth type after switching connection type in form
12+
const formInstance = Form.useFormInstance();
13+
useEffect(() => {
14+
formInstance.setFieldValue(['auth_data', 'type'], 'basic');
15+
}, [formInstance]);
16+
1117
return (
1218
<>
13-
{/* Hide Form.Item control, because its value is set in 'useSelectConnectionType' hook */}
1419
<Form.Item name={['auth_data', 'type']} hidden />
1520
<Form.Item label={t('username')} name={['auth_data', 'user']} rules={[{ required: true }]}>
1621
<Input size="large" />

src/entities/connection/ui/ConnectionTypeForm/components/ConnectionAuthS3/index.tsx

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/entities/connection/ui/ConnectionTypeForm/components/ConnectionAuthSamba/index.tsx

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/entities/connection/ui/ConnectionTypeForm/components/ConnectionS3/index.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
22
import { Form, Input, Radio } from 'antd';
33
import { useTranslation } from 'react-i18next';
44

5-
import { ConnectionAuthS3 } from '../ConnectionAuthS3';
65
import { ConnectionHttpProtocol } from '../ConnectionHttpProtocol';
6+
import { useSensitiveFields } from '../../hooks';
77

88
export const ConnectionS3 = () => {
99
const { t } = useTranslation('connection');
10+
const { isRequired } = useSensitiveFields();
11+
12+
// Reset auth type after switching connection type in form
13+
const formInstance = Form.useFormInstance();
14+
useEffect(() => {
15+
formInstance.setFieldValue(['auth_data', 'type'], 's3');
16+
}, [formInstance]);
1017

1118
return (
1219
<>
@@ -31,7 +38,14 @@ export const ConnectionS3 = () => {
3138
<Form.Item label={t('s3.region')} name={['connection_data', 'region']}>
3239
<Input size="large" placeholder="us-east-1" />
3340
</Form.Item>
34-
<ConnectionAuthS3 />
41+
42+
<Form.Item name={['auth_data', 'type']} hidden />
43+
<Form.Item label={t('s3.accessKey')} name={['auth_data', 'access_key']} rules={[{ required: true }]}>
44+
<Input size="large" />
45+
</Form.Item>
46+
<Form.Item label={t('s3.secretKey')} name={['auth_data', 'secret_key']} rules={[{ required: isRequired }]}>
47+
<Input.Password size="large" />
48+
</Form.Item>
3549
</>
3650
);
3751
};

src/entities/connection/ui/ConnectionTypeForm/components/ConnectionSamba/index.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import React, { useState } from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import { Form, Input, InputNumber, Radio, RadioChangeEvent } from 'antd';
33
import { useTranslation } from 'react-i18next';
44

55
import { MAX_ALLOWED_PORT, MIN_ALLOWED_PORT } from '../../constants';
6-
import { ConnectionAuthSamba } from '../ConnectionAuthSamba';
6+
import { useSensitiveFields } from '../../hooks';
77

88
export const ConnectionSamba = () => {
99
const { t } = useTranslation('connection');
10+
const { isRequired } = useSensitiveFields();
1011

12+
// Reset auth type after switching connection type in form
1113
const formInstance = Form.useFormInstance();
1214
Form.useWatch('protocol', formInstance);
1315

@@ -21,6 +23,10 @@ export const ConnectionSamba = () => {
2123
}
2224
};
2325

26+
useEffect(() => {
27+
formInstance.setFieldValue(['auth_data', 'type'], 'samba');
28+
}, [formInstance]);
29+
2430
return (
2531
<>
2632
<Form.Item label={t('host')} name={['connection_data', 'host']} rules={[{ required: true }]}>
@@ -46,7 +52,25 @@ export const ConnectionSamba = () => {
4652
<Form.Item label={t('samba.domain')} name={['connection_data', 'domain']}>
4753
<Input size="large" placeholder="mycompany.com" />
4854
</Form.Item>
49-
<ConnectionAuthSamba />
55+
56+
{/* Hide Form.Item control, because its value is set in 'useSelectConnectionType' hook */}
57+
<Form.Item name={['auth_data', 'type']} hidden />
58+
<Form.Item label={t('username', { ns: 'auth' })} name={['auth_data', 'user']} rules={[{ required: true }]}>
59+
<Input size="large" />
60+
</Form.Item>
61+
<Form.Item
62+
label={t('password', { ns: 'auth' })}
63+
name={['auth_data', 'password']}
64+
rules={[{ required: isRequired }]}
65+
>
66+
<Input.Password size="large" />
67+
</Form.Item>
68+
<Form.Item label={t('samba.authType')} name={['auth_data', 'auth_type']} initialValue="NTLMv2">
69+
<Radio.Group>
70+
<Radio.Button value="NTLMv1">NTLMv1</Radio.Button>
71+
<Radio.Button value="NTLMv2">NTLMv2</Radio.Button>
72+
</Radio.Group>
73+
</Form.Item>
5074
</>
5175
);
5276
};

src/entities/connection/ui/ConnectionTypeForm/hooks/useSelectConnectionType/index.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,14 @@
11
import { ConnectionType } from '@shared/types';
2-
import { Form } from 'antd';
32
import { useState } from 'react';
4-
import { ConnectionAuthType } from '@entities/connection';
53

64
import { UseSelectConnectionTypeProps } from './types';
75

86
/** Hook for handling connection type state in connection form */
97
export const useSelectConnectionType = ({ initialType }: UseSelectConnectionTypeProps) => {
10-
const formInstance = Form.useFormInstance();
118
const [selectedConnectionType, setConnectionType] = useState<ConnectionType | undefined>(initialType);
129

13-
const getAuthDataTypeValue = (type: ConnectionType): ConnectionAuthType => {
14-
switch (type) {
15-
case ConnectionType.CLICKHOUSE:
16-
case ConnectionType.FTP:
17-
case ConnectionType.FTPS:
18-
case ConnectionType.HDFS:
19-
case ConnectionType.HIVE:
20-
case ConnectionType.MSSQL:
21-
case ConnectionType.MYSQL:
22-
case ConnectionType.ORACLE:
23-
case ConnectionType.POSTGRES:
24-
case ConnectionType.SFTP:
25-
case ConnectionType.WEBDAV:
26-
return ConnectionAuthType.BASIC;
27-
case ConnectionType.S3:
28-
return ConnectionAuthType.S3;
29-
case ConnectionType.SAMBA:
30-
return ConnectionAuthType.SAMBA;
31-
}
32-
};
33-
3410
const handleSelectConnectionType = (type: ConnectionType) => {
3511
setConnectionType(type);
36-
formInstance.setFieldValue(['auth_data', 'type'], getAuthDataTypeValue(type));
3712
};
3813

3914
return { selectedConnectionType, handleSelectConnectionType };

0 commit comments

Comments
 (0)