-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add hook dependencies and ensure fetchSuperSetBaseUrl is a stabl…
…e reference
- Loading branch information
1 parent
4bd13e9
commit f2402c5
Showing
2 changed files
with
16 additions
and
9 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
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 | ||
} |
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