forked from kubeflow/hub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
130 lines (119 loc) · 3.58 KB
/
App.tsx
File metadata and controls
130 lines (119 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import * as React from 'react';
import '@patternfly/react-core/dist/styles/base.css';
import './app.css';
import {
Alert,
Bullseye,
Button,
Page,
PageSection,
PageSidebar,
Spinner,
Stack,
StackItem,
} from '@patternfly/react-core';
import ToastNotifications from '~/shared/components/ToastNotifications';
import { useSettings } from '~/shared/hooks/useSettings';
import { AUTH_HEADER, MOCK_AUTH, isStandalone } from '~/shared/utilities/const';
import { logout } from '~/shared/utilities/appUtils';
import { NamespaceSelectorContext } from '~/shared/context/NamespaceSelectorContext';
import NavSidebar from './NavSidebar';
import AppRoutes from './AppRoutes';
import { AppContext } from './AppContext';
import { ModelRegistrySelectorContextProvider } from './context/ModelRegistrySelectorContext';
import NavBar from './NavBar';
const App: React.FC = () => {
const {
configSettings,
userSettings,
loaded: configLoaded,
loadError: configError,
} = useSettings();
const { namespacesLoaded, namespacesLoadError, initializationError } =
React.useContext(NamespaceSelectorContext);
const username = userSettings?.userId;
React.useEffect(() => {
if (MOCK_AUTH && username) {
localStorage.setItem(AUTH_HEADER, username);
} else {
localStorage.removeItem(AUTH_HEADER);
}
}, [username]);
const contextValue = React.useMemo(
() =>
configSettings && userSettings
? {
config: configSettings!,
user: userSettings!,
}
: null,
[configSettings, userSettings],
);
const error = configError || namespacesLoadError || initializationError;
const sidebar = <PageSidebar isSidebarOpen={false} />;
// We lack the critical data to startup the app
if (error) {
// There was an error fetching critical data
return (
<Page sidebar={sidebar}>
<PageSection>
<Stack hasGutter>
<StackItem>
<Alert variant="danger" isInline title="General loading error">
<p>
{configError?.message ||
namespacesLoadError?.message ||
initializationError?.message ||
'Unknown error occurred during startup'}
</p>
<p>Logging out and logging back in may solve the issue</p>
</Alert>
</StackItem>
<StackItem>
<Button
variant="secondary"
onClick={() => logout().then(() => window.location.reload())}
>
Logout
</Button>
</StackItem>
</Stack>
</PageSection>
</Page>
);
}
// Waiting on the API to finish
const loading =
!configLoaded || !userSettings || !configSettings || !contextValue || !namespacesLoaded;
return loading ? (
<Bullseye>
<Spinner />
</Bullseye>
) : (
<AppContext.Provider value={contextValue}>
<Page
mainContainerId="primary-app-container"
masthead={
isStandalone() ? (
<NavBar
username={username}
onLogout={() => {
logout().then(() => window.location.reload());
}}
/>
) : (
''
)
}
isManagedSidebar={isStandalone()}
sidebar={isStandalone() ? <NavSidebar /> : sidebar}
>
<ModelRegistrySelectorContextProvider>
<AppRoutes />
</ModelRegistrySelectorContextProvider>
<ToastNotifications />
</Page>
</AppContext.Provider>
);
};
export default App;