-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add cancel function when you select an option in search and navigate away from the optionList #42471
Add cancel function when you select an option in search and navigate away from the optionList #42471
Conversation
src/libs/HttpUtils.ts
Outdated
@@ -14,6 +14,8 @@ import HttpsError from './Errors/HttpsError'; | |||
let shouldFailAllRequests = false; | |||
let shouldForceOffline = false; | |||
|
|||
type AbortCommand = 'All' | 'SearchForReports'; |
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 think you can infer this based on API commands
(typeof consts) OR 'All'?
src/pages/ChatFinderPage/index.tsx
Outdated
@@ -143,6 +144,8 @@ function ChatFinderPage({betas, isSearchingForReports, navigation}: ChatFinderPa | |||
return; | |||
} | |||
|
|||
HttpUtils.cancelPendingRequests('SearchForReports'); |
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 would use the READ_COMMANDS.SEARCH_FOR_REPORTS
src/libs/HttpUtils.ts
Outdated
} | ||
|
||
function cancelPendingRequests() { | ||
cancellationController.abort(); | ||
function cancelPendingRequests(command: AbortCommand = 'All') { |
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.
Probably would be good to add a new const in I would use the READ_COMMANDS object
Running a build https://github.com/Expensify/App/actions/runs/9205926408 |
This comment has been minimized.
This comment has been minimized.
src/libs/HttpUtils.ts
Outdated
SearchForReports: READ_COMMANDS.SEARCH_FOR_REPORTS, | ||
} as const; | ||
|
||
type AbortCommand = (typeof ABORT_COMMANDS)[keyof typeof ABORT_COMMANDS]; |
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 think this can be simplified with
type AbortCommand = keyof typeof ABORT_COMMANDS;
src/libs/HttpUtils.ts
Outdated
import * as ApiUtils from './ApiUtils'; | ||
import HttpsError from './Errors/HttpsError'; | ||
|
||
let shouldFailAllRequests = false; | ||
let shouldForceOffline = false; | ||
|
||
const ABORT_COMMANDS = { | ||
All: 'All', | ||
SearchForReports: READ_COMMANDS.SEARCH_FOR_REPORTS, |
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.
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;
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.
thanks! Good point!
@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 |
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.
Thanks @rinej changes look good to me
🚀 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 Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label and/or tagged@Expensify/design
so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.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