-
Notifications
You must be signed in to change notification settings - Fork 589
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: TreeSelectionView component handles grid selection sync #5077
Conversation
WalkthroughThe Changes
Possibly related PRs
Suggested labels
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (2)
app/packages/core/src/plugins/SchemaIO/components/TreeSelectionView.tsx (2)
223-295
: Ensure efficient synchronization between grid selection and checkbox treeThe
useEffect
hook appropriately updates thecheckedState
whendata
andunboundState
differ, ensuring that selections made in the grid are reflected in the tree. However, consider verifying the performance of this effect with large datasets to prevent potential slowdowns. Optimizing the synchronization logic can enhance user experience.
330-333
: Consider removingnodeId
from the displayed title to avoid exposing internal identifiersIncluding
nodeId
in thetitle
may expose internal identifiers to users, which could be unnecessary or potentially confusing. It might be better to display only user-friendly information.Apply this diff to adjust the
title
:const title = `Group ${getGroupIdx( nodeId, structure - )} • ${count} Samples • ${nodeId}`; + )} • ${count} Samples`;
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
app/packages/core/src/plugins/SchemaIO/components/TreeSelectionView.tsx
(7 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/packages/core/src/plugins/SchemaIO/components/TreeSelectionView.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.
🔇 Additional comments (1)
app/packages/core/src/plugins/SchemaIO/components/TreeSelectionView.tsx (1)
383-395
: Verify that the expand/collapse icon reflects the corrected allCollapsed
state
After fixing the logic in handleExpandCollapseAll
, ensure that the IconButton
displays the appropriate icon based on the updated allCollapsed
state. This will accurately represent the current state and expected action (expand or collapse all) to the user.
const [allCollapsed, setAllCollapsed] = React.useState(false); | ||
|
||
const handleExpandCollapseAll = () => { | ||
setCollapsedState((prevState) => { | ||
const newState = { ...prevState }; | ||
Object.keys(newState).forEach((key) => { | ||
newState[key] = allCollapsed; | ||
}); | ||
return newState; | ||
}); | ||
setAllCollapsed(!allCollapsed); // Toggle the expand/collapse state | ||
}; |
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.
Fix the toggle logic in handleExpandCollapseAll
to correctly expand/collapse all nodes
The handleExpandCollapseAll
function currently sets the collapsed state of all nodes to the current allCollapsed
value and then toggles allCollapsed
. This results in the nodes reflecting the previous state instead of the intended new state after the button is clicked. To correctly toggle the collapse state, you should first compute the new allCollapsed
value and then apply it to all nodes.
Apply this diff to fix the logic:
const handleExpandCollapseAll = () => {
+ const newAllCollapsed = !allCollapsed;
+ setAllCollapsed(newAllCollapsed); // Toggle the expand/collapse state
setCollapsedState((prevState) => {
const newState = { ...prevState };
Object.keys(newState).forEach((key) => {
- newState[key] = allCollapsed;
+ newState[key] = newAllCollapsed;
});
return newState;
});
- setAllCollapsed(!allCollapsed); // Toggle the expand/collapse state
};
📝 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.
const [allCollapsed, setAllCollapsed] = React.useState(false); | |
const handleExpandCollapseAll = () => { | |
setCollapsedState((prevState) => { | |
const newState = { ...prevState }; | |
Object.keys(newState).forEach((key) => { | |
newState[key] = allCollapsed; | |
}); | |
return newState; | |
}); | |
setAllCollapsed(!allCollapsed); // Toggle the expand/collapse state | |
}; | |
const [allCollapsed, setAllCollapsed] = React.useState(false); | |
const handleExpandCollapseAll = () => { | |
const newAllCollapsed = !allCollapsed; | |
setAllCollapsed(newAllCollapsed); // Toggle the expand/collapse state | |
setCollapsedState((prevState) => { | |
const newState = { ...prevState }; | |
Object.keys(newState).forEach((key) => { | |
newState[key] = newAllCollapsed; | |
}); | |
return newState; | |
}); | |
}; |
* implement the grid change on checkboxes * implement style tweak and add expand/collapse all button
What changes are proposed in this pull request?
Bugfix:
How is this patch tested? If it is not, please explain why.
Created a dataset with 200 groups of duplicate samples. Selection in the grid is captured in the grid. expansion works.
Screen.Recording.2024-11-07.at.9.39.36.PM.mov
Release Notes
Is this a user-facing change that should be mentioned in the release notes?
notes for FiftyOne users.
(Details in 1-2 sentences. You can just refer to another PR with a description
if this PR is part of a larger change.)
What areas of FiftyOne does this PR affect?
fiftyone
Python library changesSummary by CodeRabbit
New Features
Improvements
TreeNode
component for clearer context.These changes significantly improve user interaction with the tree structure, making it easier to manage selections.