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

Refactor/qp #5012

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/packages/app/src/pages/datasets/DatasetPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dataset, Snackbar, Starter } from "@fiftyone/core";
import { Dataset, Snackbar, Starter, QueryPerformanceToast } from "@fiftyone/core";
import "@fiftyone/embeddings";
import "@fiftyone/map";
import { OperatorCore } from "@fiftyone/operators";
Expand All @@ -10,7 +10,6 @@ import { usePreloadedQuery } from "react-relay";
import { useRecoilValue } from "recoil";
import { graphql } from "relay-runtime";
import Nav from "../../components/Nav";
import QueryPerformanceToast from "../../components/QueryPerformanceToast";
import type { Route } from "../../routing";
import style from "../index.module.css";
import type { DatasetPageQuery } from "./__generated__/DatasetPageQuery.graphql";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ const QueryPerformanceToast = () => {
return createPortal(
<Toast
duration={SHOWN_FOR}
layout={{ bottom: '100px', vertical: "bottom", horizontal: "center", backgroundColor: theme.custom.toastBackgroundColor}}
layout={{
bottom: "100px",
vertical: "bottom",
horizontal: "center",
backgroundColor: theme.custom.toastBackgroundColor,
}}
Comment on lines +47 to +52
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

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.

Suggested change
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';

primary={(setOpen) => {
return (
<Button
Expand All @@ -54,7 +59,12 @@ const QueryPerformanceToast = () => {
open(QP_MODE, "_blank")?.focus();
setOpen(false);
}}
sx={{ marginLeft: "auto", backgroundColor: theme.primary.main, color: "#FFFFFF", boxShadow: 0 }} // Right align the button
sx={{
marginLeft: "auto",
backgroundColor: theme.primary.main,
color: theme.text.primary,
boxShadow: 0,
}} // Right align the button
Comment on lines +62 to +67
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

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.

>
View Documentation
</Button>
Expand All @@ -64,6 +74,7 @@ const QueryPerformanceToast = () => {
return (
<div>
<Button
data-cy="btn-dismiss-query-performance-toast"
variant="text"
color="secondary"
size="small"
Expand All @@ -84,7 +95,11 @@ const QueryPerformanceToast = () => {
<Bolt sx={{ color: theme.custom.lightning, marginRight: "8px" }} />
<Typography
variant="subtitle1"
sx={{ fontWeight: 500, marginRight: "8px", color: theme.text.primary }}
sx={{
fontWeight: 500,
marginRight: "8px",
color: theme.text.primary,
}}
Comment on lines +98 to +102
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

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.

>
Query Performance is Available!
</Typography>
Expand Down
1 change: 1 addition & 0 deletions app/packages/core/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ 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";
Loading