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

Fix random big number during loading in query editor result #8650

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/8650.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Fix random big number when loading in query result ([#8650](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8650))
Copy link
Member

Choose a reason for hiding this comment

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

Can we stop the setInterval when the query is not running?

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 useEffect returns the clearInterval method so it will no longer triggers every second after the component unmounts

Original file line number Diff line number Diff line change
Expand Up @@ -41,40 +41,39 @@
setPopover(!isPopoverOpen);
};

const updateElapsedTime = () => {
const time = Date.now() - (props.queryStatus.startTime || 0);
if (time > BUFFER_TIME) {
setElapsedTime(time);
} else {
setElapsedTime(0);
}
};

useEffect(() => {
const updateElapsedTime = () => {
const currentTime = Date.now();

Check warning on line 46 in src/plugins/data/public/query/query_string/language_service/lib/query_result.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/query_string/language_service/lib/query_result.tsx#L46

Added line #L46 was not covered by tests
if (!props.queryStatus.startTime) {
return;

Check warning on line 48 in src/plugins/data/public/query/query_string/language_service/lib/query_result.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/query_string/language_service/lib/query_result.tsx#L48

Added line #L48 was not covered by tests
}
const elapsed = currentTime - props.queryStatus.startTime;
setElapsedTime(elapsed);

Check warning on line 51 in src/plugins/data/public/query/query_string/language_service/lib/query_result.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/query_string/language_service/lib/query_result.tsx#L50-L51

Added lines #L50 - L51 were not covered by tests
};

const interval = setInterval(updateElapsedTime, 1000);

return () => clearInterval(interval);
});

if (props.queryStatus.status === ResultStatus.LOADING) {
if (elapsedTime < BUFFER_TIME) {
return null;
if (elapsedTime > BUFFER_TIME) {
if (props.queryStatus.status === ResultStatus.LOADING) {
const time = Math.floor(elapsedTime / 1000);
return (

Check warning on line 62 in src/plugins/data/public/query/query_string/language_service/lib/query_result.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/query_string/language_service/lib/query_result.tsx#L61-L62

Added lines #L61 - L62 were not covered by tests
<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"
>
{i18n.translate('data.query.languageService.queryResults.loadTime', {
defaultMessage: 'Loading {time} s',
values: { time },
})}
</EuiButtonEmpty>
);
}

if (props.queryStatus.status === ResultStatus.READY) {
Expand All @@ -85,7 +84,7 @@
});
} else if (props.queryStatus.elapsedMs < 1000) {
message = i18n.translate(
'data.query.languageService.queryResults.completeTimeInMiliseconds',
'data.query.languageService.queryResults.completeTimeInMilliseconds',
{
defaultMessage: 'Completed in {timeMS} ms',
values: { timeMS: props.queryStatus.elapsedMs },
Expand Down
Loading