Skip to content

Commit

Permalink
Fix random big number during loading in query editor result (opensear…
Browse files Browse the repository at this point in the history
…ch-project#8650)

* Fix random big number during loading in query editor result

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>

* Changeset file for PR opensearch-project#8650 created/updated

* Fix initial loading number

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>

---------

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
1 parent e23f332 commit a7414f0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
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))
Original file line number Diff line number Diff line change
Expand Up @@ -41,40 +41,42 @@ export function QueryResult(props: { queryStatus: QueryStatus }) {
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();
if (!props.queryStatus.startTime) {
return;
}
const elapsed = currentTime - props.queryStatus.startTime;
setElapsedTime(elapsed);
};

const interval = setInterval(updateElapsedTime, 1000);

return () => clearInterval(interval);
});
return () => {
clearInterval(interval);
setElapsedTime(0);
};
}, [props.queryStatus.startTime]);

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 (
<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 +87,7 @@ export function QueryResult(props: { queryStatus: QueryStatus }) {
});
} 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

0 comments on commit a7414f0

Please sign in to comment.