Skip to content

Commit b39df5d

Browse files
author
Zabilsya
committed
[DOP-22300] add increment_by field
1 parent 41ce398 commit b39df5d

File tree

16 files changed

+136
-24
lines changed

16 files changed

+136
-24
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ export const ConnectionAuthBasic = () => {
88

99
return (
1010
<>
11-
<Form.Item name={['auth_data', 'type']} hidden />
11+
<Form.Item name={['auth_data', 'type']} hidden>
12+
<Input size="large" />
13+
</Form.Item>
1214
<Form.Item label="User" name={['auth_data', 'user']} rules={[{ required: true }]}>
1315
<Input size="large" />
1416
</Form.Item>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ export const ConnectionAuthS3 = () => {
88

99
return (
1010
<>
11-
<Form.Item name={['auth_data', 'type']} hidden />
11+
<Form.Item name={['auth_data', 'type']} hidden>
12+
<Input size="large" />
13+
</Form.Item>
1214
<Form.Item label="Access key" name={['auth_data', 'access_key']} rules={[{ required: true }]}>
1315
<Input size="large" />
1416
</Form.Item>

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ export const ConnectionOracle = () => {
1111
const [isSidDisabled, setSidDisabled] = useState(false);
1212

1313
const changeDisabledFields = useCallback(() => {
14-
const serviceName = form.getFieldValue('service_name');
15-
const sid = form.getFieldValue('sid');
14+
const serviceName = form.getFieldValue(['connection_data', 'service_name']);
15+
const sid = form.getFieldValue(['connection_data', 'sid']);
1616
setServiceNameDisabled(!!sid);
1717
setSidDisabled(!!serviceName);
1818
}, [form]);
1919

2020
const handleFieldChange = () => {
2121
changeDisabledFields();
22-
form.validateFields(['service_name', 'sid']);
22+
form.validateFields([
23+
['connection_data', 'service_name'],
24+
['connection_data', 'sid'],
25+
]);
2326
};
2427

2528
//* It needs to validate required fields service_name and sid correctly if they have initial values

src/entities/group/api/hooks/useGetInitialGroup/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ export const useGetInitialGroup = ({ id }: GetGroupRequest): UseQueryResult<Grou
1010
queryKey: [GroupQueryKey.GET_GROUP, id],
1111
queryFn: () => groupService.getGroup({ id }),
1212
enabled: !!id,
13+
throwOnError: false,
1314
});
1415
};

src/entities/transfer/api/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export type TransferConnectionParamFieldName = 'source_params' | 'target_params'
3838

3939
export interface TransferStrategyParams {
4040
type: 'full' | 'incremental';
41+
increment_by?: string;
4142
}
4243

4344
interface TransferParamsHive {

src/entities/transfer/constants.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
1-
import { prepareOptionsForSelect } from '@shared/ui';
2-
3-
import { TransferStrategyParams } from './api';
4-
5-
export const TRANSFER_STRATEGY_PARAMS_SELECT_OPTIONS = prepareOptionsForSelect<TransferStrategyParams['type']>({
6-
data: ['full', 'incremental'],
7-
renderLabel: (data) => data,
8-
renderValue: (data) => data,
9-
});
1+
export const TRANSFER_INCREMENT_BY_DEFAULT = 'modified_since';
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { TRANSFER_INCREMENT_BY_DEFAULT } from '@entities/transfer';
2+
import { ConnectionType } from '@shared/types';
3+
import { Form, Input } from 'antd';
4+
import React, { useLayoutEffect, useState } from 'react';
5+
6+
export const IncrementByForm = () => {
7+
/* useWatch takes a value from Form.Item, but useFormInstance takes one from general form state
8+
* useWatch returns undefined when Form.Item has not rendered yet
9+
* https://github.com/ant-design/ant-design/issues/49010
10+
*/
11+
Form.useWatch(['source_params', 'type']);
12+
const formInstance = Form.useFormInstance();
13+
const sourceConnectionType = formInstance.getFieldValue(['source_params', 'type']) as ConnectionType;
14+
const [isDisabled, setDisabled] = useState(false);
15+
16+
// change increment_by value and disabled field state depending on source connection type
17+
useLayoutEffect(() => {
18+
switch (sourceConnectionType) {
19+
case ConnectionType.HDFS:
20+
case ConnectionType.S3:
21+
setDisabled(true);
22+
return formInstance.setFields([
23+
{
24+
name: ['strategy_params', 'increment_by'],
25+
value: TRANSFER_INCREMENT_BY_DEFAULT,
26+
errors: [],
27+
},
28+
]);
29+
case ConnectionType.CLICKHOUSE:
30+
case ConnectionType.HIVE:
31+
case ConnectionType.MS_SQL:
32+
case ConnectionType.MY_SQL:
33+
case ConnectionType.ORACLE:
34+
case ConnectionType.POSTGRES:
35+
return setDisabled(false);
36+
}
37+
}, [formInstance, sourceConnectionType]);
38+
39+
return (
40+
<Form.Item label="Increment by" name={['strategy_params', 'increment_by']} rules={[{ required: true }]}>
41+
<Input size="large" disabled={isDisabled} />
42+
</Form.Item>
43+
);
44+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './IncrementByForm';
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
import { TransferStrategyParams } from '@entities/transfer';
3+
import { prepareOptionsForSelect } from '@shared/ui';
4+
5+
import { IncrementByForm } from './components';
6+
7+
export const TRANSFER_STRATEGY_PARAMS_SELECT_OPTIONS = prepareOptionsForSelect<TransferStrategyParams['type']>({
8+
data: ['full', 'incremental'],
9+
renderLabel: (data) => data,
10+
renderValue: (data) => data,
11+
});
12+
13+
export const INCREMENT_BY_COMPONENT = {
14+
full: null,
15+
incremental: <IncrementByForm />,
16+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from 'react';
2+
import { Fieldset, Select } from '@shared/ui';
3+
import { Form } from 'antd';
4+
import { TransferStrategyParams } from '@entities/transfer';
5+
6+
import { INCREMENT_BY_COMPONENT, TRANSFER_STRATEGY_PARAMS_SELECT_OPTIONS } from './constants';
7+
8+
export const StrategyParams = () => {
9+
const name = ['strategy_params', 'type'];
10+
11+
/* useWatch takes a value from Form.Item, but useFormInstance takes one from general form state
12+
* useWatch returns undefined when Form.Item has not rendered yet
13+
* https://github.com/ant-design/ant-design/issues/49010
14+
*/
15+
Form.useWatch(name);
16+
const strategyParamsType = Form.useFormInstance().getFieldValue(name) as TransferStrategyParams['type'];
17+
18+
return (
19+
<Fieldset title="Strategy params">
20+
<Form.Item label="Strategy params" name={name} rules={[{ required: true }]}>
21+
<Select size="large" options={TRANSFER_STRATEGY_PARAMS_SELECT_OPTIONS} placeholder="Select strategy" />
22+
</Form.Item>
23+
{INCREMENT_BY_COMPONENT[strategyParamsType]}
24+
</Fieldset>
25+
);
26+
};

0 commit comments

Comments
 (0)