[Search] Clear selections when sorting to prevent stale selection state#72334
Conversation
Solution UpdateHey! So while fixing this bug, I discovered something interesting. The original issue was that selections got misaligned because we were using unsorted data to build the selection state, but showing sorted data in the UI. Easy fix, right? Just use But then I realized: when you sort, it's not just reordering - it's actually fetching fresh data from the backend. Which means the data could be completely different (new expenses added, some deleted, etc.). So keeping selections doesn't really make sense anymore. The user thinks they have 50 items selected, but some might not even exist in the new result set. New approach: When sorting changes, just clear all selections. Clean state, fresh start. Here is a video pointing out to what i mean and the behaviour in the new solution Screen.Recording.2025-10-10.at.15.52.20.movlet me know what you think about tihs approach @techievivek @eVoloshchak @cead22 |
Codecov Report❌ Patch coverage is
... and 6 files with indirect coverage changes 🚀 New features to boost your workflow:
|
|
there seems to be an issue with the assigned c+ reviewer shouldnt it be @eVoloshchak ? cc @techievivek |
I agree with this, and was thinking this should be the approach when I saw the issue before I read your comment 👍 |
Agree with this too. We already clear the selection when a new search text is entered, sorting is conceptually the same, we're just changing the search query |
|
Great .. working on it today. |
|
@eVoloshchak Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
| const clearSelectedTransactions: SearchContextProps['clearSelectedTransactions'] = useCallback( | ||
| (searchHashOrClearIDsFlag, shouldTurnOffSelectionMode = false) => { | ||
| if (typeof searchHashOrClearIDsFlag === 'boolean') { | ||
| setSelectedTransactions([]); |
There was a problem hiding this comment.
What is the limitation of passing an empty array to setSelectedTransactions? It looks like it's supposed to set selectedTransactionIDs automatically.
Can we modify setSelectedTransactions instead?
There was a problem hiding this comment.
setSelectedTransactions([]) alone was not working, so I needed to add setSearchContextData.
however after merging latest main, setSelectedTransactions already handles this internally. so i reverted this change
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppScreen.Recording.2025-11-04.at.15.15.41.movAndroid: mWeb ChromeScreen.Recording.2025-11-04.at.15.11.03.moviOS: HybridAppScreen.Recording.2025-11-04.at.15.16.05.moviOS: mWeb SafariScreen.Recording.2025-11-04.at.15.17.11.movMacOS: Chrome / SafariScreen.Recording.2025-11-04.at.15.07.44.movMacOS: DesktopScreen.Recording.2025-11-04.at.15.20.19.mov |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/cead22 in version: 9.2.45-0 🚀
|
|
🚀 Deployed to production by https://github.com/luacmartins in version: 9.2.45-6 🚀
|
Explanation of Change
Fixed Issues
$ #70594
PROPOSAL: #70594 (comment)
Tests
Preconditions: Account with atleast 50 expenses
Offline tests
Same as tests
QA Steps
Same as tests
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectioncanBeMissingparam foruseOnyxtoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Not applicable on mobile
Screen.Recording.2025-10-27.at.18.13.37.mov
Android: mWeb Chrome
Not applicable on mobile
Screen.Recording.2025-10-27.at.18.19.39.mov
iOS: Native
Not applicable on mobile
Screen.Recording.2025-10-27.at.18.04.03.mov
iOS: mWeb Safari
Not applicable on mobile
Screen.Recording.2025-10-27.at.18.23.48.mov
MacOS: Chrome / Safari
Screen.Recording.2025-10-27.at.18.00.44.mov
MacOS: Desktop
Screen.Recording.2025-10-27.at.18.39.05.mov