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

Bug fixes for Query Performance Toast #5048

Merged
merged 8 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ const NumericFieldFilter = ({ color, modal, named = true, path }: Props) => {
const [showRange, setShowRange] = React.useState(!isGroup);
const field = fos.useAssertedRecoilValue(fos.field(path));
const queryPerformance = useRecoilValue(fos.queryPerformance);
const hasBounds = useRecoilValue(state.hasBounds({ path, modal }));
const hasBounds = useRecoilValue(
state.hasBounds({ path, modal, shouldCalculate: !queryPerformance })
);

if (!queryPerformance && named && !hasBounds) {
return null;
Expand Down Expand Up @@ -87,6 +89,7 @@ const NumericFieldFilter = ({ color, modal, named = true, path }: Props) => {
color: theme.text.secondary,
borderRadius: "8px",
border: "1px solid " + theme.secondary.main,
height: "30px",
}}
>
Filter by {name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ export const FLOAT_NONFINITES: Nonfinite[] = ["inf", "ninf", "nan"];
export const hasBounds = selectorFamily({
key: "hasBounds",
get:
(params: { path: string; modal: boolean }) =>
(params: { path: string; modal: boolean; shouldCalculate: boolean }) =>
({ get }) => {
return Boolean(get(boundsAtom(params))?.every((b) => b !== null));
const shouldCalculate = params.shouldCalculate ?? true;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this because I was seeing that whenever a sidebar section was opened we were calling to lightningModeQuery to get the bounds which in QP mode we should never see that until a user actually clicks a button to view a slider or opens a dropdown. This was firing off because if we aren't in QP mode we want to check if something has bounds to determine if we want to show it at all instead of just saying "No Results". This way in QP we don't check bounds until the user selects the field and in non QP mode we always check it.

return shouldCalculate
? Boolean(get(boundsAtom(params))?.every((b) => b !== null))
: Boolean(false);
},
});

Expand Down
31 changes: 22 additions & 9 deletions app/packages/core/src/components/QueryPerformanceToast.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
import { Toast } from "@fiftyone/components";
import { QP_MODE } from "@fiftyone/core";
import { QP_MODE, QP_MODE_SUMMARY } from "@fiftyone/core";
import { getBrowserStorageEffectForKey } from "@fiftyone/state";
import { Box, Button, Typography } from "@mui/material";
import { Bolt } from "@mui/icons-material";
import React, { useEffect, useState } from "react";
import { createPortal } from "react-dom";
import { atom, useRecoilState } from "recoil";
import { atom, useRecoilState, useRecoilValue } from "recoil";
import { useTheme } from "@fiftyone/components";
import * as atoms from "@fiftyone/state/src/recoil/atoms";

const SHOWN_FOR = 5000;
const SHOWN_FOR = 10000;

const hideQueryPerformanceToast = atom({
key: "hideQueryPerformanceToast",
default: false,
effects: [
getBrowserStorageEffectForKey("hideQueryPerformanceToast", {
valueClass: "boolean",
sessionStorage: true,
}),
],
});

const QueryPerformanceToast = ({
onClick = () => window.open(QP_MODE, "_blank")?.focus(),
onClick = (isFrameFilter: boolean) => {
const link = isFrameFilter ? QP_MODE_SUMMARY : QP_MODE;
window.open(link, "_blank")?.focus();
},
onDispatch = (event) => {
console.debug(event);
},
text = "View Documentation",
}) => {
const [path, setPath] = useState("");
const [shown, setShown] = useState(false);
const [disabled, setDisabled] = useRecoilState(hideQueryPerformanceToast);
const element = document.getElementById("queryPerformance");
const theme = useTheme();
const frameFields = useRecoilValue(atoms.frameFields);

useEffect(() => {
const listen = (event) => {
onDispatch(event);
setPath(event.path);
setShown(true);
};
window.addEventListener("queryperformance", listen);
Expand All @@ -57,14 +66,18 @@ const QueryPerformanceToast = ({
horizontal: "center",
backgroundColor: theme.custom.toastBackgroundColor,
}}
primary={(setOpen) => {
primary={() => {
return (
<Button
variant="contained"
size="small"
onClick={() => {
onClick();
setOpen(false);
onClick(
frameFields.some((frame) =>
path.includes(`frames.${frame.path}`)
)
);
setShown(false);
}}
sx={{
marginLeft: "auto",
Expand All @@ -77,7 +90,7 @@ const QueryPerformanceToast = ({
</Button>
);
}}
secondary={(setOpen) => {
secondary={() => {
return (
<div>
<Button
Expand All @@ -87,7 +100,7 @@ const QueryPerformanceToast = ({
size="small"
onClick={() => {
setDisabled(true);
setOpen(false);
setShown(false);
}}
style={{ marginLeft: "auto", color: theme.text.secondary }} // Right align the button
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,51 +1,9 @@
import * as fos from "@fiftyone/state";
import { count, pathColor } from "@fiftyone/state";
import React, { Suspense, useEffect } from "react";
import { pathColor } from "@fiftyone/state";
import React from "react";
import { useRecoilValue } from "recoil";
import FilterItem from "./FilterItem";
import useFilterData from "./useFilterData";

const LABEL_TAGS = "_label_tags";
const TIMEOUT = 5000;

class QueryPerformanceToast extends Event {
path?: string;
constructor(path?: string) {
super("queryperformance");
this.path = path;
}
}

const QueryPerformanceDispatcher = ({ path }: { path: string }) => {
useEffect(() => {
const timeout = setTimeout(() => {
window.dispatchEvent(new QueryPerformanceToast(path));
}, TIMEOUT);

return () => clearTimeout(timeout);
}, [path]);
return null;
};

const QueryPerformanceSubscriber = ({ path }: { path: string }) => {
useRecoilValue(count({ extended: false, modal: false, path }));
return null;
};

const QueryPerformance = ({ path }: { path: string }) => {
const queryPerformance = useRecoilValue(fos.queryPerformance);

if (queryPerformance || path === LABEL_TAGS || !path) {
return null;
}

return (
<Suspense fallback={<QueryPerformanceDispatcher path={path} />}>
<QueryPerformanceSubscriber path={path} />
</Suspense>
);
};

const FilterablePathEntries = ({
modal,
path,
Expand All @@ -61,12 +19,9 @@ const FilterablePathEntries = ({

return (
<>
{!modal && <QueryPerformance path={path} />}
<>
{data.map(({ color: _, ...props }) => (
<FilterItem key={props.path} color={color} {...events} {...props} />
))}
</>
{data.map(({ color: _, ...props }) => (
<FilterItem key={props.path} color={color} {...events} {...props} />
))}
</>
);
};
Expand Down
3 changes: 3 additions & 0 deletions app/packages/core/src/utils/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export const FRAME_FILTERING_DISABLED =
export const QP_MODE =
"https://docs.voxel51.com/user_guide/app.html#query-performance";

export const QP_MODE_SUMMARY =
"https://docs.voxel51.com/user_guide/using_datasets.html#summary-fields";

export const NAME_COLORSCALE = "https://plotly.com/python/colorscales/";

export const OBJECT_PATCHES =
Expand Down
Loading