forked from kubeflow/model-registry
-
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.
Signed-off-by: lucferbux <[email protected]>
- Loading branch information
Showing
5 changed files
with
91 additions
and
11 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
58 changes: 58 additions & 0 deletions
58
clients/ui/frontend/src/shared/context/DashboardScriptLoader.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,58 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { isIntegrated } from '../utilities/const'; | ||
import { Bullseye, Spinner } from '@patternfly/react-core'; | ||
|
||
type DashboardScriptLoaderProps = { | ||
children: React.ReactNode; | ||
}; | ||
|
||
const loadScript = (src: string, onLoad: () => void, onError: () => void) => { | ||
const script = document.createElement('script'); | ||
script.src = src; | ||
script.async = true; | ||
script.onload = onLoad; | ||
script.onerror = onError; | ||
document.head.appendChild(script); | ||
}; | ||
|
||
/* eslint-disable no-console */ | ||
const DashboardScriptLoader: React.FC<DashboardScriptLoaderProps> = ({ children }) => { | ||
const [scriptLoaded, setScriptLoaded] = useState(false); | ||
|
||
useEffect(() => { | ||
const scriptUrl = '/dashboard_lib.bundle.js'; | ||
|
||
if (!isIntegrated()) { | ||
console.warn( | ||
'DashboardScriptLoader: Script not loaded because deployment mode is not integrated', | ||
); | ||
setScriptLoaded(true); | ||
return; | ||
} | ||
|
||
fetch(scriptUrl, { method: 'HEAD' }) | ||
.then((response) => { | ||
if (response.ok) { | ||
loadScript( | ||
scriptUrl, | ||
() => setScriptLoaded(true), | ||
() => console.error('Failed to load the script'), | ||
); | ||
} else { | ||
console.warn('Script not found'); | ||
} | ||
}) | ||
.catch((error) => console.error('Error checking script existence', error)) | ||
.finally(() => setScriptLoaded(true)); | ||
}, []); | ||
|
||
return !scriptLoaded ? ( | ||
<Bullseye> | ||
<Spinner /> | ||
</Bullseye> | ||
) : ( | ||
<>{children}</> | ||
); | ||
}; | ||
|
||
export default DashboardScriptLoader; |
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
4 changes: 1 addition & 3 deletions
4
clients/ui/frontend/src/shared/hooks/useQueryParamNamespaces.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