Skip to content
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

[Discover] Decouple data$ updates to prevent rows clearing on hook re-render #8806

Merged

Conversation

joshuali925
Copy link
Member

@joshuali925 joshuali925 commented Nov 4, 2024

Description

While #8552 is fixed by not letting query automatically run again, updating selected field still clears all rows in discover. This happens because any re-render to hook useSearch will clear data$ by creating a new observable.

This PR fixes it by decoupling update logic based on dependencies.

Issues Resolved

#8552

Screenshot

No UI change

Testing the changes

i don't see UT for useSearch, @LDrago27 could you take a look if they will break anything?

Changelog

  • fix: decouple data$ updates to prevent rows clearing on hook re-render

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

Copy link
Contributor

github-actions bot commented Nov 4, 2024

❌ Empty Changelog Section

The Changelog section in your PR description is empty. Please add a valid changelog entry or entries. If you did add a changelog entry, check to make sure that it was not accidentally included inside the comment block in the Changelog section.

@joshuali925 joshuali925 marked this pull request as draft November 4, 2024 22:14
@joshuali925 joshuali925 marked this pull request as ready for review November 4, 2024 22:45
Copy link

codecov bot commented Nov 4, 2024

Codecov Report

Attention: Patch coverage is 87.50000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 60.87%. Comparing base (78204a0) to head (9dd86ac).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
...public/query/timefilter/timefilter_service.mock.ts 66.66% 1 Missing ⚠️
...ic/application/view_components/utils/use_search.ts 90.90% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8806      +/-   ##
==========================================
+ Coverage   60.78%   60.87%   +0.08%     
==========================================
  Files        3798     3799       +1     
  Lines       90701    90761      +60     
  Branches    14284    14294      +10     
==========================================
+ Hits        55135    55248     +113     
+ Misses      32067    32004      -63     
- Partials     3499     3509      +10     
Flag Coverage Δ
Linux_1 29.04% <0.00%> (-0.01%) ⬇️
Linux_2 56.39% <ø> (ø)
Linux_3 37.81% <87.50%> (+0.15%) ⬆️
Linux_4 29.87% <0.00%> (+0.04%) ⬆️
Windows_1 29.06% <0.00%> (-0.01%) ⬇️
Windows_2 56.34% <ø> (ø)
Windows_3 37.81% <87.50%> (+0.14%) ⬆️
Windows_4 29.87% <0.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ashwin-pc
Copy link
Member

@joshuali925 can you add a UT atleast for your part of the change?

Signed-off-by: Joshua Li <[email protected]>
Signed-off-by: Joshua Li <[email protected]>
Comment on lines +172 to +184
useEffect(() => {
data$.next({ ...data$.value, queryStatus: { startTime } });
}, [data$, startTime]);

useEffect(() => {
data$.next({
...data$.value,
status:
shouldSearchOnPageLoad() && !skipInitialFetch.current
? ResultStatus.LOADING
: ResultStatus.UNINITIALIZED,
});
}, [data$, shouldSearchOnPageLoad, skipInitialFetch]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why this is separated into two useEffect()'s? If mimicking the original useMemo(), could be done in a single update and reduce the number of useEffects().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

startTime updates should only update queryStatus.startTime and not reset status. it's the bug this PR is trying to fix, we should decouple queryStatus and status updates

Signed-off-by: Joshua Li <[email protected]>
getTimeUpdate$: jest.fn(),
getRefreshIntervalUpdate$: jest.fn(),
getTimeUpdate$: jest.fn(() => new Observable<unknown>()),
getRefreshIntervalUpdate$: jest.fn(() => new Observable<unknown>()),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not related to this pr, but think we need update codecov config to ignore mocks

@joshuali925 joshuali925 merged commit e664cd0 into opensearch-project:main Nov 7, 2024
68 of 69 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Nov 7, 2024
…re-render (#8806)

Signed-off-by: Joshua Li <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
(cherry picked from commit e664cd0)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
joshuali925 pushed a commit that referenced this pull request Nov 8, 2024
…re-render (#8806) (#8829)

(cherry picked from commit e664cd0)

Signed-off-by: Joshua Li <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants