-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DOP-20046] create update delete connection
- Loading branch information
Zabilsya
committed
Dec 3, 2024
1 parent
eb76bb0
commit f759056
Showing
74 changed files
with
1,091 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './useGetConnection'; | ||
export * from './useDeleteConnection'; |
25 changes: 25 additions & 0 deletions
25
src/entities/connection/api/hooks/useDeleteConnection/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useMutation, UseMutationResult, useQueryClient } from '@tanstack/react-query'; | ||
import { notification } from 'antd'; | ||
import { getErrorMessage } from '@shared/config'; | ||
|
||
import { connectionService } from '../../connectionService'; | ||
import { DeleteConnectionRequest } from '../../types'; | ||
import { ConnectionQueryKey } from '../../keys'; | ||
|
||
/** Hook for deleting connection */ | ||
export const useDeleteConnection = (data: DeleteConnectionRequest): UseMutationResult => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: () => connectionService.deleteConnection(data), | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: [ConnectionQueryKey.GET_CONNECTIONS] }); | ||
queryClient.removeQueries({ queryKey: [ConnectionQueryKey.GET_CONNECTION, data.id] }); | ||
}, | ||
onError: (error) => { | ||
notification.error({ | ||
message: getErrorMessage(error), | ||
}); | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ConnectionType } from '@shared/types'; | ||
import { prepareOptionsForSelect } from '@shared/ui'; | ||
|
||
import { ConnectionBucketStyle, ConnectionProtocol } from './api'; | ||
|
||
export const CONNECTION_TYPE_SELECT_OPTIONS = prepareOptionsForSelect<ConnectionType>({ | ||
data: Object.values(ConnectionType), | ||
renderLabel: (data) => data, | ||
renderValue: (data) => data, | ||
}); | ||
|
||
export const CONNECTION_BUCKET_STYLE_SELECT_OPTIONS = prepareOptionsForSelect<ConnectionBucketStyle>({ | ||
data: ['domain', 'path'], | ||
renderLabel: (data) => data, | ||
renderValue: (data) => data, | ||
}); | ||
|
||
export const CONNECTION_PROTOCOL_SELECT_OPTIONS = prepareOptionsForSelect<ConnectionProtocol>({ | ||
data: ['https', 'http'], | ||
renderLabel: (data) => data, | ||
renderValue: (data) => data, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export * from './api'; | ||
export * from './constants'; | ||
export * from './ui'; |
22 changes: 22 additions & 0 deletions
22
src/entities/connection/ui/ConnectionTypeForm/components/ConnectionHdfs/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
import { Form, Input } from 'antd'; | ||
|
||
import { useSensitiveFields } from '../../hooks'; | ||
|
||
export const ConnectionHdfs = () => { | ||
const { isRequired } = useSensitiveFields(); | ||
|
||
return ( | ||
<> | ||
<Form.Item label="Cluster" name="cluster" rules={[{ required: true }]}> | ||
<Input size="large" /> | ||
</Form.Item> | ||
<Form.Item label="User" name="user" rules={[{ required: true }]}> | ||
<Input size="large" /> | ||
</Form.Item> | ||
<Form.Item label="Password" name="password" rules={[{ required: isRequired }]}> | ||
<Input.Password size="large" /> | ||
</Form.Item> | ||
</> | ||
); | ||
}; |
22 changes: 22 additions & 0 deletions
22
src/entities/connection/ui/ConnectionTypeForm/components/ConnectionHive/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
import { Form, Input } from 'antd'; | ||
|
||
import { useSensitiveFields } from '../../hooks'; | ||
|
||
export const ConnectionHive = () => { | ||
const { isRequired } = useSensitiveFields(); | ||
|
||
return ( | ||
<> | ||
<Form.Item label="Cluster" name="cluster" rules={[{ required: true }]}> | ||
<Input size="large" /> | ||
</Form.Item> | ||
<Form.Item label="User" name="user" rules={[{ required: true }]}> | ||
<Input size="large" /> | ||
</Form.Item> | ||
<Form.Item label="Password" name="password" rules={[{ required: isRequired }]}> | ||
<Input.Password size="large" /> | ||
</Form.Item> | ||
</> | ||
); | ||
}; |
71 changes: 71 additions & 0 deletions
71
src/entities/connection/ui/ConnectionTypeForm/components/ConnectionOracle/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React, { useCallback, useEffect, useState } from 'react'; | ||
import { Form, Input, InputNumber } from 'antd'; | ||
|
||
import { useSensitiveFields } from '../../hooks'; | ||
import { MAX_ALLOWED_PORT, MIN_ALLOWED_PORT } from '../../constants'; | ||
|
||
export const ConnectionOracle = () => { | ||
const { isRequired } = useSensitiveFields(); | ||
const form = Form.useFormInstance(); | ||
|
||
const [isServiceNameDisabled, setServiceNameDisabled] = useState(false); | ||
const [isSidDisabled, setSidDisabled] = useState(false); | ||
|
||
const changeDisabledFields = useCallback(() => { | ||
const serviceName = form.getFieldValue('service_name'); | ||
const sid = form.getFieldValue('sid'); | ||
setServiceNameDisabled(!!sid); | ||
setSidDisabled(!!serviceName); | ||
}, [form]); | ||
|
||
const handleFieldChange = () => { | ||
changeDisabledFields(); | ||
form.validateFields(['service_name', 'sid']); | ||
}; | ||
|
||
//* It needs to validate required fields service_name and sid correctly if they have initial values | ||
useEffect(() => { | ||
changeDisabledFields(); | ||
}, [changeDisabledFields]); | ||
|
||
return ( | ||
<> | ||
<Form.Item label="Host" name="host" rules={[{ required: true }]}> | ||
<Input size="large" /> | ||
</Form.Item> | ||
<Form.Item label="Port" name="port" rules={[{ required: true }]}> | ||
<InputNumber size="large" min={MIN_ALLOWED_PORT} max={MAX_ALLOWED_PORT} /> | ||
</Form.Item> | ||
<Form.Item | ||
label="Service name" | ||
name="service_name" | ||
rules={[ | ||
{ | ||
required: !isServiceNameDisabled, | ||
message: 'Either Service name or Sid is required', | ||
}, | ||
]} | ||
> | ||
<Input size="large" disabled={isServiceNameDisabled} onChange={handleFieldChange} /> | ||
</Form.Item> | ||
<Form.Item | ||
label="Sid" | ||
name="sid" | ||
rules={[ | ||
{ | ||
required: !isSidDisabled, | ||
message: 'Either Service name or Sid is required', | ||
}, | ||
]} | ||
> | ||
<Input size="large" disabled={isSidDisabled} onChange={handleFieldChange} /> | ||
</Form.Item> | ||
<Form.Item label="User" name="user" rules={[{ required: true }]}> | ||
<Input size="large" /> | ||
</Form.Item> | ||
<Form.Item label="Password" name="password" rules={[{ required: isRequired }]}> | ||
<Input.Password size="large" /> | ||
</Form.Item> | ||
</> | ||
); | ||
}; |
29 changes: 29 additions & 0 deletions
29
src/entities/connection/ui/ConnectionTypeForm/components/ConnectionPostgres/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import { Form, Input, InputNumber } from 'antd'; | ||
|
||
import { useSensitiveFields } from '../../hooks'; | ||
import { MAX_ALLOWED_PORT, MIN_ALLOWED_PORT } from '../../constants'; | ||
|
||
export const ConnectionPostgres = () => { | ||
const { isRequired } = useSensitiveFields(); | ||
|
||
return ( | ||
<> | ||
<Form.Item label="Database name" name="database_name" rules={[{ required: true }]}> | ||
<Input size="large" /> | ||
</Form.Item> | ||
<Form.Item label="Host" name="host" rules={[{ required: true }]}> | ||
<Input size="large" /> | ||
</Form.Item> | ||
<Form.Item label="Port" name="port" rules={[{ required: true }]}> | ||
<InputNumber size="large" min={MIN_ALLOWED_PORT} max={MAX_ALLOWED_PORT} /> | ||
</Form.Item> | ||
<Form.Item label="User" name="user" rules={[{ required: true }]}> | ||
<Input size="large" /> | ||
</Form.Item> | ||
<Form.Item label="Password" name="password" rules={[{ required: isRequired }]}> | ||
<Input.Password size="large" /> | ||
</Form.Item> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.