-
Notifications
You must be signed in to change notification settings - Fork 590
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
Bugfix: clean treeselectionview type and fix a initial state check grid samples issue #5053
Changes from 7 commits
7b2b4e7
8a2578c
0e6e5b8
2fa7265
54093f2
3aaa981
5ea3e04
8cf5375
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 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,6 +3,7 @@ import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; | |||||||||||||
import { Box, Checkbox, FormControlLabel, IconButton } from "@mui/material"; | ||||||||||||||
import React, { useEffect } from "react"; | ||||||||||||||
import { ViewPropsType } from "../utils/types"; | ||||||||||||||
import { useUnboundState } from "@fiftyone/state"; | ||||||||||||||
|
||||||||||||||
interface CheckedState { | ||||||||||||||
[key: string]: { | ||||||||||||||
|
@@ -70,6 +71,13 @@ export default function TreeSelectionView(props: ViewPropsType) { | |||||||||||||
const [checkedState, setCheckedState] = | ||||||||||||||
React.useState<CheckedState>(initialCheckedState); | ||||||||||||||
|
||||||||||||||
const unboundState = useUnboundState(checkedState); | ||||||||||||||
|
||||||||||||||
// useEffect(() => { | ||||||||||||||
// console.log('unboundState useEffect', unboundState) | ||||||||||||||
// // no need to call onChange here, because the change comes from python side | ||||||||||||||
// }, [data, unboundState]) | ||||||||||||||
|
||||||||||||||
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. Remove unused unboundState or document its purpose The Either:
- const unboundState = useUnboundState(checkedState);
-
- // useEffect(() => {
- // console.log('unboundState useEffect', unboundState)
- // // no need to call onChange here, because the change comes from python side
- // }, [data, unboundState])
📝 Committable suggestion
Suggested change
|
||||||||||||||
// Initialize collapsed state for all parents | ||||||||||||||
const initialCollapsedState: CollapsedState = React.useMemo(() => { | ||||||||||||||
const state: CollapsedState = {}; | ||||||||||||||
|
@@ -192,6 +200,16 @@ export default function TreeSelectionView(props: ViewPropsType) { | |||||||||||||
return idx === -1 ? 0 : idx + 1; | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
useEffect(() => { | ||||||||||||||
const sampleIds = view?.data.flatMap(([parentId, children]) => { | ||||||||||||||
return children.map((childId) => | ||||||||||||||
typeof childId === "string" ? childId : childId[0] | ||||||||||||||
); | ||||||||||||||
}); | ||||||||||||||
onChange(path, sampleIds); | ||||||||||||||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||||||||||||||
}, []); | ||||||||||||||
Comment on lines
+198
to
+206
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 duplicate initialization logic and fix effect dependencies The useEffect duplicates the initialization logic from the early return block and has several issues:
Consider refactoring to: - useEffect(() => {
- const sampleIds = view?.data.flatMap(([parentId, children]) => {
- return children.map((childId) =>
- typeof childId === "string" ? childId : childId[0]
- );
- });
- onChange(path, sampleIds);
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, []);
+ useEffect(() => {
+ if (data === undefined && view?.data) {
+ const sampleIds = view.data.flatMap(([parentId, children]) => {
+ return children.map((childId) =>
+ typeof childId === "string" ? childId : childId[0]
+ );
+ });
+ onChange(path, sampleIds);
+ }
+ }, [data, view?.data, path, onChange]);
|
||||||||||||||
|
||||||||||||||
// CheckboxView: Represents a single checkbox (either parent or child) | ||||||||||||||
function CheckboxView({ | ||||||||||||||
id, | ||||||||||||||
|
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.
If you are confident this useEffect is no longer needed, you can probably just delete it @lanzhenw - it looks like it is just a console.log() anyway
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.
removed.