-
Notifications
You must be signed in to change notification settings - Fork 590
Convert SearchTracePage/SearchForm to functional component #3078
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
base: main
Are you sure you want to change the base?
Convert SearchTracePage/SearchForm to functional component #3078
Conversation
Signed-off-by: JeevaRamanathan <[email protected]>
How to use the Graphite Merge QueueAdd the label merge-queue to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3078 +/- ##
==========================================
- Coverage 97.92% 97.88% -0.05%
==========================================
Files 260 260
Lines 8162 8162
Branches 2151 2124 -27
==========================================
- Hits 7993 7989 -4
- Misses 169 173 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| changeServiceHandler(fieldData.service); | ||
| setFormData(prevState => ({ | ||
| ...prevState, | ||
| operation: DEFAULT_OPERATION, | ||
| })); |
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.
There's a potential race condition in the service selection logic. Currently, when a service is selected, two separate setFormData calls occur in sequence:
- First call updates the service field
- Second call resets the operation to
DEFAULT_OPERATION
Since React state updates are batched and asynchronous, the second update might not see the changes from the first update, potentially causing inconsistent state.
Consider combining both updates into a single setFormData call:
setFormData(prevState => ({
...prevState,
...fieldData,
operation: fieldData.service ? DEFAULT_OPERATION : prevState.operation
}));This ensures both the service update and operation reset happen atomically in a single state update.
| changeServiceHandler(fieldData.service); | |
| setFormData(prevState => ({ | |
| ...prevState, | |
| operation: DEFAULT_OPERATION, | |
| })); | |
| setFormData(prevState => ({ | |
| ...prevState, | |
| ...fieldData, | |
| operation: fieldData.service ? DEFAULT_OPERATION : prevState.operation | |
| })); |
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
packages/jaeger-ui/src/components/SearchTracePage/SearchForm.jsx
Outdated
Show resolved
Hide resolved
packages/jaeger-ui/src/components/SearchTracePage/SearchForm.jsx
Outdated
Show resolved
Hide resolved
| expect(operationOnChange).toBeDefined(); | ||
| operationOnChange('testOperation'); | ||
| expect(handleChangeMock).toHaveBeenCalledWith({ operation: 'testOperation' }); | ||
| expect(operationOnChange).toBeDefined(); |
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.
how is this equivalent to checking that the handler was called?
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.
Yeah I agree, after converting to a functional component, the handleChangeMock is not working properly with the current implementation. I'll check again. Your guidance on the section would be appreciated.
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 @yurishkuro, I have updated this retaining the same check. Can you please check and let know if this looks good or any further changes is required
yurishkuro
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.
it is unusual to change unit tests when performing migration to functional component. It may indicate that you're breaking the functionality.
Signed-off-by: JeevaRamanathan <[email protected]>
|
Hi @yurishkuro, jaeger-ui/packages/jaeger-ui/src/components/SearchTracePage/SearchForm.test.js Lines 432 to 435 in 30a402d
jaeger-ui/packages/jaeger-ui/src/components/SearchTracePage/SearchForm.test.js Lines 520 to 534 in 30a402d
Yeah, but in few cases like above test changes were necessary because those tests were directly extending the SearchForm class and accessing internal methods; when converting to a functional component, these class-based patterns don't work anymore since there's no class to extend or this context to access and the tests were failing. |
Signed-off-by: JeevaRamanathan <[email protected]>
how? |
I manually tested the SearchForm with various inputs, verified correct functionality, results, and layout visually, and also ran the test suite. Please let me know if anything was missed |
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. You may re-open it if you need more time. |
| ); | ||
| } | ||
|
|
||
| SearchFormImpl.propTypes = { |
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.
why is this needed? normally functional components are just pure functions
Which problem is this PR solving?
Description of the changes
packages/jaeger-ui/src/components/SearchTracePage/SearchForm.jsxfrom class to functional and improved test cases.How was this change tested?
Checklist
jaeger:make lint testjaeger-ui:npm run lintandnpm run test