This is an automated email from the ASF dual-hosted git repository.
likyh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new 8f13d200e fix(config-ui): add retry test connection on bp create
(#3994)
8f13d200e is described below
commit 8f13d200e0dc91a664c87a1ac6ea4ab2c0017520
Author: 青湛 <[email protected]>
AuthorDate: Wed Dec 21 14:36:40 2022 +0800
fix(config-ui): add retry test connection on bp create (#3994)
---
.../src/pages/blueprint/create/step-one/index.tsx | 16 +++-
config-ui/src/store/connections/context.tsx | 2 +-
config-ui/src/store/connections/types.ts | 1 -
.../src/store/connections/use-context-value.ts | 89 +++++++++-------------
4 files changed, 51 insertions(+), 57 deletions(-)
diff --git a/config-ui/src/pages/blueprint/create/step-one/index.tsx
b/config-ui/src/pages/blueprint/create/step-one/index.tsx
index 6506c4360..891f8107e 100644
--- a/config-ui/src/pages/blueprint/create/step-one/index.tsx
+++ b/config-ui/src/pages/blueprint/create/step-one/index.tsx
@@ -17,9 +17,9 @@
*/
import React from 'react'
-import { InputGroup } from '@blueprintjs/core'
+import { InputGroup, Icon } from '@blueprintjs/core'
-import { useConnection } from '@/store'
+import { useConnection, ConnectionStatusEnum } from '@/store'
import { Card, Divider, MultiSelector, Loading } from '@/components'
import { ModeEnum } from '../../types'
@@ -75,7 +75,7 @@ export const StepOne = () => {
uniqueList.includes(cs.unique)
)}
onChangeItems={(selectedItems) => {
- onTest(selectedItems)
+ onTest(selectedItems[selectedItems.length - 1])
onChangeUniqueList(selectedItems.map((sc) => sc.unique))
}}
/>
@@ -86,9 +86,17 @@ export const StepOne = () => {
<li key={cs.unique}>
<span className='name'>{cs.name}</span>
<span className={`status ${cs.status}`}>
- {cs.status === 'testing' && (
+ {cs.status === ConnectionStatusEnum.TESTING && (
<Loading size={14} style={{ marginRight: 4 }} />
)}
+ {cs.status === ConnectionStatusEnum.OFFLINE && (
+ <Icon
+ size={14}
+ icon='repeat'
+ style={{ marginRight: 4, cursor: 'pointer' }}
+ onClick={() => onTest(cs)}
+ />
+ )}
{cs.status}
</span>
</li>
diff --git a/config-ui/src/store/connections/context.tsx
b/config-ui/src/store/connections/context.tsx
index 1e70c95c6..b29743460 100644
--- a/config-ui/src/store/connections/context.tsx
+++ b/config-ui/src/store/connections/context.tsx
@@ -27,7 +27,7 @@ import { useContextValue } from './use-context-value'
const ConnectionContext = React.createContext<{
connections: ConnectionItemType[]
onRefresh: () => void
- onTest: (selectedConnections: ConnectionItemType[]) => void
+ onTest: (selectedConnection: ConnectionItemType) => void
}>({
connections: [],
onRefresh: () => {},
diff --git a/config-ui/src/store/connections/types.ts
b/config-ui/src/store/connections/types.ts
index b43613121..db1bf73e9 100644
--- a/config-ui/src/store/connections/types.ts
+++ b/config-ui/src/store/connections/types.ts
@@ -21,7 +21,6 @@ import { Plugins } from '@/plugins'
export enum ConnectionStatusEnum {
ONLINE = 'online',
OFFLINE = 'offline',
- WAITING = 'waiting',
TESTING = 'testing',
NULL = 'null'
}
diff --git a/config-ui/src/store/connections/use-context-value.ts
b/config-ui/src/store/connections/use-context-value.ts
index 0b5396292..91be622c7 100644
--- a/config-ui/src/store/connections/use-context-value.ts
+++ b/config-ui/src/store/connections/use-context-value.ts
@@ -89,61 +89,48 @@ export const useContextValue = (plugins: string[]) => {
}, [])
const handleTest = useCallback(
- async (selectedConnections: ConnectionItemType[]) => {
- const uniqueList = selectedConnections.map((cs) => cs.unique)
-
- const initConnections = connections.map((cs) =>
- uniqueList.includes(cs.unique) &&
- cs.status === ConnectionStatusEnum.NULL
- ? {
- ...cs,
- status: ConnectionStatusEnum.WAITING
- }
- : cs
+ async (selectedConnection: ConnectionItemType) => {
+ setConnections((connections) =>
+ connections.map((cs) =>
+ cs.unique === selectedConnection.unique
+ ? {
+ ...cs,
+ status: ConnectionStatusEnum.TESTING
+ }
+ : cs
+ )
)
- setConnections(initConnections)
-
- const [updatedConnection] = await Promise.all(
- initConnections
- .filter((cs) => cs.status === ConnectionStatusEnum.WAITING)
- .map(async (cs) => {
- setConnections(
- initConnections.map((it) =>
- it.unique === cs.unique
- ? { ...it, status: ConnectionStatusEnum.TESTING }
- : it
- )
- )
- const { plugin, endpoint, proxy, token, username, password } = cs
- let status
-
- try {
- const res = await API.testConnection(plugin, {
- endpoint,
- proxy,
- token,
- username,
- password
- })
- status = res.success
- ? ConnectionStatusEnum.ONLINE
- : ConnectionStatusEnum.OFFLINE
- } catch {
- status = ConnectionStatusEnum.OFFLINE
- }
-
- return { ...cs, status }
- })
- )
+ const { plugin, endpoint, proxy, token, username, password } =
+ selectedConnection
+
+ let status = ConnectionStatusEnum.OFFLINE
+
+ try {
+ const res = await API.testConnection(plugin, {
+ endpoint,
+ proxy,
+ token,
+ username,
+ password
+ })
+ status = res.success
+ ? ConnectionStatusEnum.ONLINE
+ : ConnectionStatusEnum.OFFLINE
+ } catch {
+ status = ConnectionStatusEnum.OFFLINE
+ }
- if (updatedConnection) {
- setConnections((connections) =>
- connections.map((cs) =>
- cs.unique === updatedConnection.unique ? updatedConnection : cs
- )
+ setConnections((connections) =>
+ connections.map((cs) =>
+ cs.unique === selectedConnection.unique
+ ? {
+ ...cs,
+ status
+ }
+ : cs
)
- }
+ )
},
[connections]
)