feat: add an overlay to show general preview errs#1974
Conversation
This adds an overlay much like the connection error and copy error ones, but it is for general use in the various preview widgets.
WalkthroughThe changes modify both the preview view component and type declarations. In the preview component, a new error handling mechanism is introduced by adding an atom to store error messages and integrating an Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
frontend/app/view/preview/preview.tsx (3)
201-201: Add explicit type for errorMsgAtom.Consider adding explicit type for better type safety:
-this.errorMsgAtom = atom(null) as PrimitiveAtom<ErrorMsg>; +this.errorMsgAtom = atom<ErrorMsg | null>(null);
1277-1277: Use stable key for mapped buttons.Using
crypto.randomUUID()as a key will cause unnecessary re-renders as it generates a new value on each render. Consider using a stable key based on the button text or a pre-defined index.-key={crypto.randomUUID()} +key={buttonDef.text}
1269-1281: Use optional chaining for buttons map.The buttons mapping can be simplified using optional chaining for better readability and safety.
-{errorMsg.buttons && - errorMsg.buttons.map((buttonDef) => ( +{errorMsg.buttons?.map((buttonDef) => (🧰 Tools
🪛 Biome (1.9.4)
[error] 1269-1281: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
frontend/app/theme.scss(1 hunks)frontend/app/view/preview/preview.tsx(7 hunks)frontend/types/custom.d.ts(1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
frontend/app/view/preview/preview.tsx
[error] 1269-1281: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Build for TestDriver.ai
- GitHub Check: Analyze (go)
🔇 Additional comments (2)
frontend/types/custom.d.ts (1)
434-445: LGTM! Well-structured type definitions for error handling.The new types
ErrorButtonDefandErrorMsgare well-designed with clear properties that provide a comprehensive structure for error messages and associated actions.frontend/app/theme.scss (1)
116-116: LGTM! Consistent styling for error overlay.The new CSS variable follows the existing pattern of overlay background colors and provides a suitable semi-transparent red background for error states.
| if (errorMsg.closeAction) { | ||
| errorMsg.closeAction; | ||
| } |
There was a problem hiding this comment.
Fix closeAction invocation.
The closeAction is not being invoked properly. The function reference is being used as a value without calling it.
-errorMsg.closeAction;
+errorMsg.closeAction();📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (errorMsg.closeAction) { | |
| errorMsg.closeAction; | |
| } | |
| if (errorMsg.closeAction) { | |
| - errorMsg.closeAction; | |
| + errorMsg.closeAction(); | |
| } |
| "items-start": true, | ||
| })} | ||
| > | ||
| <i className=" text-[#e6ba1e] text-base"></i> |
There was a problem hiding this comment.
Add missing warning icon class.
The icon element is missing the Font Awesome warning icon class.
-<i className=" text-[#e6ba1e] text-base"></i>
+<i className="fa-solid fa-triangle-exclamation text-[#e6ba1e] text-base"></i>📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| <i className=" text-[#e6ba1e] text-base"></i> | |
| <i className="fa-solid fa-triangle-exclamation text-[#e6ba1e] text-base"></i> |
There was a problem hiding this comment.
Actionable comments posted: 0
♻️ Duplicate comments (1)
frontend/app/view/preview/preview.tsx (1)
1294-1296:⚠️ Potential issueFix closeAction invocation.
The
closeActionis not being invoked properly. The function reference is being used as a value without calling it.Apply this diff to fix the invocation:
-errorMsg.closeAction; +errorMsg.closeAction();
🧹 Nitpick comments (2)
frontend/app/view/preview/preview.tsx (2)
1274-1286: Use optional chaining for better code quality.The map operation on
errorMsg.buttonscould be simplified using optional chaining.Apply this diff to improve the code:
-{errorMsg.buttons && - errorMsg.buttons.map((buttonDef) => ( +{errorMsg.buttons?.map((buttonDef) => (🧰 Tools
🪛 Biome (1.9.4)
[error] 1274-1286: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
1282-1282: Replace randomUUID with stable keys.Using
crypto.randomUUID()for React key props can cause unnecessary re-renders as the key changes on every render. Consider using a stable identifier from the button definition.Apply this diff to improve stability:
-key={crypto.randomUUID()} +key={buttonDef.text}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
frontend/app/view/preview/preview.tsx(7 hunks)frontend/types/custom.d.ts(1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
frontend/app/view/preview/preview.tsx
[error] 1274-1286: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Build for TestDriver.ai
- GitHub Check: Analyze (go)
🔇 Additional comments (4)
frontend/types/custom.d.ts (1)
434-446: LGTM! Well-structured type definitions.The new types
ErrorButtonDefandErrorMsgare well-designed with:
- Clear and descriptive property names
- Proper use of optional properties
- Type-safe union type for error levels
- Reusable button definition type
frontend/app/view/preview/preview.tsx (3)
6-6: LGTM! Well-organized imports.The new imports are properly organized and necessary for the error overlay functionality.
Also applies to: 43-43, 46-46
166-166: LGTM! Clean atom integration.The
errorMsgAtomis properly integrated into the PreviewModel class.Also applies to: 201-201
1130-1130: LGTM! Clean error overlay integration.The ErrorOverlay component is properly integrated with PreviewView:
- Uses proper state management with useAtom
- Implements clean reset functionality
- Conditionally renders based on error state
Also applies to: 1151-1151
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
frontend/app/view/preview/preview.tsx (1)
1235-1305: Add TypeScript types for props and error levels.The
ErrorOverlaycomponent could benefit from stronger type safety.Consider adding these TypeScript types:
type ErrorLevel = 'error' | 'warning'; interface ErrorOverlayProps { errorMsg: ErrorMsg; resetOverlay: () => void; }Also, consider extracting hardcoded CSS values to variables for better maintainability:
-className="absolute top-[0] left-1.5 right-1.5 z-[var(--zindex-block-mask-inner)]" +className="absolute top-0 left-1.5 right-1.5 z-[var(--zindex-block-mask-inner)]"
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
frontend/app/view/preview/preview.tsx(7 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Analyze (go)
- GitHub Check: Build for TestDriver.ai
🔇 Additional comments (2)
frontend/app/view/preview/preview.tsx (2)
6-6: LGTM!The new imports for
CopyButtonand additional Jotai atoms are correctly added.Also applies to: 43-43
1130-1130: LGTM!The error handling integration is well-implemented with proper state management using Jotai atoms and conditional rendering of the error overlay.
Also applies to: 1151-1151
This adds an overlay much like the connection error and copy error ones, but it is for general use in the various preview widgets.
This adds an overlay much like the connection error and copy error ones, but it is for general use in the various preview widgets.