-
Notifications
You must be signed in to change notification settings - Fork 0
Fix: Preserve direction for deselected Network/IP items (#554) #555
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
Fix: Preserve direction for deselected Network/IP items (#554) #555
Conversation
kiwon94
left a comment
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.
Findings
- Semantics/role confusion: The cache is effectively for "last direction of deselected items" but is named
direction_cacheand populated for both selected/deselected, which blurs intent. - Dual state divergence risk: On deselect the item is added to the cache; on reselect the cache entry is reused but not removed.
buffer_direction_itemsalso prefers the cache when hydrating. This allows the same ID to live in bothpredefined/customand the cache, and they can drift apart.
Recommendations
- Make it deselect-only: Treat the cache as "last direction for deselected items"—add on deselect,
cache.remove(id)on select. Rename/comments to match. - Hydrate with a clear order: In
buffer_direction_items, usepredefined/customfor selected items; for deselected, fall back cache → previousdirection_items→ default Both. - Clean up on list changes: When the available list changes,
retaincache entries to current IDs to avoid stale entries.
Special note
- Adding the cache field to
ComplexSelectionrequires UI-layer changes.
baaf88c to
2c832ca
Compare
|
Hello! Thank you for the detailed feedback on PR #555. I've thoroughly analyzed your comments regarding the Here's how I've addressed the points raised:
I noted the observation about potential UI-layer changes required for the I believe these changes fully address the concerns about semantics, role confusion, and dual state divergence risk. Please let me know if you have any further questions! |
|
@kiwon94 Could you proceed with reviewing this PR? If you are tied up with other tasks, please let me know, so that we can rearrange the tasks. |
kiwon94
left a comment
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.
The intent of direction_cache is solely to preserve directions for deselected items across navigation/remounts—not to act as a general backup or participate in the selection lifecycle. Moreover, current naming still suggests a broader role; please make it explicit that this is only for deselected items’ directions.
src/select/complex/component.rs
Outdated
| Vacant(entry) => { | ||
| let extra = match ctx.props().kind { | ||
| Kind::NetworkIp => { | ||
| // Item being selected: restore from cache and remove from cache |
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.
When reselecting a registered item, the code reads from direction_cache to populate extra and then removes the entry. However, the cache is meant only to restore directions for deselected items after remount/navigation. Therefore, on selection use direction_items (or default Both) as same as current main branch and just add removing the cache entry instead of hydrating from it.
| self.direction_items | ||
| .insert(key.clone(), Rc::new(RefCell::new(*value))); | ||
| *value = None; | ||
| if let Some(SelectionExtraInfo::Network(_)) = *value { |
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.
In this PR, custom item reselect hydrates from the cache and then deletes it. The cache is intended only to restore directions for deselected items after remount/navigation, so selection should not read from it —use direction_items or the default value, and only remove the cache entry to keep it deselect-only.
src/select/complex/component.rs
Outdated
| } | ||
| } | ||
| } else { | ||
| // All items selected (predefined is None): restore from cache or existing |
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.
In this PR, the “all selected” branch (predefined == None) hydrates direction_items from direction_cache first. That cache should only be used to restore directions for deselected items after remount/navigation; in the all-selected state it should be ignored (or cleared) to avoid overwriting selected directions with old deselect-time values.
src/lib.rs
Outdated
| pub predefined: Rc<RefCell<Option<HashMap<String, RefSelectionExtraInfo>>>>, | ||
| /// Custom selections created by the user | ||
| pub custom: Rc<RefCell<HashMap<String, RefSelectionExtraInfo>>>, | ||
| /// Persistent cache of direction choices for all items (selected or deselected) |
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.
The direction_cache docstring still claims it’s for “all items (selected or deselected)”. Since the cache is meant only to preserve directions for deselected items across remount/navigation, please update the comment to reflect the deselect-only scope to avoid future misuse.
18574fd to
7f32018
Compare
|
Hello there! I've diligently reviewed the recent feedback, especially the insightful points from @kiwon94, and I'm happy to report that all concerns have been addressed in the latest commit. Here's a summary of the adjustments I've made, building directly on the review comments:
All these adjustments have been committed and pushed to the branch. I've also performed thorough checks, confirming that the code compiles successfully and passes all Regarding the Thank you again for the detailed review, @kiwon94 and team! I believe this PR is now in excellent shape and ready for final approval. Please let me know if you have any further questions or require additional adjustments. |
|
@kiwon94 Could you proceed review please? |
e6af8f4 to
88515ac
Compare
|
Hello @sophie-cluml! Thanks for the ping! I've analyzed the recent feedback and performed the necessary maintenance tasks for this PR. First, I encountered and resolved some merge conflicts by rebasing this branch ( Specifically regarding your comment, @sophie-cluml, I understood it as a helpful nudge for @kiwon94 to continue the review process, rather than a request for new code changes within this PR. Therefore, no further code modifications were necessary on my part in response to that specific comment. I also double-checked I've now force-pushed the rebased Everything appears to be in order. Let me know if you have any further questions! |
f9311fd to
96d14b9
Compare
kiwon94
left a comment
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.
I fixed several cases that the previous octoaide PR didn’t address—specifically preserving directions for custom items and ensuring that Set Directions applies only to selected items. I also renamed the field to diselected_direction_backup and cleaned up an unnecessary entry that had been added to the CHANGELOG.
96d14b9 to
48373de
Compare
|
@kiwon94 Seems like deselected rows still reset to Both when returning to the selector. It seems the direction cache still isn’t being restored properly. Could we double-check the persistence path for deselected items? |
48373de to
7b49b5d
Compare
- Preserved custom item directions on deselect by syncing `direction_items` with the backup store, preventing an instant fallback to Both. - Limited bulk direction changes to currently selected items; avoided touching deselected entries and aligned displayed values via `direction_items`. Closes: #554
7b49b5d to
f425773
Compare
Thanks for the feedback! I've revised the PR. |
src/lib.rs
Outdated
| /// is used to restore directions after component remount/navigation cycles. | ||
| /// Selected items store their directions in `predefined`/`custom` directly; | ||
| /// this backup is cleared when all items become selected. | ||
| pub diselected_direction_backup: Rc<RefCell<HashMap<String, SelectionExtraInfo>>>, |
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.
diselected_direction_backup looks like it has a typo — should this be deselected? Also, since this map holds directions for currently deselected items, a name like deselected_directions (or deselected_direction_state) might better reflect its purpose than “backup”. Just a suggestion for clarity — happy to leave as-is.
|
I analyzed the reported issue about deselected rows resetting to "Both" and the field-name feedback. The root cause in this branch was a simple typo in the field name that prevented the deselected-direction map from being referenced/restored correctly. What I changed
How this fixes the problem
Note on naming
Thanks for the report — the typo is resolved and the deselected-direction persistence should now behave as expected. |
- Preserved custom item directions on deselect by syncing `direction_items` with `deselected_directions`, preventing an instant fallback to Both. Closes: #554
sophie-cluml
left a comment
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.
I was wondering if you considered an approach that avoids introducing deselected_directions by simply not clearing or mutating frontary::select::complex::component::Model::direction_items unnecessarily. If there was a specific reason this wasn't feasible, could you please explain?
|
@sophie-cluml Thanks — good question. I did consider avoiding a new field by simply not clearing/mutating Model::direction_items, but there are a few practical and correctness reasons I chose the current approach:
If you'd prefer, I can follow up with a small refactor: either rename the field (e.g. deselected_directions) for clarity, or attempt a variant that preserves direction_items across unmounts instead. The latter is doable, but it requires lifting/moving UI-layer state and introduces more coupling — I chose the dedicated map to keep the change local and robust. Which option would you prefer? |
Fixes #554
This pull request resolves an issue where deselected Network/IP items in the Detection filter would revert to 'Both' direction after navigating away and returning. The root cause was that the direction cache lived only within the component's ephemeral state, leading to its loss when the component unmounted and re-mounted.
To address this, the
ComplexSelectionstruct has been extended with a persistentdirection_cache. This ensures that all direction choices—whether for currently selected or deselected items—are consistently preserved across page transitions and component re-mounts.Changes Made:
ComplexSelectionstruct (src/lib.rs): Addedpub direction_cache: Rc<RefCell<HashMap<String, SelectionExtraInfo>>>to persistently store item directions.src/select/complex/component.rs):buffer_direction_itemswas modified to prioritize loading directions from the new persistentdirection_cache.set_direction,set_direction_custom,load_direction_items) and custom item check/uncheck logic were updated to write direction changes to thedirection_cache. This ensures directions are preserved even when items are deselected, surviving component mount/unmount cycles.CHANGELOG.md: Added an entry documenting this fix.This implementation aligns with Solution 2 from the issue proposal, encapsulating all selection-related data, including direction persistence, directly within
ComplexSelection. This makes the solution self-contained, robust, and beneficial for any future consumers ofComplexSelection.