Skip to content

Commit

Permalink
keep previous query result if current query result in error
Browse files Browse the repository at this point in the history
Signed-off-by: abbyhu2000 <[email protected]>
  • Loading branch information
abbyhu2000 committed Nov 13, 2024
1 parent 25d3de7 commit 01b8e71
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,10 @@ export default function DiscoverCanvas({ setHeaderActionMenu, history, optionalR
/>
)}
{fetchState.status === ResultStatus.ERROR && (
<DiscoverNoResults
queryString={data.query.queryString}
query={data.query.queryString.getQuery()}
savedQuery={data.query.savedQueries}
timeFieldName={timeField}
/>
<>
<MemoizedDiscoverChartContainer {...fetchState} />
<MemoizedDiscoverTable rows={rows} scrollToTop={scrollToTop} />
</>
)}
{fetchState.status === ResultStatus.UNINITIALIZED && (
<DiscoverUninitialized onRefresh={() => refetch$.next()} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ export const useSearch = (services: DiscoverViewServices) => {
dataset = searchSource.getField('index');

let elapsedMs;
let hits;
let rows;
let bucketInterval = {};
let chartData;
try {
// Only show loading indicator if we are fetching when the rows are empty
if (fetchStateRef.current.rows?.length === 0) {
Expand Down Expand Up @@ -254,11 +258,9 @@ export const useSearch = (services: DiscoverViewServices) => {
inspectorRequest
.stats(getResponseInspectorStats(fetchResp, searchSource))
.ok({ json: fetchResp });
const hits = fetchResp.hits.total as number;
const rows = fetchResp.hits.hits;
hits = fetchResp.hits.total as number;
rows = fetchResp.hits.hits;
elapsedMs = inspectorRequest.getTime();
let bucketInterval = {};
let chartData;
for (const row of rows) {
const fields = Object.keys(dataset!.flattenHit(row));
for (const fieldName of fields) {
Expand Down Expand Up @@ -322,12 +324,23 @@ export const useSearch = (services: DiscoverViewServices) => {
}
}

// We push the error status to the data$ subject so that the error can be displayed in the query editor footer
// Still push the previous search results since we want to keep the previous query result if the current query result in error
data$.next({
status: ResultStatus.ERROR,
queryStatus: {
body: { error: errorBody },
elapsedMs,
},
fieldCounts: fetchStateRef.current.fieldCounts,
hits,
rows,
bucketInterval,
chartData,
title:
indexPattern?.title !== searchSource.getDataFrame()?.name
? searchSource.getDataFrame()?.name
: indexPattern?.title,
});
} finally {
initalSearchComplete.current = true;
Expand Down

0 comments on commit 01b8e71

Please sign in to comment.