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 62feb924 fix: move setAllConnections to the right statement (#2889)
62feb924 is described below
commit 62feb924e61910a6b966f8787e4a53d932f5f0bf
Author: likyh <[email protected]>
AuthorDate: Wed Aug 31 20:46:47 2022 +0800
fix: move setAllConnections to the right statement (#2889)
* fix: move setAllConnections to right statement
* fix: fix for review
Co-authored-by: linyh <[email protected]>
---
config-ui/src/hooks/useConnectionManager.jsx | 45 +++++++++++++---------------
1 file changed, 20 insertions(+), 25 deletions(-)
diff --git a/config-ui/src/hooks/useConnectionManager.jsx
b/config-ui/src/hooks/useConnectionManager.jsx
index 19f21557..4633118e 100644
--- a/config-ui/src/hooks/useConnectionManager.jsx
+++ b/config-ui/src/hooks/useConnectionManager.jsx
@@ -72,8 +72,11 @@ function useConnectionManager (
const [allProviderConnections, setAllProviderConnections] = useState([])
const [domainRepositories, setDomainRepositories] = useState([])
const [testedConnections, setTestedConnections] = useState([])
- const [connectionCount, setConnectionCount] = useState(0)
- const [connectionLimitReached, setConnectionLimitReached] = useState(false)
+ const connectionCount = useMemo(() => allConnections.length,
[allConnections])
+ const connectionLimitReached = useMemo(() =>
+ sourceLimits[provider?.id] && connectionCount >= sourceLimits[provider.id],
+ [/*provider?.id, */sourceLimits, connectionCount],
+ )
const [connectionsList, setConnectionsList] = useState([])
@@ -403,22 +406,22 @@ function useConnectionManager (
c = await request.get(
`${DEVLAKE_ENDPOINT}/plugins/${provider.id}/connections`
)
+ console.log('>> RAW ALL CONNECTIONS DATA FROM API...', c?.data)
+ const providerConnections = []
+ .concat(Array.isArray(c?.data) ? c?.data : [])
+ .map((conn, idx) => {
+ return {
+ ...conn,
+ status: ConnectionStatus.OFFLINE,
+ ID: conn.ID || conn.id,
+ id: conn.id,
+ name: conn.name,
+ endpoint: conn.endpoint,
+ errors: [],
+ }
+ })
+ setAllConnections(providerConnections)
}
-
- console.log('>> RAW ALL CONNECTIONS DATA FROM API...', c?.data)
- const providerConnections = []
- .concat(Array.isArray(c?.data) ? c?.data : [])
- .map((conn, idx) => {
- return {
- ...conn,
- status: ConnectionStatus.OFFLINE,
- ID: conn.ID || conn.id,
- id: conn.id,
- name: conn.name,
- endpoint: conn.endpoint,
- errors: [],
- }
- })
if (notify) {
ToastNotification.show({
message: 'Loaded all connections.',
@@ -426,12 +429,6 @@ function useConnectionManager (
icon: 'small-tick',
})
}
- setAllConnections(providerConnections)
- setConnectionCount(c?.data?.length)
- setConnectionLimitReached(
- sourceLimits[provider.id] &&
- c.data?.length >= sourceLimits[provider.id]
- )
setIsFetching(false)
} catch (e) {
console.log('>> FAILED TO FETCH ALL CONNECTIONS', e)
@@ -442,8 +439,6 @@ function useConnectionManager (
})
setIsFetching(false)
setAllConnections([])
- setConnectionCount(0)
- setConnectionLimitReached(false)
setErrors([e.message])
handleOfflineMode(e.response?.status, e.response)
}