Skip to content

Commit

Permalink
fixing loading state thanks ashwinpc
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Li <[email protected]>
  • Loading branch information
sejli committed Oct 23, 2024
1 parent 8bd7627 commit 64b5969
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import React, { useEffect, useState } from 'react';
export enum ResultStatus {
UNINITIALIZED = 'uninitialized',
LOADING = 'loading', // initial data load
LOADING_MORE = 'loading_more', // loading additional data while existing results are presents
READY = 'ready', // results came back
NO_RESULTS = 'none', // no results came back
ERROR = 'error', // error occurred
Expand Down Expand Up @@ -59,23 +60,12 @@ export function QueryResult(props: { queryStatus: QueryStatus }) {
};
}, [props.queryStatus.startTime]);

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>
);
if (
props.queryStatus.status === ResultStatus.LOADING ||
props.queryStatus.status === ResultStatus.LOADING_MORE
) {
if (elapsedTime < BUFFER_TIME) {
return null;
}
const time = Math.floor(elapsedTime / 1000);
return (
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/public/ui/query_editor/editors/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export const SingleLineInput: React.FC<SingleLineInputProps> = ({
lineDecorationsWidth: 0,
scrollbar: {
vertical: 'hidden',
horizontalScrollbarSize: 1,
},
overviewRulerLanes: 0,
hideCursorInOverviewRuler: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { trackQueryMetric } from '../../../ui_metric';
export enum ResultStatus {
UNINITIALIZED = 'uninitialized',
LOADING = 'loading', // initial data load
LOADING_MORE = 'loading_more', // loading additional data while existing results are present
READY = 'ready', // results came back
NO_RESULTS = 'none', // no results came back
ERROR = 'error', // error occurred
Expand Down Expand Up @@ -150,6 +151,7 @@ export const useSearch = (services: DiscoverViewServices) => {
if (!dataset) {
data$.next({
status: shouldSearchOnPageLoad() ? ResultStatus.LOADING : ResultStatus.UNINITIALIZED,
queryStatus: { startTime },
});
return;
}
Expand Down Expand Up @@ -181,7 +183,9 @@ export const useSearch = (services: DiscoverViewServices) => {
try {
// Only show loading indicator if we are fetching when the rows are empty
if (fetchStateRef.current.rows?.length === 0) {
data$.next({ status: ResultStatus.LOADING });
data$.next({ status: ResultStatus.LOADING, queryStatus: { startTime } });
} else {
data$.next({ status: ResultStatus.LOADING_MORE, queryStatus: { startTime } });
}

// Initialize inspect adapter for search source
Expand Down Expand Up @@ -293,6 +297,7 @@ export const useSearch = (services: DiscoverViewServices) => {
toastNotifications,
interval,
data,
startTime,
services,
sort,
savedSearch?.searchSource,
Expand Down

0 comments on commit 64b5969

Please sign in to comment.