Skip to content
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

Merge release/v1.1.0 to develop #5011

Closed
wants to merge 2 commits into from
Closed

Conversation

voxel51-bot
Copy link
Collaborator

@voxel51-bot voxel51-bot commented Oct 30, 2024

Merge release/v1.1.0 to develop

Summary by CodeRabbit

  • New Features

    • Introduced the QueryPerformanceToast component to provide users with notifications about query performance.
    • The toast includes guidance on improving query performance and links to documentation.
  • Enhancements

    • Integrated QueryPerformanceToast into the DatasetPage for improved user experience.

Copy link
Contributor

coderabbitai bot commented Oct 30, 2024

Walkthrough

The changes in this pull request involve the addition of a new component, QueryPerformanceToast, which is designed to display notifications related to query performance. This component has been integrated into the DatasetPage.tsx file, where it is now rendered alongside existing components. Additionally, the QueryPerformanceToast component is defined in a new file and has been exported from the core components index, allowing it to be utilized throughout the application.

Changes

File Path Change Summary
app/packages/app/src/pages/datasets/DatasetPage.tsx Added import and rendering of QueryPerformanceToast component.
app/packages/core/src/components/QueryPerformanceToast.tsx Introduced a new QueryPerformanceToast component that displays notifications about query performance.
app/packages/core/src/components/index.ts Added export statement for QueryPerformanceToast to make it accessible from the core components index.

Possibly related PRs

  • Toast component #4955: The introduction of the Toast component is related as it provides a customizable notification mechanism, similar to the QueryPerformanceToast component added in the main PR.
  • Toast component refactor #4957: The refactor of the Toast component to enhance its reusability and state management with Recoil is relevant since it aligns with the notification functionality of QueryPerformanceToast.
  • Add ToastView to Python Panels #4968: The addition of ToastView to Python Panels enhances the integration of toast notifications, which is directly related to the QueryPerformanceToast functionality.
  • make it pretty #4999: The modifications to the QueryPerformanceToast component for visual alignment with design mocks indicate a direct relationship with the changes made in the main PR.
  • Merge release/v1.1.0 to develop #5007: The changes to the QueryPerformanceToast component regarding its initial visibility state are relevant as they directly affect how the component behaves, similar to the changes in the main PR.

Suggested reviewers

  • findtopher
  • minhtuev

🐇 In the meadow, I hop with glee,
A toast for queries, oh so free!
With performance tips, it lights the way,
Come join the fun, let's play today!
A sprinkle of joy in every byte,
Query performance, shining bright! ✨


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Outside diff range and nitpick comments (3)
app/packages/core/src/components/index.ts (1)

12-12: Consider maintaining alphabetical order of exports.

The new export follows the correct naming and path conventions, but for better maintainability, consider moving it before ResourceCount to maintain alphabetical ordering with other exports.

 export { default as Loading } from "./Loading";
+export { default as QueryPerformanceToast } from "./QueryPerformanceToast";
 export { default as ResourceCount } from "./ResourceCount";
 export * from "./Sidebar";
 export { default as Snackbar } from "./Snackbar";
 export { default as ViewBar, rollbackViewBar } from "./ViewBar/ViewBar";
 export * from "./Starter";
-export { default as QueryPerformanceToast } from "./QueryPerformanceToast";
app/packages/app/src/pages/datasets/DatasetPage.tsx (1)

Line range hint 1-15: Consider organizing imports by category.

While the current import organization is functional, consider grouping imports into categories for better maintainability:

  1. External dependencies (React, Relay)
  2. Internal packages (@fiftyone/*)
  3. Local components and types
  4. Styles
+ // External dependencies
import React from "react";
import { usePreloadedQuery } from "react-relay";
import { useRecoilValue } from "recoil";
import { graphql } from "relay-runtime";

+ // Internal packages
import { Dataset, Snackbar, Starter, QueryPerformanceToast } from "@fiftyone/core";
import "@fiftyone/embeddings";
import "@fiftyone/map";
import { OperatorCore } from "@fiftyone/operators";
import "@fiftyone/relay";
import * as fos from "@fiftyone/state";
import { datasetQueryContext } from "@fiftyone/state";

+ // Local imports
import Nav from "../../components/Nav";
import type { Route } from "../../routing";
import type { DatasetPageQuery } from "./__generated__/DatasetPageQuery.graphql";

+ // Styles
import style from "../index.module.css";
app/packages/core/src/components/QueryPerformanceToast.tsx (1)

1-11: Add TypeScript types and improve constant naming.

Consider these improvements for better type safety and clarity:

  • Add explicit type imports from React (e.g., FC, MouseEvent)
  • Rename SHOWN_FOR to something more descriptive like TOAST_DISPLAY_DURATION_MS
  • Add type annotation to the constant
-import React, { useEffect, useState } from "react";
+import React, { FC, useEffect, useState } from "react";

-const SHOWN_FOR = 5000;
+const TOAST_DISPLAY_DURATION_MS: number = 5000;
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 430c3f7 and 32b352e.

📒 Files selected for processing (3)
  • app/packages/app/src/pages/datasets/DatasetPage.tsx (1 hunks)
  • app/packages/core/src/components/QueryPerformanceToast.tsx (1 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)

1-1: LGTM! Import statement follows package organization.

The QueryPerformanceToast import is correctly grouped with other core components from @fiftyone/core package.


Line range hint 92-94: Verify toast notification hierarchy and z-index.

The QueryPerformanceToast is placed alongside Snackbar, which is correct for global notifications. However, ensure there are no z-index conflicts or overlay issues between these components.

Consider implementing a toast/notification manager to handle multiple notifications if not already present.

app/packages/core/src/components/QueryPerformanceToast.tsx (1)

23-126: 🛠️ Refactor suggestion

Consider performance optimizations.

The component could benefit from these performance improvements:

  • Memoize callback functions using useCallback
  • Memoize complex JSX using useMemo
  • Consider using React.memo for the component itself if it's used in a list or frequently re-rendered context
+const QueryPerformanceToast: FC = React.memo(() => {
   // ... existing implementation
-});
+}, (prevProps, nextProps) => true);

Comment on lines +13 to +21
const hideQueryPerformanceToast = atom({
key: "hideQueryPerformanceToast",
default: false,
effects: [
getBrowserStorageEffectForKey("hideQueryPerformanceToast", {
valueClass: "boolean",
}),
],
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance type safety and naming for Recoil atom.

Consider these improvements:

  • Add an interface for the atom state
  • Namespace the atom key to avoid potential conflicts
  • Consider using a constant for the storage key
+interface QueryPerformanceToastState {
+  hidden: boolean;
+}

+const STORAGE_KEY = "fiftyone.queryPerformance.hideToast";

 const hideQueryPerformanceToast = atom({
-  key: "hideQueryPerformanceToast",
+  key: "fiftyone.atoms.hideQueryPerformanceToast",
   default: false,
+  effects: [
+    getBrowserStorageEffectForKey(STORAGE_KEY, {
       valueClass: "boolean",
     }),
   ],
 });
📝 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.

Suggested change
const hideQueryPerformanceToast = atom({
key: "hideQueryPerformanceToast",
default: false,
effects: [
getBrowserStorageEffectForKey("hideQueryPerformanceToast", {
valueClass: "boolean",
}),
],
});
interface QueryPerformanceToastState {
hidden: boolean;
}
const STORAGE_KEY = "fiftyone.queryPerformance.hideToast";
const hideQueryPerformanceToast = atom({
key: "fiftyone.atoms.hideQueryPerformanceToast",
default: false,
effects: [
getBrowserStorageEffectForKey(STORAGE_KEY, {
valueClass: "boolean",
}),
],
});

Comment on lines +36 to +42
if (!element) {
throw new Error("no query performance element");
}

if (!shown || disabled) {
return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Improve error handling approach.

Instead of throwing an error, consider:

  • Logging the error and gracefully handling the missing element
  • Providing a more descriptive error message
  • Adding error boundaries for better error handling
-  if (!element) {
-    throw new Error("no query performance element");
-  }
+  if (!element) {
+    console.error("QueryPerformanceToast: Target DOM element #queryPerformance not found");
+    return null;
+  }
📝 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.

Suggested change
if (!element) {
throw new Error("no query performance element");
}
if (!shown || disabled) {
return null;
}
if (!element) {
console.error("QueryPerformanceToast: Target DOM element #queryPerformance not found");
return null;
}
if (!shown || disabled) {
return null;
}

Comment on lines +23 to +34
const QueryPerformanceToast = () => {
const [shown, setShown] = useState(false);
const [disabled, setDisabled] = useRecoilState(hideQueryPerformanceToast);
const element = document.getElementById("queryPerformance");
const theme = useTheme();
useEffect(() => {
const listen = () => {
setShown(true);
};
window.addEventListener("queryperformance", listen);
return () => window.removeEventListener("queryperformance", listen);
}, []);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Improve component type safety and event handling.

Several TypeScript and React best practices could be applied here:

  • Add FC type to the component
  • Define custom event type for 'queryperformance'
  • Move DOM element access into useEffect to avoid potential null checks during SSR
+interface QueryPerformanceEvent extends Event {
+  // add any custom event properties here
+}

-const QueryPerformanceToast = () => {
+const QueryPerformanceToast: FC = () => {
   const [shown, setShown] = useState(false);
   const [disabled, setDisabled] = useRecoilState(hideQueryPerformanceToast);
-  const element = document.getElementById("queryPerformance");
   const theme = useTheme();
+  
   useEffect(() => {
+    const element = document.getElementById("queryPerformance");
+    if (!element) {
+      console.error("Query performance element not found");
+      return;
+    }
+    
-    const listen = () => {
+    const listen = (event: QueryPerformanceEvent) => {
       setShown(true);
     };
-    window.addEventListener("queryperformance", listen);
-    return () => window.removeEventListener("queryperformance", listen);
-  }, []);
+    window.addEventListener("queryperformance", listen as EventListener);
+    return () => window.removeEventListener("queryperformance", listen as EventListener);
+  }, []);
📝 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.

Suggested change
const QueryPerformanceToast = () => {
const [shown, setShown] = useState(false);
const [disabled, setDisabled] = useRecoilState(hideQueryPerformanceToast);
const element = document.getElementById("queryPerformance");
const theme = useTheme();
useEffect(() => {
const listen = () => {
setShown(true);
};
window.addEventListener("queryperformance", listen);
return () => window.removeEventListener("queryperformance", listen);
}, []);
interface QueryPerformanceEvent extends Event {
// add any custom event properties here
}
const QueryPerformanceToast: FC = () => {
const [shown, setShown] = useState(false);
const [disabled, setDisabled] = useRecoilState(hideQueryPerformanceToast);
const theme = useTheme();
useEffect(() => {
const element = document.getElementById("queryPerformance");
if (!element) {
console.error("Query performance element not found");
return;
}
const listen = (event: QueryPerformanceEvent) => {
setShown(true);
};
window.addEventListener("queryperformance", listen as EventListener);
return () => window.removeEventListener("queryperformance", listen as EventListener);
}, []);

Comment on lines +44 to +126
return createPortal(
<Toast
duration={SHOWN_FOR}
layout={{
bottom: "100px",
vertical: "bottom",
horizontal: "center",
backgroundColor: theme.custom.toastBackgroundColor,
}}
primary={(setOpen) => {
return (
<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
>
View Documentation
</Button>
);
}}
secondary={(setOpen) => {
return (
<div>
<Button
variant="text"
color="secondary"
size="small"
onClick={() => {
setDisabled(true);
setOpen(false);
}}
style={{ marginLeft: "auto", color: theme.text.secondary }} // Right align the button
>
Dismiss
</Button>
</div>
);
}}
message={
<>
<Box sx={{ display: "flex", alignItems: "center" }}>
<Bolt sx={{ color: theme.custom.lightning, marginRight: "8px" }} />
<Typography
variant="subtitle1"
sx={{
fontWeight: 500,
marginRight: "8px",
color: theme.text.primary,
}}
>
Query Performance is Available!
</Typography>
<Typography
variant="caption"
sx={{
color: theme.custom.lightning,
borderRadius: "2px",
padding: "2px 4px",
fontSize: "1rem",
}}
>
NEW
</Typography>
</Box>
<Typography variant="body2" sx={{ color: theme.text.secondary }}>
Index the most critical fields for faster data loading and query
performance.
</Typography>
</>
}
/>,
element
);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance accessibility and style organization.

Consider these improvements:

  • Add aria labels for better accessibility
  • Move inline styles to sx prop
  • Extract magic numbers to constants
  • Add proper button types
 <Button
   variant="contained"
   size="small"
+  type="button"
+  aria-label="View query performance documentation"
   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
+  }}
 >

 <Button
   variant="text"
   color="secondary"
   size="small"
+  type="button"
+  aria-label="Dismiss notification"
   onClick={() => {
     setDisabled(true);
     setOpen(false);
   }}
-  style={{ marginLeft: "auto", color: theme.text.secondary }}
+  sx={{ 
+    marginLeft: "auto", 
+    color: theme.text.secondary 
+  }}
 >
📝 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.

Suggested change
return createPortal(
<Toast
duration={SHOWN_FOR}
layout={{
bottom: "100px",
vertical: "bottom",
horizontal: "center",
backgroundColor: theme.custom.toastBackgroundColor,
}}
primary={(setOpen) => {
return (
<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
>
View Documentation
</Button>
);
}}
secondary={(setOpen) => {
return (
<div>
<Button
variant="text"
color="secondary"
size="small"
onClick={() => {
setDisabled(true);
setOpen(false);
}}
style={{ marginLeft: "auto", color: theme.text.secondary }} // Right align the button
>
Dismiss
</Button>
</div>
);
}}
message={
<>
<Box sx={{ display: "flex", alignItems: "center" }}>
<Bolt sx={{ color: theme.custom.lightning, marginRight: "8px" }} />
<Typography
variant="subtitle1"
sx={{
fontWeight: 500,
marginRight: "8px",
color: theme.text.primary,
}}
>
Query Performance is Available!
</Typography>
<Typography
variant="caption"
sx={{
color: theme.custom.lightning,
borderRadius: "2px",
padding: "2px 4px",
fontSize: "1rem",
}}
>
NEW
</Typography>
</Box>
<Typography variant="body2" sx={{ color: theme.text.secondary }}>
Index the most critical fields for faster data loading and query
performance.
</Typography>
</>
}
/>,
element
);
};
return createPortal(
<Toast
duration={SHOWN_FOR}
layout={{
bottom: "100px",
vertical: "bottom",
horizontal: "center",
backgroundColor: theme.custom.toastBackgroundColor,
}}
primary={(setOpen) => {
return (
<Button
variant="contained"
size="small"
type="button"
aria-label="View query performance documentation"
onClick={() => {
open(QP_MODE, "_blank")?.focus();
setOpen(false);
}}
sx={{
marginLeft: "auto",
backgroundColor: theme.primary.main,
color: theme.text.primary,
boxShadow: 0,
}}
>
View Documentation
</Button>
);
}}
secondary={(setOpen) => {
return (
<div>
<Button
variant="text"
color="secondary"
size="small"
type="button"
aria-label="Dismiss notification"
onClick={() => {
setDisabled(true);
setOpen(false);
}}
sx={{
marginLeft: "auto",
color: theme.text.secondary
}}
>
Dismiss
</Button>
</div>
);
}}
message={
<>
<Box sx={{ display: "flex", alignItems: "center" }}>
<Bolt sx={{ color: theme.custom.lightning, marginRight: "8px" }} />
<Typography
variant="subtitle1"
sx={{
fontWeight: 500,
marginRight: "8px",
color: theme.text.primary,
}}
>
Query Performance is Available!
</Typography>
<Typography
variant="caption"
sx={{
color: theme.custom.lightning,
borderRadius: "2px",
padding: "2px 4px",
fontSize: "1rem",
}}
>
NEW
</Typography>
</Box>
<Typography variant="body2" sx={{ color: theme.text.secondary }}>
Index the most critical fields for faster data loading and query
performance.
</Typography>
</>
}
/>,
element
);
};

@findtopher findtopher closed this Oct 30, 2024
@findtopher findtopher deleted the merge/release/v1.1.0 branch October 30, 2024 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants