Skip to content

Commit ffc008e

Browse files
ZabilsyaZabilsya
andauthored
[DOP-22030] create transfer (#47)
Co-authored-by: Zabilsya <[email protected]>
1 parent aa764ed commit ffc008e

File tree

47 files changed

+543
-28
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+543
-28
lines changed

src/app/config/router/instance.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
CreateConnectionPage,
1313
UpdateConnectionPage,
1414
} from '@pages/connection';
15-
import { TransferDetailPage, TransferListPage } from '@pages/transfer';
15+
import { CreateTransferPage, TransferDetailPage, TransferListPage } from '@pages/transfer';
1616
import { RunDetailPage } from '@pages/run';
1717

1818
import { ErrorBoundary, NotFoundError } from '../errorBoundary';
@@ -117,6 +117,10 @@ export const router = createBrowserRouter([
117117
path: '/transfers/runs/:id',
118118
element: <RunDetailPage />,
119119
},
120+
{
121+
path: '/transfers/create',
122+
element: <CreateTransferPage />,
123+
},
120124
],
121125
},
122126
{

src/entities/transfer/api/transferService.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { axiosInstance } from '@shared/config';
22
import { PaginationResponse } from '@shared/types';
33

4-
import { DeleteTransferRequest, GetTransferRequest, GetTransfersRequest, Transfer } from './types';
4+
import {
5+
CreateTransferRequest,
6+
DeleteTransferRequest,
7+
GetTransferRequest,
8+
GetTransfersRequest,
9+
Transfer,
10+
} from './types';
511

612
export const transferService = {
713
getTransfers: (params: GetTransfersRequest): Promise<PaginationResponse<Transfer>> => {
@@ -12,6 +18,10 @@ export const transferService = {
1218
return axiosInstance.get(`transfers/${id}`);
1319
},
1420

21+
createTransfer: (data: CreateTransferRequest): Promise<Transfer> => {
22+
return axiosInstance.post(`transfers`, data);
23+
},
24+
1525
deleteTransfer: ({ id }: DeleteTransferRequest): Promise<null> => {
1626
return axiosInstance.delete(`transfers/${id}`);
1727
},

src/entities/transfer/api/types.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ export interface Transfer {
77
source_connection_id: number;
88
target_connection_id: number;
99
description: string;
10-
is_scheduled: boolean;
11-
schedule: string;
1210
queue_id: number;
1311
source_params:
1412
| TransferParamsHive
@@ -23,9 +21,13 @@ export interface Transfer {
2321
| TransferTargetParamsHdfs
2422
| TransferTargetParamsS3;
2523
strategy_params: TransferStrategyParams;
24+
is_scheduled: boolean;
25+
schedule: string;
2626
}
2727

28-
interface TransferStrategyParams {
28+
export type TransferConnectionParamFieldName = 'source_params' | 'target_params';
29+
30+
export interface TransferStrategyParams {
2931
type: 'full' | 'incremental';
3032
}
3133

@@ -47,7 +49,6 @@ interface TransferParamsPostgres {
4749
interface TransferParamsHdfs {
4850
type: ConnectionType.HDFS;
4951
directory_path: string;
50-
options: object;
5152
}
5253

5354
interface TransferSourceParamsHdfs extends TransferParamsHdfs {
@@ -61,7 +62,6 @@ interface TransferTargetParamsHdfs extends TransferParamsHdfs {
6162
interface TransferParamsS3 {
6263
type: ConnectionType.S3;
6364
directory_path: string;
64-
options: object;
6565
}
6666

6767
interface TransferSourceParamsS3 extends TransferParamsS3 {
@@ -80,6 +80,8 @@ export interface GetTransferRequest {
8080
id: number;
8181
}
8282

83+
export interface CreateTransferRequest extends Omit<Transfer, 'id'> {}
84+
8385
export interface DeleteTransferRequest {
8486
id: number;
8587
}

src/entities/transfer/constants.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { prepareOptionsForSelect } from '@shared/ui';
2+
import { FileFormatType } from '@shared/types';
3+
4+
import { TransferStrategyParams } from './api';
5+
6+
export const TRANSFER_STRATEGY_PARAMS_SELECT_OPTIONS = prepareOptionsForSelect<TransferStrategyParams['type']>({
7+
data: ['full', 'incremental'],
8+
renderLabel: (data) => data,
9+
renderValue: (data) => data,
10+
});
11+
12+
export const TRANSFER_SOURCE_CONNECTION_FILE_FORMAT_SELECT_OPTIONS = prepareOptionsForSelect<FileFormatType>({
13+
data: Object.values(FileFormatType),
14+
renderLabel: (data) => data,
15+
renderValue: (data) => data,
16+
});
17+
18+
export const TRANSFER_TARGET_CONNECTION_FILE_FORMAT_SELECT_OPTIONS = prepareOptionsForSelect<
19+
Exclude<FileFormatType, 'json'>
20+
>({
21+
data: [FileFormatType.CSV, FileFormatType.JSON_LINE],
22+
renderLabel: (data) => data,
23+
renderValue: (data) => data,
24+
});

src/entities/transfer/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './api';
2+
export * from './constants';
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react';
2+
import { ConnectionQueryKey, connectionService } from '@entities/connection';
3+
import { ManagedSelect } from '@shared/ui';
4+
import { Divider, Form, Input } from 'antd';
5+
6+
import { useSelectConnectionType } from '../../hooks';
7+
8+
import { SourceParamsProps } from './types';
9+
import { TRANSFER_SOURCE_CONNECTION_TYPE_COMPONENT } from './constants';
10+
11+
export const SourceParams = ({ groupId, initialSourceConnectionType }: SourceParamsProps) => {
12+
const { selectedConnectionType, handleSelectConnection } = useSelectConnectionType({
13+
connectionParamFieldName: 'source_params',
14+
initialConnectionType: initialSourceConnectionType,
15+
});
16+
17+
return (
18+
<>
19+
<Divider>Source params</Divider>
20+
<Form.Item label="Source connection" name="source_connection_id" rules={[{ required: true }]}>
21+
<ManagedSelect
22+
size="large"
23+
queryKey={[ConnectionQueryKey.GET_CONNECTIONS, groupId]}
24+
queryFunction={(params) => connectionService.getConnections({ group_id: groupId, ...params })}
25+
renderOptionValue={(connection) => connection.id}
26+
renderOptionLabel={(connection) => connection.name}
27+
onSelect={handleSelectConnection}
28+
placeholder="Select source connection"
29+
/>
30+
</Form.Item>
31+
<Form.Item name={['source_params', 'type']} style={{ display: 'none' }}>
32+
<Input />
33+
</Form.Item>
34+
{TRANSFER_SOURCE_CONNECTION_TYPE_COMPONENT[selectedConnectionType!]}
35+
</>
36+
);
37+
};
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 { ConnectionType } from '@shared/types';
3+
4+
import { TransferConnectionHdfs } from '../TransferConnectionHdfs';
5+
import { TransferConnectionHive } from '../TransferConnectionHive';
6+
import { TransferConnectionOracle } from '../TransferConnectionOracle';
7+
import { TransferConnectionPostgres } from '../TransferConnectionPostgres';
8+
import { TransferConnectionS3 } from '../TransferConnectionS3';
9+
10+
export const TRANSFER_SOURCE_CONNECTION_TYPE_COMPONENT = {
11+
[ConnectionType.HDFS]: <TransferConnectionHdfs name="source_params" />,
12+
[ConnectionType.HIVE]: <TransferConnectionHive name="source_params" />,
13+
[ConnectionType.ORACLE]: <TransferConnectionOracle name="source_params" />,
14+
[ConnectionType.POSTGRES]: <TransferConnectionPostgres name="source_params" />,
15+
[ConnectionType.S3]: <TransferConnectionS3 name="source_params" />,
16+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './SourceParams';
2+
export * from './types';
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { ConnectionType } from '@shared/types';
2+
3+
export interface SourceParamsProps {
4+
groupId: number;
5+
initialSourceConnectionType?: ConnectionType;
6+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react';
2+
import { ConnectionQueryKey, connectionService } from '@entities/connection';
3+
import { ManagedSelect } from '@shared/ui';
4+
import { Divider, Form, Input } from 'antd';
5+
6+
import { useSelectConnectionType } from '../../hooks';
7+
8+
import { TargetParamsProps } from './types';
9+
import { TRANSFER_TARGET_CONNECTION_TYPE_COMPONENT } from './constants';
10+
11+
export const TargetParams = ({ groupId, initialTargetConnectionType }: TargetParamsProps) => {
12+
const { selectedConnectionType, handleSelectConnection } = useSelectConnectionType({
13+
connectionParamFieldName: 'target_params',
14+
initialConnectionType: initialTargetConnectionType,
15+
});
16+
17+
return (
18+
<>
19+
<Divider>Target params</Divider>
20+
<Form.Item label="Target connection" name="target_connection_id" rules={[{ required: true }]}>
21+
<ManagedSelect
22+
size="large"
23+
queryKey={[ConnectionQueryKey.GET_CONNECTIONS, groupId]}
24+
queryFunction={(params) => connectionService.getConnections({ group_id: groupId, ...params })}
25+
renderOptionValue={(connection) => connection.id}
26+
renderOptionLabel={(connection) => connection.name}
27+
onSelect={handleSelectConnection}
28+
placeholder="Select target connection"
29+
/>
30+
</Form.Item>
31+
<Form.Item name={['target_params', 'type']} style={{ display: 'none' }}>
32+
<Input />
33+
</Form.Item>
34+
{TRANSFER_TARGET_CONNECTION_TYPE_COMPONENT[selectedConnectionType!]}
35+
</>
36+
);
37+
};

0 commit comments

Comments
 (0)