Skip to content

Commit

Permalink
fix: add hook dependencies and ensure fetchSuperSetBaseUrl is a stabl…
Browse files Browse the repository at this point in the history
…e reference
  • Loading branch information
HendrikThePendric committed Jan 13, 2025
1 parent 4bd13e9 commit f2402c5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
23 changes: 15 additions & 8 deletions src/api/superSetGateway.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import { useConfig } from '@dhis2/app-service-config'
import { useCallback, useMemo } from 'react'

export const useFetchSuperSetBaseUrl = () => {
const { baseUrl } = useConfig()
const url = new URL(
'superset-gateway/api/info',
baseUrl === '..'
? window.location.href.split('dhis-web-dashboard/')[0]
: `${baseUrl}/`
)?.href
const url = useMemo(
() =>
new URL(
'superset-gateway/api/info',
baseUrl === '..'
? window.location.href.split('dhis-web-dashboard/')[0]
: `${baseUrl}/`
)?.href,
[baseUrl]
)

return async () => {
const fetchSuperSetBaseUrl = useCallback(async () => {
const response = await fetch(url)
if (!response.ok) {
throw new Error(`Response status: ${response.status}`)
}

const data = await response.json()
return data.supersetBaseUrl
}
}, [url])

return fetchSuperSetBaseUrl
}
2 changes: 1 addition & 1 deletion src/components/SystemSettingsProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const SystemSettingsProvider = ({ children }) => {
setSettings(resolvedSystemSettings)
}
fetchData()
}, [])
}, [engine, fetchSuperSetBaseUrl])

return (
<SystemSettingsCtx.Provider
Expand Down

0 comments on commit f2402c5

Please sign in to comment.