Skip to content

Commit

Permalink
[DOP-20065] transfer list and transfer detail (#40)
Browse files Browse the repository at this point in the history
Co-authored-by: Zabilsya <[email protected]>
  • Loading branch information
Zabilsya and Zabilsya authored Nov 2, 2024
1 parent 074b066 commit d5139a2
Show file tree
Hide file tree
Showing 48 changed files with 620 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1 @@
API_URL="https://localhost:8000/v1/"
API_URL="http://localhost:8000/v1/"
9 changes: 9 additions & 0 deletions src/app/config/router/instance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { CreateGroupPage, GroupDetailPage, GroupListPage, UpdateGroupPage } from
import { AuthProvider } from '@entities/auth';
import { CreateQueuePage, QueueDetailPage, QueueListPage, UpdateQueuePage } from '@pages/queue';
import { ConnectionDetailPage, ConnectionListPage } from '@pages/connection';
import { TransferDetailPage, TransferListPage } from '@pages/transfer';

import { ErrorBoundary, NotFoundError } from '../errorBoundary';

Expand Down Expand Up @@ -86,6 +87,14 @@ export const router = createBrowserRouter([
path: '/connections/:id',
element: <ConnectionDetailPage />,
},
{
path: '/transfers',
element: <TransferListPage />,
},
{
path: '/transfers/:id',
element: <TransferDetailPage />,
},
],
},
{
Expand Down
6 changes: 5 additions & 1 deletion src/app/styles/antd.less
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
border-radius: 0;
}

.ant-descriptions {
width: 100%;
}

.ant-descriptions-item-label {
width: 300px;
width: 250px;
font-weight: 700;
}

Expand Down
22 changes: 11 additions & 11 deletions src/entities/connection/api/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PaginationRequest } from '@shared/types';
import { ConnectionType, PaginationRequest } from '@shared/types';

export type Connection = {
id: number;
Expand All @@ -11,33 +11,33 @@ type ConnectionData = ConnectionHive | ConnectionHdfs | ConnectionOracle | Conne

interface ConnectionHive {
auth_data: {
type: 'hive';
type: ConnectionType.HIVE;
user: string;
};
connection_data: {
type: 'hive';
type: ConnectionType.HIVE;
cluster: string;
};
}

interface ConnectionHdfs {
auth_data: {
type: 'hdfs';
type: ConnectionType.HDFS;
user: string;
};
connection_data: {
type: 'hdfs';
type: ConnectionType.HDFS;
cluster: string;
};
}

interface ConnectionOracle {
auth_data: {
type: 'oracle';
type: ConnectionType.ORACLE;
user: string;
};
connection_data: {
type: 'oracle';
type: ConnectionType.ORACLE;
host: string;
port: number;
service_name: string | null;
Expand All @@ -48,11 +48,11 @@ interface ConnectionOracle {

interface ConnectionPostgres {
auth_data: {
type: 'postgres';
type: ConnectionType.POSTGRES;
user: string;
};
connection_data: {
type: 'postgres';
type: ConnectionType.POSTGRES;
host: string;
port: number;
database_name: string;
Expand All @@ -62,11 +62,11 @@ interface ConnectionPostgres {

interface ConnectionS3 {
auth_data: {
type: 's3';
type: ConnectionType.S3;
access_key: string;
};
connection_data: {
type: 's3';
type: ConnectionType.S3;
host: string;
bucket: string;
bucket_style: 'domain' | 'path';
Expand Down
1 change: 1 addition & 0 deletions src/entities/transfer/api/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useGetTransfer';
13 changes: 13 additions & 0 deletions src/entities/transfer/api/hooks/useGetTransfer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useSuspenseQuery, UseSuspenseQueryResult } from '@tanstack/react-query';

import { transferService } from '../../transferService';
import { GetTransferRequest, Transfer } from '../../types';
import { TransferQueryKey } from '../../keys';

/** Hook for getting transfer info from backend */
export const useGetTransfer = ({ id }: GetTransferRequest): UseSuspenseQueryResult<Transfer> => {
return useSuspenseQuery({
queryKey: [TransferQueryKey.GET_TRANSFER, id],
queryFn: () => transferService.getTransfer({ id }),
});
};
4 changes: 4 additions & 0 deletions src/entities/transfer/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './transferService';
export * from './types';
export * from './keys';
export * from './hooks';
4 changes: 4 additions & 0 deletions src/entities/transfer/api/keys/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const TransferQueryKey = {
GET_TRANSFERS: 'GET_TRANSFERS',
GET_TRANSFER: 'GET_TRANSFER',
} as const;
14 changes: 14 additions & 0 deletions src/entities/transfer/api/transferService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { axiosInstance } from '@shared/config';
import { PaginationResponse } from '@shared/types';

import { GetTransferRequest, GetTransfersRequest, Transfer } from './types';

export const transferService = {
getTransfers: (params: GetTransfersRequest): Promise<PaginationResponse<Transfer>> => {
return axiosInstance.get('transfers', { params });
},

getTransfer: ({ id }: GetTransferRequest): Promise<Transfer> => {
return axiosInstance.get(`transfers/${id}`);
},
};
81 changes: 81 additions & 0 deletions src/entities/transfer/api/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { ConnectionType, FileFormat, FileFormatCsv, FileFormatJsonLine, PaginationRequest } from '@shared/types';

export interface Transfer {
id: number;
group_id: number;
name: string;
source_connection_id: number;
target_connection_id: number;
description: string;
is_scheduled: boolean;
schedule: string;
queue_id: number;
source_params:
| TransferParamsHive
| TransferParamsOracle
| TransferParamsPostgres
| TransferSourceParamsHdfs
| TransferSourceParamsS3;
target_params:
| TransferParamsHive
| TransferParamsOracle
| TransferParamsPostgres
| TransferTargetParamsHdfs
| TransferTargetParamsS3;
strategy_params: TransferStrategyParams;
}

interface TransferStrategyParams {
type: 'full' | 'incremental';
}

interface TransferParamsHive {
type: ConnectionType.HIVE;
table_name: string;
}

interface TransferParamsOracle {
type: ConnectionType.ORACLE;
table_name: string;
}

interface TransferParamsPostgres {
type: ConnectionType.POSTGRES;
table_name: string;
}

interface TransferParamsHdfs {
type: ConnectionType.HDFS;
directory_path: string;
options: object;
}

interface TransferSourceParamsHdfs extends TransferParamsHdfs {
file_format: FileFormat;
}

interface TransferTargetParamsHdfs extends TransferParamsHdfs {
file_format: FileFormatCsv | FileFormatJsonLine;
}

interface TransferParamsS3 {
type: ConnectionType.S3;
directory_path: string;
options: object;
}

interface TransferSourceParamsS3 extends TransferParamsS3 {
file_format: FileFormat;
}

interface TransferTargetParamsS3 extends TransferParamsS3 {
file_format: FileFormatCsv | FileFormatJsonLine;
}

export interface GetTransfersRequest extends PaginationRequest {
group_id: number;
}

export interface GetTransferRequest {
id: number;
}
1 change: 1 addition & 0 deletions src/entities/transfer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './api';
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getDescriptionItems } from './utils';

export const ConnectionAuthData = ({ data, ...props }: ConnectionAuthDataProps) => {
return (
<Descriptions title="Connection auth data" bordered {...props}>
<Descriptions {...props}>
<Descriptions.Item label="Type" span={3}>
{data.type}
</Descriptions.Item>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { DescriptionItem } from '@shared/types';
import { ConnectionType, DescriptionItem } from '@shared/types';

import { GetDescriptionItemsProps } from './types';

/** Util for mapping data for Description component depends on connection type */
export const getDescriptionItems = ({ data }: GetDescriptionItemsProps): DescriptionItem[] => {
switch (data.type) {
case 's3':
case ConnectionType.S3:
return [
{
label: 'Access key',
content: data.access_key,
},
];
default:
case ConnectionType.HIVE:
case ConnectionType.HDFS:
case ConnectionType.ORACLE:
case ConnectionType.POSTGRES:
return [
{
label: 'User',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getDescriptionItems } from './utils';

export const ConnectionData = ({ data, ...props }: ConnectionDataProps) => {
return (
<Descriptions title="Connection data" bordered {...props}>
<Descriptions {...props}>
<Descriptions.Item label="Type" span={3}>
{data.type}
</Descriptions.Item>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { DescriptionItem } from '@shared/types';
import { ConnectionType, DescriptionItem } from '@shared/types';

import { GetDescriptionItemsProps } from './types';

/** Util for mapping data for Description component depends on connection type */
export const getDescriptionItems = ({ data }: GetDescriptionItemsProps): DescriptionItem[] => {
switch (data.type) {
case 'oracle':
case ConnectionType.ORACLE:
return [
{
label: 'Host',
Expand All @@ -24,7 +24,7 @@ export const getDescriptionItems = ({ data }: GetDescriptionItemsProps): Descrip
content: data.sid || '',
},
];
case 'postgres':
case ConnectionType.POSTGRES:
return [
{
label: 'Host',
Expand All @@ -39,7 +39,7 @@ export const getDescriptionItems = ({ data }: GetDescriptionItemsProps): Descrip
content: data.database_name,
},
];
case 's3':
case ConnectionType.S3:
return [
{
label: 'Host',
Expand All @@ -66,7 +66,8 @@ export const getDescriptionItems = ({ data }: GetDescriptionItemsProps): Descrip
content: data.region || '',
},
];
default:
case ConnectionType.HIVE:
case ConnectionType.HDFS:
return [
{
label: 'Cluster',
Expand Down
9 changes: 6 additions & 3 deletions src/features/connection/ConnectionDetailInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ export const ConnectionDetailInfo = ({ connection, group, ...props }: Connection
<Descriptions.Item label="Group" span={3}>
<Link to={`/groups/${group.id}`}>{group.name}</Link>
</Descriptions.Item>
<Descriptions.Item className={classes.subDescription} label="Auth data" span={3}>
<ConnectionAuthData data={connection.auth_data} />
</Descriptions.Item>
<Descriptions.Item className={classes.subDescription} label="Connection data" span={3}>
<ConnectionData data={connection.connection_data} />
</Descriptions.Item>
</Descriptions>

<ConnectionAuthData data={connection.auth_data} />
<ConnectionData data={connection.connection_data} />
</div>
);
};
14 changes: 14 additions & 0 deletions src/features/connection/ConnectionDetailInfo/styles.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,18 @@
display: flex;
flex-direction: column;
gap: 24px;

.subDescription {
:global(+ .ant-descriptions-item-content) {
padding: 0;
}

:global(.ant-descriptions-item) {
padding: 0;
}

:global(.ant-descriptions-view) {
border: 0;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import { Descriptions } from 'antd';

import { TransferFileFormatDataProps } from './types';
import { getDescriptionItems } from './utils';

export const TransferFileFormatData = ({ data, ...props }: TransferFileFormatDataProps) => {
return (
<Descriptions {...props}>
<Descriptions.Item label="Type" span={3}>
{data.type}
</Descriptions.Item>
{getDescriptionItems({ data }).map((item, index) => (
<Descriptions.Item label={item.label} span={3} key={index}>
{item.content}
</Descriptions.Item>
))}
</Descriptions>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { FileFormat } from '@shared/types';
import { DescriptionsProps } from 'antd';

export interface TransferFileFormatDataProps extends DescriptionsProps {
data: FileFormat;
}
Loading

0 comments on commit d5139a2

Please sign in to comment.