Skip to content

Commit 9c80372

Browse files
committed
refactor(FR-2628): rename useEduAppApiEndpoint to useResolvedApiEndpoint (#6850)
Resolves FR-2628 (sub-task of Epic [FR-2616](https://lablup.atlassian.net/browse/FR-2616)) resolves #NNN (FR-MMM) <!-- replace NNN, MMM with the GitHub issue number and the corresponding Jira issue number. --> <!-- Please precisely, concisely, and concretely describe what this PR changes, the rationale behind codes, and how it affects the users and other developers. --> **Checklist:** (if applicable) - [ ] Documentation - [ ] Minium required manager version - [ ] Specific setting for review (eg., KB link, endpoint or how to setup) - [ ] Minimum requirements to check during review - [ ] Test case(s) to demonstrate the difference of before/after ## Stack This PR is part of the Story 1 stack for Epic FR-2616 (Extract sToken login flow into reusable boundary component). See the [dev plan](../blob/main/.specs/draft-stoken-login-boundary/dev-plan.md) for the full scope. The Story 1 PR stack is #6850#6851#6852#6853#6854#6855#6856 on top of spec PR #6828. [FR-2616]: https://lablup.atlassian.net/browse/FR-2616?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent ce58ca6 commit 9c80372

3 files changed

Lines changed: 16 additions & 21 deletions

File tree

react/src/components/EduAppLauncher.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ const EduAppLauncher: React.FC<EduAppLauncherProps> = ({
167167
* Initialize the backend.ai client with session-based auth mode.
168168
*
169169
* The caller (`EduAppLauncherPage`) is responsible for providing a
170-
* non-empty endpoint via `useEduAppApiEndpoint()`, which reads from
170+
* non-empty endpoint via `useResolvedApiEndpoint()`, which reads from
171171
* `config.toml` and suspends until resolved. If the endpoint is still
172172
* empty here, client initialization will be rejected and the outer
173173
* catch in `_launch` will surface the error via notification.
Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,26 @@
55
import { fetchAndParseConfig } from './useWebUIConfig';
66

77
/**
8-
* Resolve the Backend.AI API endpoint for the EduAppLauncher page.
8+
* Resolve the Backend.AI API endpoint from `config.toml` and fallbacks.
99
*
10-
* Unlike the main app flow, the EduAppLauncher page is entered via a token URL
11-
* and never goes through `LoginView` or `useInitializeConfig`. As a result,
12-
* neither `localStorage('backendaiwebui.api_endpoint')` nor the `loginConfigState`
13-
* atom are populated, and the shared `useApiEndpoint()` hook returns an empty
14-
* string.
15-
*
16-
* This hook resolves the endpoint from `config.toml` directly (the same file
17-
* `LoginView` would have parsed), with the existing sources kept as fallbacks
18-
* for any rare pre-populated case. It is intentionally scoped to the Edu page
19-
* only; see FR-2483 for rationale (other independent pages may share the
20-
* pattern but a broader `useApiEndpoint` refactor is explicitly out of scope).
10+
* Intended for pages and components that are entered outside of the normal
11+
* `LoginView` → `useInitializeConfig` flow (e.g. token URL entry points like
12+
* `EduAppLauncher` or the sToken login boundary) where neither
13+
* `localStorage('backendaiwebui.api_endpoint')` nor the `loginConfigState`
14+
* atom have been populated yet. The shared `useApiEndpoint()` hook would
15+
* return an empty string in those cases.
2116
*
2217
* Resolution order:
2318
* 1. `config.toml` → `general.apiEndpoint`
2419
* 2. `localStorage('backendaiwebui.api_endpoint')`
25-
* 3. Empty string (the page should display an error in this case)
20+
* 3. Empty string (the caller should display an error in this case)
2621
*
2722
* Implementation note: this function suspends by throwing a promise so the
2823
* caller can gate rendering with `<Suspense>` until endpoint resolution
29-
* completes. By the time `EduAppLauncher` mounts, the hook returns the
30-
* resolved endpoint string, which may still be an empty string if every
24+
* completes. The resolved value may still be an empty string if every
3125
* fallback source is unavailable — downstream code is responsible for
32-
* surfacing that failure (for example, via an error notification).
26+
* surfacing that failure (for example, via an error notification or an
27+
* `endpoint-unresolved` error state).
3328
*/
3429

3530
let cachedEndpoint: string | null = null;
@@ -62,7 +57,7 @@ const resolveEndpoint = async (): Promise<string> => {
6257
* Throws a promise on first call so the component tree suspends until the
6358
* config.toml fetch completes; subsequent calls return the cached value.
6459
*/
65-
export const useEduAppApiEndpoint = (): string => {
60+
export const useResolvedApiEndpoint = (): string => {
6661
if (cachedEndpoint !== null) {
6762
return cachedEndpoint;
6863
}

react/src/pages/EduAppLauncherPage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Copyright (c) 2015-2026 Lablup Inc. All rights reserved.
44
*/
55
import { CSSTokenVariables } from '../components/MainLayout/MainLayout';
6-
import { useEduAppApiEndpoint } from '../hooks/useEduAppApiEndpoint';
6+
import { useResolvedApiEndpoint } from '../hooks/useResolvedApiEndpoint';
77
import React, { Suspense } from 'react';
88

99
const EduAppLauncherLazy = React.lazy(
@@ -16,7 +16,7 @@ const EduAppLauncherLazy = React.lazy(
1616
*
1717
* Because this page is entered via a token URL and never goes through
1818
* LoginView, it resolves the API endpoint directly from `config.toml`
19-
* via `useEduAppApiEndpoint()`. The Suspense boundary below gates
19+
* via `useResolvedApiEndpoint()`. The Suspense boundary below gates
2020
* EduAppLauncher rendering until endpoint resolution completes; the
2121
* resolved value may still be an empty string if every fallback source
2222
* is unavailable, in which case `EduAppLauncher._initClient` throws and
@@ -43,7 +43,7 @@ const EduAppLauncherPage: React.FC = () => {
4343

4444
const EduAppLauncherPageContent: React.FC = () => {
4545
'use memo';
46-
const apiEndpoint = useEduAppApiEndpoint();
46+
const apiEndpoint = useResolvedApiEndpoint();
4747

4848
return <EduAppLauncherLazy apiEndpoint={apiEndpoint} active={true} />;
4949
};

0 commit comments

Comments
 (0)