-
Notifications
You must be signed in to change notification settings - Fork 557
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
Refactor/qp #5012
Refactor/qp #5012
Conversation
WalkthroughThe changes involve modifications to the Changes
Possibly related PRs
Suggested reviewers
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
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (2)
app/packages/core/src/components/index.ts (1)
12-12
: LGTM! Good architectural decision.Moving the QueryPerformanceToast to core and exporting it through the barrel file improves modularity and reusability. The export follows the established pattern and maintains consistency with other component exports.
app/packages/core/src/components/QueryPerformanceToast.tsx (1)
Line range hint
1-124
: Consider enhancing TypeScript usage and constants management.
- The
SHOWN_FOR
constant could be moved to a constants file for better maintainability.- Consider adding proper TypeScript types for the component props and theme values.
// types.ts export interface QueryPerformanceToastProps { portalElementId?: string; } // constants.ts export const TOAST_CONSTANTS = { SHOWN_DURATION: 5000, PORTAL_ID: 'queryPerformance', } as const;Then update the component:
- const SHOWN_FOR = 5000; + import { TOAST_CONSTANTS } from './constants'; + import type { QueryPerformanceToastProps } from './types'; - const QueryPerformanceToast = () => { + const QueryPerformanceToast: React.FC<QueryPerformanceToastProps> = ({ + portalElementId = TOAST_CONSTANTS.PORTAL_ID + }) => {
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (3)
app/packages/app/src/pages/datasets/DatasetPage.tsx
(1 hunks)app/packages/core/src/components/QueryPerformanceToast.tsx
(4 hunks)app/packages/core/src/components/index.ts
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
app/packages/app/src/pages/datasets/DatasetPage.tsx (1)
Pattern **/*.{ts,tsx}
: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.
app/packages/core/src/components/QueryPerformanceToast.tsx (1)
Pattern **/*.{ts,tsx}
: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.
app/packages/core/src/components/index.ts (1)
Pattern **/*.{ts,tsx}
: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.
🔇 Additional comments (3)
app/packages/app/src/pages/datasets/DatasetPage.tsx (2)
Line range hint 108-108
: LGTM! Proper placement of QueryPerformanceToast.
The component is correctly positioned alongside other global UI elements.
1-1
: LGTM! Verify other imports of QueryPerformanceToast.
The import change aligns with moving the toast component to core.
Let's verify no other files are still importing from the old location:
✅ Verification successful
Import change is correctly implemented
The verification shows that:
- QueryPerformanceToast is properly exported from @fiftyone/core
- No other files are importing it from the old location
- The only imports are from the new @fiftyone/core location
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for any remaining imports from the old location
rg "from ['\"].*components/QueryPerformanceToast['\"]"
Length of output: 60
Script:
#!/bin/bash
# Let's try a broader search for QueryPerformanceToast to find any remaining imports
rg "QueryPerformanceToast" -A 2 -B 2
Length of output: 3848
app/packages/core/src/components/QueryPerformanceToast.tsx (1)
77-77
: LGTM! Good test coverage addition.
The data-cy attribute follows best practices for Cypress testing and uses a clear, descriptive identifier.
sx={{ | ||
fontWeight: 500, | ||
marginRight: "8px", | ||
color: theme.text.primary, | ||
}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider memoizing Typography styles.
The sx object is recreated on every render. Consider using useMemo
to optimize performance.
+ const titleTypographyStyles = useMemo(() => ({
+ fontWeight: 500,
+ marginRight: "8px",
+ color: theme.text.primary,
+ }), [theme.text.primary]);
<Typography
variant="subtitle1"
- sx={{
- fontWeight: 500,
- marginRight: "8px",
- color: theme.text.primary,
- }}
+ sx={titleTypographyStyles}
>
Committable suggestion was skipped due to low confidence.
layout={{ | ||
bottom: "100px", | ||
vertical: "bottom", | ||
horizontal: "center", | ||
backgroundColor: theme.custom.toastBackgroundColor, | ||
}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider memoizing the layout object.
The layout object is recreated on every render. Consider using useMemo
to optimize performance.
+ const layout = useMemo(() => ({
+ bottom: "100px",
+ vertical: "bottom",
+ horizontal: "center",
+ backgroundColor: theme.custom.toastBackgroundColor,
+ }), [theme.custom.toastBackgroundColor]);
return createPortal(
<Toast
duration={SHOWN_FOR}
- layout={{
- bottom: "100px",
- vertical: "bottom",
- horizontal: "center",
- backgroundColor: theme.custom.toastBackgroundColor,
- }}
+ layout={layout}
📝 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.
layout={{ | |
bottom: "100px", | |
vertical: "bottom", | |
horizontal: "center", | |
backgroundColor: theme.custom.toastBackgroundColor, | |
}} | |
const layout = useMemo(() => ({ | |
bottom: "100px", | |
vertical: "bottom", | |
horizontal: "center", | |
backgroundColor: theme.custom.toastBackgroundColor, | |
}), [theme.custom.toastBackgroundColor]); | |
return createPortal( | |
<Toast | |
duration={SHOWN_FOR} | |
layout={layout} | |
``` | |
Note: The suggestion assumes that `useMemo` is imported from 'react'. If it's not already imported, you would need to add: | |
```typescript | |
import { useMemo } from 'react'; |
sx={{ | ||
marginLeft: "auto", | ||
backgroundColor: theme.primary.main, | ||
color: theme.text.primary, | ||
boxShadow: 0, | ||
}} // Right align the button |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Remove redundant comment and consider memoizing styles.
The comment "Right align the button" is redundant as it's describing what marginLeft: "auto"
does. Also, consider memoizing the sx object.
+ const primaryButtonStyles = useMemo(() => ({
+ marginLeft: "auto",
+ backgroundColor: theme.primary.main,
+ color: theme.text.primary,
+ boxShadow: 0,
+ }), [theme.primary.main, theme.text.primary]);
<Button
variant="contained"
size="small"
onClick={() => {
open(QP_MODE, "_blank")?.focus();
setOpen(false);
}}
- sx={{
- marginLeft: "auto",
- backgroundColor: theme.primary.main,
- color: theme.text.primary,
- boxShadow: 0,
- }} // Right align the button
+ sx={primaryButtonStyles}
>
Committable suggestion was skipped due to low confidence.
What changes are proposed in this pull request?
refactor toast component to core
How is this patch tested? If it is not, please explain why.
running server locally and changing is shown to True by default to make the popup appear
Release Notes
Is this a user-facing change that should be mentioned in the release notes?
notes for FiftyOne users.
What areas of FiftyOne does this PR affect?
fiftyone
Python library changesSummary by CodeRabbit
New Features
QueryPerformanceToast
component to enhance theDatasetPage
with performance notifications.Improvements
QueryPerformanceToast
component with formatting adjustments.data-cy
attribute to the dismiss button for improved testing capabilities.Accessibility
QueryPerformanceToast
available for import across the application through the core components index.