Skip to content

Commit f759056

Browse files
author
Zabilsya
committed
[DOP-20046] create update delete connection
1 parent eb76bb0 commit f759056

File tree

74 files changed

+1091
-165
lines changed

Some content is hidden

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

74 files changed

+1091
-165
lines changed

docker/entrypoint.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ window.env = {
66
};
77
EOF
88

9+
sed -i '/<\/head>/i \ <script src="/env-config.js"></script>' /usr/share/nginx/html/index.html
10+
911
exec "$@"

src/app/config/router/instance.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import { AuthLayout, ErrorLayout, PrivateLayout } from '@app/layouts';
66
import { CreateGroupPage, GroupDetailPage, GroupListPage, UpdateGroupPage } from '@pages/group';
77
import { AuthProvider } from '@entities/auth';
88
import { CreateQueuePage, QueueDetailPage, QueueListPage, UpdateQueuePage } from '@pages/queue';
9-
import { ConnectionDetailPage, ConnectionListPage } from '@pages/connection';
9+
import {
10+
ConnectionDetailPage,
11+
ConnectionListPage,
12+
CreateConnectionPage,
13+
UpdateConnectionPage,
14+
} from '@pages/connection';
1015
import { TransferDetailPage, TransferListPage } from '@pages/transfer';
1116
import { RunDetailPage } from '@pages/run';
1217

@@ -92,6 +97,14 @@ export const router = createBrowserRouter([
9297
path: '/connections/:id',
9398
element: <ConnectionDetailPage />,
9499
},
100+
{
101+
path: '/connections/create',
102+
element: <CreateConnectionPage />,
103+
},
104+
{
105+
path: '/connections/:id/update',
106+
element: <UpdateConnectionPage />,
107+
},
95108
{
96109
path: '/transfers',
97110
element: <TransferListPage />,

src/app/styles/antd.less

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
border-radius: 0;
44
}
55

6-
.ant-descriptions {
7-
width: 100%;
8-
}
9-
106
.ant-descriptions-item-label {
117
width: 250px;
128
font-weight: 700;
@@ -16,7 +12,9 @@
1612
background-color: @white;
1713
}
1814

19-
.ant-select {
15+
.ant-descriptions,
16+
.ant-select,
17+
.ant-input-number {
2018
width: 100%;
2119
}
2220

src/entities/auth/api/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ export interface LoginRequest {
1111

1212
export interface LoginResponse {
1313
access_token: string;
14-
refresh_token: string;
14+
token_type: string;
1515
}

src/entities/connection/api/connectionService.ts

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

4-
import { GetConnectionsRequest, Connection, GetConnectionRequest } from './types';
4+
import {
5+
GetConnectionsRequest,
6+
Connection,
7+
GetConnectionRequest,
8+
CreateConnectionRequest,
9+
UpdateConnectionRequest,
10+
DeleteConnectionRequest,
11+
} from './types';
512

613
export const connectionService = {
714
getConnections: (params: GetConnectionsRequest): Promise<PaginationResponse<Connection>> => {
@@ -11,4 +18,16 @@ export const connectionService = {
1118
getConnection: ({ id }: GetConnectionRequest): Promise<Connection> => {
1219
return axiosInstance.get(`connections/${id}`);
1320
},
21+
22+
createConnection: (data: CreateConnectionRequest): Promise<Connection> => {
23+
return axiosInstance.post(`connections`, data);
24+
},
25+
26+
updateConnection: ({ id, ...data }: UpdateConnectionRequest): Promise<Connection> => {
27+
return axiosInstance.patch(`connections/${id}`, data);
28+
},
29+
30+
deleteConnection: ({ id }: DeleteConnectionRequest): Promise<null> => {
31+
return axiosInstance.delete(`connections/${id}`);
32+
},
1433
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './useGetConnection';
2+
export * from './useDeleteConnection';
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { useMutation, UseMutationResult, useQueryClient } from '@tanstack/react-query';
2+
import { notification } from 'antd';
3+
import { getErrorMessage } from '@shared/config';
4+
5+
import { connectionService } from '../../connectionService';
6+
import { DeleteConnectionRequest } from '../../types';
7+
import { ConnectionQueryKey } from '../../keys';
8+
9+
/** Hook for deleting connection */
10+
export const useDeleteConnection = (data: DeleteConnectionRequest): UseMutationResult => {
11+
const queryClient = useQueryClient();
12+
13+
return useMutation({
14+
mutationFn: () => connectionService.deleteConnection(data),
15+
onSuccess: () => {
16+
queryClient.invalidateQueries({ queryKey: [ConnectionQueryKey.GET_CONNECTIONS] });
17+
queryClient.removeQueries({ queryKey: [ConnectionQueryKey.GET_CONNECTION, data.id] });
18+
},
19+
onError: (error) => {
20+
notification.error({
21+
message: getErrorMessage(error),
22+
});
23+
},
24+
});
25+
};

src/entities/connection/api/types.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ export type Connection = {
99

1010
type ConnectionData = ConnectionHive | ConnectionHdfs | ConnectionOracle | ConnectionPostgres | ConnectionS3;
1111

12+
export type ConnectionBucketStyle = 'domain' | 'path';
13+
14+
export type ConnectionProtocol = 'https' | 'http';
15+
1216
interface ConnectionHive {
1317
auth_data: {
1418
type: ConnectionType.HIVE;
1519
user: string;
20+
password?: string;
1621
};
1722
connection_data: {
1823
type: ConnectionType.HIVE;
@@ -24,6 +29,7 @@ interface ConnectionHdfs {
2429
auth_data: {
2530
type: ConnectionType.HDFS;
2631
user: string;
32+
password?: string;
2733
};
2834
connection_data: {
2935
type: ConnectionType.HDFS;
@@ -35,44 +41,45 @@ interface ConnectionOracle {
3541
auth_data: {
3642
type: ConnectionType.ORACLE;
3743
user: string;
44+
password?: string;
3845
};
3946
connection_data: {
4047
type: ConnectionType.ORACLE;
4148
host: string;
4249
port: number;
4350
service_name: string | null;
4451
sid: string | null;
45-
additional_params: object;
4652
};
4753
}
4854

4955
interface ConnectionPostgres {
5056
auth_data: {
5157
type: ConnectionType.POSTGRES;
5258
user: string;
59+
password?: string;
5360
};
5461
connection_data: {
5562
type: ConnectionType.POSTGRES;
5663
host: string;
5764
port: number;
5865
database_name: string;
59-
additional_params: object;
6066
};
6167
}
6268

6369
interface ConnectionS3 {
6470
auth_data: {
6571
type: ConnectionType.S3;
6672
access_key: string;
73+
secret_key?: string;
6774
};
6875
connection_data: {
6976
type: ConnectionType.S3;
7077
host: string;
7178
bucket: string;
72-
bucket_style: 'domain' | 'path';
79+
bucket_style: ConnectionBucketStyle;
7380
port: number | null;
7481
region: string | null;
75-
protocol: 'http' | 'https';
82+
protocol: ConnectionProtocol;
7683
};
7784
}
7885

@@ -83,3 +90,19 @@ export interface GetConnectionsRequest extends PaginationRequest {
8390
export interface GetConnectionRequest {
8491
id: number;
8592
}
93+
94+
export type CreateConnectionRequest = {
95+
group_id: number;
96+
name: string;
97+
description: string;
98+
} & ConnectionData;
99+
100+
export type UpdateConnectionRequest = {
101+
id: number;
102+
name: string;
103+
description: string;
104+
} & ConnectionData;
105+
106+
export interface DeleteConnectionRequest {
107+
id: number;
108+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { ConnectionType } from '@shared/types';
2+
import { prepareOptionsForSelect } from '@shared/ui';
3+
4+
import { ConnectionBucketStyle, ConnectionProtocol } from './api';
5+
6+
export const CONNECTION_TYPE_SELECT_OPTIONS = prepareOptionsForSelect<ConnectionType>({
7+
data: Object.values(ConnectionType),
8+
renderLabel: (data) => data,
9+
renderValue: (data) => data,
10+
});
11+
12+
export const CONNECTION_BUCKET_STYLE_SELECT_OPTIONS = prepareOptionsForSelect<ConnectionBucketStyle>({
13+
data: ['domain', 'path'],
14+
renderLabel: (data) => data,
15+
renderValue: (data) => data,
16+
});
17+
18+
export const CONNECTION_PROTOCOL_SELECT_OPTIONS = prepareOptionsForSelect<ConnectionProtocol>({
19+
data: ['https', 'http'],
20+
renderLabel: (data) => data,
21+
renderValue: (data) => data,
22+
});

src/entities/connection/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
export * from './api';
2+
export * from './constants';
3+
export * from './ui';

0 commit comments

Comments
 (0)