-
Notifications
You must be signed in to change notification settings - Fork 78
refactor(FR-2493): centralize resource slot metadata into BAIMetaDataProvider #6668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nowgnuesLee
wants to merge
1
commit into
main
Choose a base branch
from
04-14-refactor_fr-2493_centralize_resource_slot_metadata_into_baimetadataprovider
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,46 @@ | ||
| --- | ||
| description: When writing or editing React components or custom hooks | ||
| paths: | ||
| - "react/**/*.{tsx,ts}" | ||
| - "packages/backend.ai-ui/**/*.{tsx,ts}" | ||
| --- | ||
|
|
||
| # 'use memo' Directive Rule | ||
|
|
||
| Always place `'use memo'` at the very top of the function body for **both React components and custom hooks** (`use*` functions). | ||
|
|
||
| ## Why | ||
|
|
||
| This project uses the React Compiler in annotation mode (`babel-plugin-react-compiler`). The `'use memo'` directive opts the function in to full compiler optimization — automatic memoization of values, callbacks, and JSX without manual `useMemo`/`useCallback`. Omitting it from hooks means the hook's internals are not optimized, even if the components consuming it are. | ||
|
|
||
| ## Pattern | ||
|
|
||
| ```tsx | ||
| // ✅ Component — always add 'use memo' | ||
| function MyComponent({ id }: Props) { | ||
| 'use memo'; | ||
|
|
||
| return <div>{id}</div>; | ||
| } | ||
|
|
||
| // ✅ Custom hook — always add 'use memo' | ||
| const useMyData = (id: string) => { | ||
| 'use memo'; | ||
|
|
||
| return useQuery(id); | ||
| }; | ||
|
|
||
| // ❌ Missing in hook — not optimized | ||
| const useMyData = (id: string) => { | ||
| return useQuery(id); | ||
| }; | ||
| ``` | ||
|
|
||
| ## Rules | ||
|
|
||
| 1. Add `'use memo'` as the **first statement** in the function body — before any hooks, variables, or logic. | ||
| 2. Apply to **both components and custom hooks** (`use*` naming convention). | ||
| 3. Comments before the directive are allowed. | ||
| 4. Use single or double quotes — **not backticks**. | ||
| 5. **Never remove** an existing `'use memo'` directive. | ||
| 6. Do not add `'use memo'` inside helper functions that are not components or hooks (plain utilities, event handlers, etc.). |
This file contains hidden or 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 hidden or 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
35 changes: 35 additions & 0 deletions
35
packages/backend.ai-ui/src/components/BAIImageWithFallback.tsx
This file contains hidden or 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,35 @@ | ||
| /** | ||
| @license | ||
| Copyright (c) 2015-2026 Lablup Inc. All rights reserved. | ||
| */ | ||
| import React, { useState } from 'react'; | ||
|
|
||
| export interface BAIImageWithFallbackProps extends Omit< | ||
| React.ImgHTMLAttributes<HTMLImageElement>, | ||
| 'onError' | ||
| > { | ||
| src: string; | ||
| fallbackIcon: React.ReactNode; | ||
| alt: string; | ||
| } | ||
|
|
||
| const BAIImageWithFallback: React.FC<BAIImageWithFallbackProps> = ({ | ||
| src, | ||
| fallbackIcon, | ||
| alt, | ||
| ...props | ||
| }) => { | ||
| 'use memo'; | ||
| const [errorSrc, setErrorSrc] = useState<string | null>(null); | ||
| const hasError = errorSrc === src; | ||
|
|
||
| if (hasError) { | ||
| return <>{fallbackIcon}</>; | ||
| } | ||
|
|
||
| return ( | ||
| <img {...props} src={src} alt={alt} onError={() => setErrorSrc(src)} /> | ||
| ); | ||
| }; | ||
|
|
||
| export default BAIImageWithFallback; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.