-
Notifications
You must be signed in to change notification settings - Fork 8.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
[Security Solution][Case] Improve hooks #89580
Conversation
Pinging @elastic/security-solution (Team: SecuritySolution) |
Pinging @elastic/security-threat-hunting (Team:Threat Hunting) |
e988d60
to
1ddae60
Compare
1ddae60
to
4155a16
Compare
4155a16
to
e84d47d
Compare
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.
Hi! This is Ece, new hire on Threat Intelligence. This is my first review! I will keep it comment only until I get ramped up - I would sincerely appreciate a review of my review :)
Reading through the changes, I had a couple of thoughts
- naming of
didCancel
usually booleans are prefixed with is, so if didCancel remained a boolean, I would have suggested a name such asisCancelled
. However it looks like didCancel became a ref. In React docs refs are usually indicated with aRef
suffix (myRef, inputRef in Refs and the DOM) this is by no means necessary, but I personally like having that visual indicator as a reminder to always read.current
of something that is clearly afooRef
. Therefore, I think thatdidCancel
could also be calleddidCancelRef
or evenisCancelledRef
- whichever works best. - reoccurence and similar usage of
didCancel
andabortCtrl
refs
it looks like we could create a new hook that encapsulates the declaration ofdidCancel
andabortCtrl
refs, as well as the cleanup func, which could be used in multiple hooks that are being tidied up in this PR. In fact,[isLoading, setIsLoading]
could also be a part of the new hook, which could be called something along the lines ofuseAbortableRequest
. error.name !== 'AbortError'
check
it looks like we always check!didCancel.current
beforehand, so if the request is aborted, we won't be executing this block anyway, so the check seems useless unless there is any other scenario in which a request can get aborted outside of the cleanup with the AbortCtrl call.- cancelToken
I am not particularly familiar with this codebase - with a quick look, it looks like the AbortController is creating an event called "abort", and 'things' get set in motion from thereon. I would have assumed that a cancelToken would be generated when the request is being made, and that cancelToken could be called to cancel the request if the user navigated away from the page, instead of an AbortController call to take care if this - I would be very happy to learn more about this pattern. I am assuming that the abort event is being caught by a middleware, will follow up with this to broaden my understanding.
Hey! Welcome to the team Ece! Feel free to leave comments on the code.
Ok!
I think this is a scenario where duplication is better than deduplication. The reason is that
I had the same thought at first 😄! Imagine a user clicks a button to submit and then press the button again very fast before the first request has been fulfilled. In this scenario the first call will be canceled, as we
|
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.
Agree that these hooks and many others in the plugin seem like there is ample opportunity for a shared hook or two to remove some of the identical code, but this fixes the loading bug and bug with no cleanup logic running when the consuming component is destroyed so lgtm 👍
@elasticmachine merge upstream |
merge conflict between base and head |
e84d47d
to
eab13e7
Compare
@elasticmachine merge upstream |
@elasticmachine merge upstream |
41b2535
to
f8c4468
Compare
💚 Build SucceededMetrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: cc @cnasikas |
# Conflicts: # x-pack/plugins/security_solution/public/cases/containers/use_bulk_update_case.tsx
…tiple-searchable-snapshot-actions * 'master' of github.com:elastic/kibana: [Rollup] Fix use of undefined value in JS import (elastic#92791) [ILM] Fix replicas not showing (elastic#92782) [Event Log] Extended README.md with the documentation for a REST API and Start plugin contract. (elastic#92562) [XY] Enables page reload toast for the legacyChartsLibrary setting (elastic#92811) [Security Solution][Case] Improve hooks (elastic#89580) [Security Solution] Update wordings and breadcrumb for timelines page (elastic#90809) [Security Solution] Replace EUI theme with mocks in jest suites (elastic#92462) docs: ✏️ use correct heading level (elastic#92806) [ILM ] Fix logic for showing/hiding recommended allocation on Cloud (elastic#90592) [Security Solution][Detections] Pull gap detection logic out in preparation for sharing between rule types (elastic#91966) [core.savedObjects] Remove _shard_doc tiebreaker since ES now adds it automatically. (elastic#92295) docs: ✏️ fix links in embeddable plugin readme (elastic#92778) # Conflicts: # x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/shared_fields/searchable_snapshot_field/searchable_snapshot_field.tsx
# Conflicts: # x-pack/plugins/security_solution/public/cases/containers/use_bulk_update_case.tsx Co-authored-by: Kibana Machine <[email protected]>
Summary
We found a problem around our paradigm in case hooks. The problem was that useCallback does not know when a component is going unmounted, however useEffect does know all the secrets/ life cycle of a component therefore we are taking advantage of it.
Checklist
Delete any items that are not applicable to this PR.
For maintainers