Skip to content

Commit 55bc5f2

Browse files
authored
Merge pull request #4 from nirupama-dev/config-error
Added config error page when project id or region is missing
2 parents 3d53142 + a2e5a73 commit 55bc5f2

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

scheduler_jupyter_plugin/credentials.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,7 @@ async def get_cached():
7676
# As such, we treat them being missing as a signal that there is
7777
# a problem with how the user is logged in to gcloud.
7878
credentials["login_error"] = 1
79+
elif not credentials["project_id"] or not credentials["region_id"]:
80+
credentials["config_error"] = 1
7981

8082
return credentials

src/scheduler/NotebookScheduler.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const NotebookSchedulerComponent = ({
7272
const abortControllerRef = useRef<any>(null);
7373
const [apiEnableUrl, setApiEnableUrl] = useState<any>(null);
7474
const [loginError, setLoginError] = useState<boolean>(false);
75+
const [configError, setConfigError] = useState<boolean>(false);
7576
const [isLoading, setIsLoading] = useState<boolean>(true);
7677
const [listingScreenFlag, setListingScreenFlag] = useState<boolean>(false);
7778
const [jobNameUniquenessError, setJobNameUniquenessError] =
@@ -100,7 +101,7 @@ const NotebookSchedulerComponent = ({
100101

101102
useEffect(() => {
102103
getKernelDetails();
103-
checkConfig(setLoginError, setIsLoading);
104+
checkConfig(setLoginError, setIsLoading, setConfigError);
104105
}, []);
105106

106107
const handleJobNameChange = (event: React.ChangeEvent<HTMLInputElement>) => {
@@ -167,11 +168,12 @@ const NotebookSchedulerComponent = ({
167168
/>
168169
Loading...
169170
</div>
170-
) : loginError && !isLoading ? (
171+
) : loginError || configError ? (
171172
<div className="login-error login-error-main">
172173
<LoginErrorComponent
173174
setLoginError={setLoginError}
174175
loginError={loginError}
176+
configError={configError}
175177
/>
176178
</div>
177179
) : (

src/utils/Config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,18 @@ export const authApi = async (
4444

4545
export const checkConfig = async (
4646
setLoginError: React.Dispatch<React.SetStateAction<boolean>>,
47-
setIsLoading: React.Dispatch<React.SetStateAction<boolean>>
47+
setIsLoading: React.Dispatch<React.SetStateAction<boolean>>,
48+
setConfigError: React.Dispatch<React.SetStateAction<boolean>>
4849
): Promise<void> => {
4950
const credentials: IAuthCredentials | undefined = await authApi();
5051
if (credentials) {
5152
if (credentials.login_error === 1) {
5253
setLoginError(true);
5354
setIsLoading(false);
5455
}
56+
if (credentials.config_error === 1) {
57+
setConfigError(true);
58+
}
5559
setIsLoading(false);
5660
}
5761
};
@@ -291,6 +295,7 @@ export const login = async (
291295
const loginStatus = (data as { login: string }).login;
292296
if (loginStatus === STATUS_SUCCESS) {
293297
setLoginError(false);
298+
window.location.reload();
294299
} else {
295300
setLoginError(true);
296301
}

src/utils/LoginErrorComponent.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,17 @@ import { IconsigninGoogle } from './Icons';
2222

2323
const LoginErrorComponent: React.FC<ILoginErrorProps> = ({
2424
loginError = false,
25-
setLoginError
25+
setLoginError,
26+
configError = false
2627
}) => {
28+
if (configError) {
29+
return (
30+
<div className="login-error">
31+
Please configure gcloud with account, project-id and region
32+
</div>
33+
);
34+
}
35+
2736
if (loginError) {
2837
return (
2938
<>

0 commit comments

Comments
 (0)