Add cancel function when you select an option in search and navigate away from the optionList#42471
Conversation
| let shouldFailAllRequests = false; | ||
| let shouldForceOffline = false; | ||
|
|
||
| type AbortCommand = 'All' | 'SearchForReports'; |
There was a problem hiding this comment.
I think you can infer this based on API commands (typeof consts) OR 'All'?
| return; | ||
| } | ||
|
|
||
| HttpUtils.cancelPendingRequests('SearchForReports'); |
There was a problem hiding this comment.
I would use the READ_COMMANDS.SEARCH_FOR_REPORTS
|
|
||
| function cancelPendingRequests() { | ||
| cancellationController.abort(); | ||
| function cancelPendingRequests(command: AbortCommand = 'All') { |
There was a problem hiding this comment.
Probably would be good to add a new const in I would use the READ_COMMANDS object
This comment has been minimized.
This comment has been minimized.
| SearchForReports: READ_COMMANDS.SEARCH_FOR_REPORTS, | ||
| } as const; | ||
|
|
||
| type AbortCommand = (typeof ABORT_COMMANDS)[keyof typeof ABORT_COMMANDS]; |
There was a problem hiding this comment.
I think this can be simplified with
type AbortCommand = keyof typeof ABORT_COMMANDS;
|
|
||
| const ABORT_COMMANDS = { | ||
| All: 'All', | ||
| SearchForReports: READ_COMMANDS.SEARCH_FOR_REPORTS, |
There was a problem hiding this comment.
Do we want to keep the names in sync? if true probably something like this is better
const ABORT_COMMANDS = {
All: 'All',
[READ_COMMANDS.SEARCH_FOR_REPORTS]: READ_COMMANDS.SEARCH_FOR_REPORTS,
} as const;
|
@rinej Can you merge main please? |
|
@mountiny Can you run an ad hoc build here to test this on physical device? |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, Desktop, and Web. Happy testing! 🧪🧪 |
|
@rinej I am unable to see any API request for Edit - nvm, now it is showing API request. |
Reviewer Checklist
Screenshots/VideosAndroid: NativeAndroid: mWeb ChromeScreen.Recording.2024-05-30.at.5.25.16.PM.moviOS: NativeScreen.Recording.2024-05-30.at.8.35.03.PM.moviOS: mWeb SafariScreen.Recording.2024-05-30.at.5.11.44.PM.movMacOS: Chrome / SafariScreen.Recording.2024-05-30.at.5.02.24.PM.mp4MacOS: DesktopScreen.Recording.2024-05-30.at.8.07.58.PM.mov |
|
🚀 Deployed to production by https://github.com/Julesssss in version: 1.4.79-11 🚀
|
Details
Issue:
Currently, when you use search in New Expensify, we show results progressively and put the "best result" at the top. However a query for the full optionList always finishes after you've started it, even if you navigate away from the page that is performing the command.
Proposal
We implemented the feature using the AbortController mechanism, which is part of the Fetch API. We created a dedicated AbortController for the SearchForReports command. This allows us to precisely control the cancellation of requests associated with this particular operation without affecting other asynchronous tasks. When selecting a report and initiating navigation, the AbortController associated with SearchForReports is triggered to cancel the requests. This ensures that ONLY pending search operations are stopped immediately.
If necessary this feature can be extended in the future by adding additional abort controllers.
Cancel_Api.mp4
Fixed Issues
$ #42384
PROPOSAL: https://callstack-hq.slack.com/archives/C05R2V5GM1S/p1716455384907969
Tests
Offline tests
QA Steps
Additionally you can check that any pending requests for SearchForReports are cancelled (see the above video for details)
Repeat above steps for RHL
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)myBool && <MyComponent />.src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))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
cancel-android.mp4
Android: mWeb Chrome
cancel-android-web.mp4
iOS: Native
cancel-ios.mp4
iOS: mWeb Safari
cancel-ios-web.mp4
MacOS: Chrome / Safari
cancel-web.mp4
MacOS: Desktop
cancel-desktop.mp4