refactor(FR-2493): centralize resource slot metadata into BAIMetaDataProvider#6668
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has required the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
Coverage report for
|
St.❔ |
Category | Percentage | Covered / Total |
|---|---|---|---|
| 🟢 | Statements | 81.87% | 429/524 |
| 🟡 | Branches | 70.43% | 362/514 |
| 🟡 | Functions | 76.86% | 93/121 |
| 🟢 | Lines | 83.19% | 391/470 |
Test suite run success
319 tests passing in 13 suites.
Report generated by 🧪jest coverage report action from 8908c4f
Coverage report for
|
St.❔ |
Category | Percentage | Covered / Total |
|---|---|---|---|
| 🔴 | Statements | 8.87% (+0% 🔼) |
1736/19573 |
| 🔴 | Branches | 8.03% (-0% 🔻) |
1097/13653 |
| 🔴 | Functions | 5.31% | 283/5328 |
| 🔴 | Lines | 8.56% (+0% 🔼) |
1628/19012 |
Show files with reduced coverage 🔻
St.❔ |
File | Statements | Branches | Functions | Lines |
|---|---|---|---|---|---|
| 🔴 | hooks/backendai.tsx | 11.11% (-0.16% 🔻) |
0% | 0% | 11.39% (-0.2% 🔻) |
Test suite run success
847 tests passing in 38 suites.
Report generated by 🧪jest coverage report action from 8908c4f
c73d14e to
1a40886
Compare
1a40886 to
f68f5f1
Compare
There was a problem hiding this comment.
Pull request overview
This PR centralizes resource slot/device metadata handling by moving the “resource slot details” fetch/merge logic into the WebUI side and exposing the consolidated result to Backend.AI UI (BUI) components via BAIMetaDataProvider + useBAIMetaData(). It also relocates the image fallback component into the shared UI package and updates multiple WebUI components to use the new hook source.
Changes:
- Added a WebUI-side
useResourceSlotsDetails()hook that fetches/config/resource-slots/detailsand merges it withresources/device_metadata.json. - Updated provider wiring so BUI reads metadata via
BAIMetaDataProvider+useBAIMetaData(), and movedBAIMetaDataWrappertoMainLayoutto avoid blocking the login screen. - Moved
ImageWithFallbackintobackend.ai-uiasBAIImageWithFallbackand updated resource-icon rendering to support SVG fallback for server-configured icons.
Reviewed changes
Copilot reviewed 36 out of 36 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| react/src/hooks/backendai.tsx | Adds WebUI useResourceSlotsDetails() that fetches server slot details and merges with static metadata. |
| react/src/components/DefaultProviders.tsx | Refactors BAIMetaDataWrapper to populate BAIMetaDataProvider with unified metadata fields; removes wrapper from root providers. |
| react/src/components/MainLayout/MainLayout.tsx | Wraps routed content with BAIMetaDataWrapper to avoid login-screen blocking. |
| react/src/components/*.tsx (multiple) | Switches imports to use WebUI useResourceSlotsDetails() and updates icon rendering to use BAIImageWithFallback. |
| react/src/components/MyResourceWithinResourceGroup.test.tsx | Updates mocks to reflect the hook import move from BUI to WebUI. |
| packages/backend.ai-ui/src/hooks/index.ts | Removes duplicate useResourceSlotsDetails export; re-exports useBAIMetaData. |
| packages/backend.ai-ui/src/components/provider/BAIMetaDataProvider/* | Expands provider/context to carry device metadata + resource slot details + merged result + refresh/loading, and introduces useBAIMetaData. |
| packages/backend.ai-ui/src/components/BAIResourceNumberWithIcon.tsx | Updates to read merged metadata from context and adds SVG fallback icon loading via BAIImageWithFallback. |
| packages/backend.ai-ui/src/components/BAIImageWithFallback.tsx | Introduces shared BAIImageWithFallback component in BUI. |
| .github/instructions/react.instructions.md | Updates guidance to require 'use memo' for components and custom hooks. |
| .claude/rules/use-memo-directive.md | Adds a repo rule enforcing 'use memo' on components and custom hooks across WebUI and BUI. |
Comments suppressed due to low confidence (2)
packages/backend.ai-ui/src/components/BAIImageWithFallback.tsx:30
hasErroris never reset whensrcchanges. If the firstsrcfails to load and later a different (valid)srcis provided, the component will remain stuck on the fallback. Consider resettinghasErrortofalsein an effect whensrcchanges.
packages/backend.ai-ui/src/components/BAIImageWithFallback.tsx:23BAIImageWithFallbackis a (newly introduced/relocated) component but it’s missing the required'use memo'directive. Add'use memo';as the first statement in the component body (before any hooks likeuseState).
f68f5f1 to
2f7f42a
Compare
…Provider - Move useResourceSlotsDetails API call from BUI to webui, populate BAIMetaDataProvider context - Add unified useBAIMetaData() hook in BUI returning deviceMetaData, resourceSlotsInRG, mergedResourceSlots, refresh, isLoading - Move ImageWithFallback from webui to BUI as BAIImageWithFallback - Fix BAIResourceNumberWithIcon to handle server-configured icons via SVG fallback - Move BAIMetaDataWrapper from DefaultProvidersForReactRoot to MainLayout (wraps only Outlet) - Update 16 webui components to import useResourceSlotsDetails from src/hooks/backendai - Remove duplicate useResourceSlotsDetails from BUI hooks/index.ts
2f7f42a to
8908c4f
Compare
|
Addressed the two suppressed Copilot comments for
|

Resolves #6484 (FR-2493)
Summary
BAIMetaDataProvidercontextuseResourceSlotsDetailsAPI call from BUI to webui, with BUI components reading from context viauseBAIMetaData()hookuseBAIMetaData()hook returningdeviceMetaData,resourceSlotsInRG,mergedResourceSlots,refresh,isLoadingImageWithFallbackfrom webui to BUI asBAIImageWithFallbackBAIResourceNumberWithIconto handle server-configured icons via SVG fallbackBAIMetaDataWrapperfromDefaultProvidersForReactRoottoMainLayout(wraps only<Outlet />) to prevent login screen blockinguseResourceSlotsDetailsfromsrc/hooks/backendaiuseResourceSlotsDetailsfrom BUIhooks/index.tsTest plan