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] Fix discover query loading state #8832

Merged
merged 2 commits into from
Nov 14, 2024

Conversation

joshuali925
Copy link
Member

@joshuali925 joshuali925 commented Nov 8, 2024

Description

Duplicated code was introduced by #8565 to run the same logic regardless of if condition, possibly due to merge conflict?

if (props.queryStatus.status === ResultStatus.LOADING) {
const time = Math.floor(elapsedTime / 1000);
return (
<EuiButtonEmpty
color="text"
size="xs"
onClick={() => {}}
isLoading
data-test-subj="queryResultLoading"
>
{i18n.translate('data.query.languageService.queryResults.loadTime', {
defaultMessage: 'Loading {time} s',
values: { time },
})}
</EuiButtonEmpty>
);
}
const time = Math.floor(elapsedTime / 1000);
return (
<EuiButtonEmpty
color="text"
size="xs"
onClick={() => {}}
isLoading
data-test-subj="queryResultLoading"
className="editor__footerItem"
>
{i18n.translate('data.query.languageService.queryResults.loadTime', {
defaultMessage: 'Loading {time} s',
values: { time },
})}
</EuiButtonEmpty>
);

It causes UI to show loading even when status is not loading. This PR fixes it

Additionally, this PR changes loading behavior to be

  1. when there are no results, running the query shows loading in query editor footer and below
  2. when there are results, running the query shows loading in query editor footer with previous query results

Issues Resolved

Screenshot

Testing the changes

Changelog

  • skip

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

sejli
sejli previously approved these changes Nov 8, 2024
Copy link

codecov bot commented Nov 8, 2024

Codecov Report

Attention: Patch coverage is 22.22222% with 7 lines in your changes missing coverage. Please review.

Project coverage is 60.87%. Comparing base (aa60870) to head (3c1a512).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
...ublic/application/view_components/canvas/index.tsx 0.00% 4 Missing ⚠️
...ic/application/view_components/utils/use_search.ts 33.33% 2 Missing ⚠️
...query_string/language_service/lib/query_result.tsx 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8832   +/-   ##
=======================================
  Coverage   60.86%   60.87%           
=======================================
  Files        3799     3799           
  Lines       90761    90757    -4     
  Branches    14294    14291    -3     
=======================================
+ Hits        55246    55248    +2     
+ Misses      32005    32000    -5     
+ Partials     3510     3509    -1     
Flag Coverage Δ
Linux_1 29.05% <0.00%> (+<0.01%) ⬆️
Linux_2 56.39% <ø> (ø)
Linux_3 37.81% <22.22%> (+<0.01%) ⬆️
Linux_4 29.87% <0.00%> (+<0.01%) ⬆️
Windows_1 29.06% <0.00%> (+<0.01%) ⬆️
Windows_2 56.34% <ø> (ø)
Windows_3 37.81% <22.22%> (+<0.01%) ⬆️
Windows_4 29.87% <0.00%> (+<0.01%) ⬆️

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.

@joshuali925 joshuali925 marked this pull request as draft November 8, 2024 01:33
@joshuali925 joshuali925 marked this pull request as ready for review November 8, 2024 03:30
@joshuali925 joshuali925 changed the title [Discover] Fix loading status when uninitialized [Discover] Fix discover query loading state Nov 8, 2024
@@ -155,7 +155,7 @@ export const useSearch = (services: DiscoverViewServices) => {
.getUpdates$()
.pipe(
pairwise(),
filter(([prev, curr]) => prev.dataset?.id === curr.dataset?.id)
filter(([prev, curr]) => prev.dataset?.id !== curr.dataset?.id)
Copy link
Member

Choose a reason for hiding this comment

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

Why do we change this logic here? @joshuali925

Copy link
Member Author

Choose a reason for hiding this comment

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

the logic was accidentally reversed due to testing, we want to reset data$ to initial state when two datasets are different (meaning user changed dataset), not when they are the same

if (fetchStateRef.current.rows?.length === 0) {
data$.next({ status: ResultStatus.LOADING, queryStatus: { startTime } });
}
data$.next({ status: ResultStatus.LOADING, queryStatus: { startTime: currentTime } });
Copy link
Member

Choose a reason for hiding this comment

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

So we wish to always to show loading indicator no matter if the rows are empty or not?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes

)}
{fetchState.status === ResultStatus.LOADING && !rows?.length && <LoadingSpinner />}
{(fetchState.status === ResultStatus.READY ||
(fetchState.status === ResultStatus.LOADING && !!rows?.length)) &&
Copy link
Member

Choose a reason for hiding this comment

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

why do we have two different result for loading status now?

Copy link
Member Author

Choose a reason for hiding this comment

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

we want to show results if query finished and results are ready, or if there are previous results while current query is loading

@abbyhu2000 abbyhu2000 merged commit c20c041 into opensearch-project:main Nov 14, 2024
71 of 73 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Nov 14, 2024
* [Discover] Fix loading status when uninitialized

Signed-off-by: Joshua Li <[email protected]>

* fix discover loading state

Signed-off-by: Joshua Li <[email protected]>

---------

Signed-off-by: Joshua Li <[email protected]>
(cherry picked from commit c20c041)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
ashwin-pc pushed a commit that referenced this pull request Nov 14, 2024
* [Discover] Fix loading status when uninitialized



* fix discover loading state



---------


(cherry picked from commit c20c041)

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
all-star-contributor backport 2.x discover for discover reinvent discover-next Skip-Changelog PRs that are too trivial to warrant a changelog or release notes entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants