-
Notifications
You must be signed in to change notification settings - Fork 605
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
python panel state stability enhancements #5390
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,20 +1,22 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { useTrackEvent } from "@fiftyone/analytics"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { CenteredStack, CodeBlock, scrollable } from "@fiftyone/components"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { clearUseKeyStores } from "@fiftyone/core/src/plugins/SchemaIO/hooks"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
PanelSkeleton, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
usePanelLoading, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
usePanelState, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
useSetPanelCloseEffect, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} from "@fiftyone/spaces"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import * as fos from "@fiftyone/state"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { Box, Typography } from "@mui/material"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { useEffect } from "react"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { useEffect, useRef } from "react"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import OperatorIO from "./OperatorIO"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { PANEL_LOAD_TIMEOUT } from "./constants"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { useActivePanelEventsCount } from "./hooks"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { Property } from "./types"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { CustomPanelProps, useCustomPanelHooks } from "./useCustomPanelHooks"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { useTrackEvent } from "@fiftyone/analytics"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import usePanelEvent from "./usePanelEvent"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { isNullish } from "@fiftyone/utilities"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
export function CustomPanel(props: CustomPanelProps) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { panelId, dimensions, panelName, panelLabel, isModalPanel } = props; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -42,7 +44,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
triggerPanelEvent(panelId, { operator: props.onUnLoad }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, []); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check warning on line 47 in app/packages/operators/src/CustomPanel.tsx
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
setLoading(count > 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -95,6 +97,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
onPathChange={handlePanelStatePathChange} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
shouldClearUseKeyStores={false} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
isModalPanel={isModalPanel} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
updatableDefaultValue={false} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
</DimensionRefresher> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
</Box> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -107,7 +110,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
dimensions?.refresh(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, []); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
return children; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -128,9 +131,24 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
on_change_spaces, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
panel_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
panel_label, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
reset_state, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return (props) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { dimensions, panelNode, isModalPanel } = props; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
const [state, setState] = usePanelState(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There might be some logic in the new I was playing around with DQ panel and confirmed that on I recorded screenshots below of what is doing on with DQ panel on a basic scan In Panel execution works fine. The state of the vars we set remain persistent, and do not reset/empty out Screen.Recording.2025-01-27.at.5.33.13.PM.movIn Panel execution sets a state. The state does not persist and goes back to base (that's why it went back to homescreen), and then upon execution completion, state gets set once more (that's why it goest to Analysis) but then gets reset to base once more Screen.Recording.2025-01-27.at.5.36.01.PM.mov |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
const [localState] = usePanelState(null, null, true); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
const hasState = !isNullish(state?.state); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
const isLoaded = localState?.loaded; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
const isReset = useRef(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (!isLoaded && hasState && reset_state) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (!isReset.current) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
setState({}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
isReset.current = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+138
to
+150
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve state management implementation. The current implementation has several areas for improvement:
Consider this implementation: - const [state, setState] = usePanelState();
- const [localState] = usePanelState(null, null, true);
- const hasState = !isNullish(state?.state);
- const isLoaded = localState?.loaded;
- const isReset = useRef(false);
-
- if (!isLoaded && hasState && reset_state) {
- if (!isReset.current) {
- setState({});
- isReset.current = true;
- }
- return null;
- }
+ const [state, setState] = usePanelState();
+ const [isReset, setIsReset] = useState(false);
+
+ useEffect(() => {
+ if (reset_state && !isReset && !isNullish(state?.state)) {
+ setState({});
+ setIsReset(true);
+ }
+ }, [reset_state, state?.state, isReset]);
+
+ if (reset_state && !isReset) {
+ return null;
+ } 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
<CustomPanel | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
panelId={panelNode?.id} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -324,6 +324,7 @@ def register_panel( | |
on_change_query_performance=None, | ||
allow_duplicates=False, | ||
priority=None, | ||
reset_state=False, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this name is confusing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree on this, since this is supposed to be about persisting state on refresh, I think more descriptive is better here - something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree. |
||
_builtin=False, | ||
): | ||
"""Registers a panel with the given name and lifecycle callbacks. | ||
|
@@ -371,6 +372,8 @@ def register_panel( | |
the panel to the opened | ||
priority (None): the priority of the panel, used for sort order | ||
_builtin (False): whether the panel is a builtin panel | ||
reset_state (False): whether to reset the state of the panel prior to on load | ||
|
||
""" | ||
params = { | ||
"panel_name": name, | ||
|
@@ -398,6 +401,7 @@ def register_panel( | |
"on_change_query_performance": on_change_query_performance, | ||
"allow_duplicates": allow_duplicates, | ||
"priority": priority, | ||
"reset_state": reset_state, | ||
"_builtin": _builtin, | ||
} | ||
return self._ctx.trigger("register_panel", params=params) | ||
|
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.
This logic is getting out of hand!