-
Notifications
You must be signed in to change notification settings - Fork 584
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 <jeevaramanathan.m@infosys.com>
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 98.14% 98.09% -0.05%
==========================================
Files 257 257
Lines 8065 8065
Branches 2031 2033 +2
==========================================
- Hits 7915 7911 -4
- Misses 150 154 +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
|
||
const operationOnChange = SearchableSelect.onChangeFns.operation; | ||
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
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 <jeevaramanathan.m@infosys.com>
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 <jeevaramanathan.m@infosys.com>
how? |
Which problem is this PR solving?
Description of the changes
packages/jaeger-ui/src/components/SearchTracePage/SearchForm.jsx
from class to functional and improved test cases.How was this change tested?
Checklist
jaeger
:make lint test
jaeger-ui
:npm run lint
andnpm run test