Skip to content

Commit

Permalink
Keep previous query result if current query result in error (#8863)
Browse files Browse the repository at this point in the history
* keep previous result

Signed-off-by: abbyhu2000 <[email protected]>

* Changeset file for PR #8863 created/updated

* add some comment

Signed-off-by: abbyhu2000 <[email protected]>

* invalid first query shows refresh data page

Signed-off-by: abbyhu2000 <[email protected]>

---------

Signed-off-by: abbyhu2000 <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
(cherry picked from commit bca4f5c)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 6256188 commit 5847721
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/8863.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Keep previous query result if current query result in error ([#8863](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8863))
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,13 @@ export default function DiscoverCanvas({ setHeaderActionMenu, history, optionalR
if (next.bucketInterval && next.bucketInterval !== fetchState.bucketInterval)
shouldUpdateState = true;
if (next.chartData && next.chartData !== fetchState.chartData) shouldUpdateState = true;
// we still want to show rows from the previous query while current query is loading
if (next.status !== ResultStatus.LOADING && next.rows && next.rows !== fetchState.rows) {
// we still want to show rows from the previous query while current query is loading or the current query results in error
if (
next.status !== ResultStatus.LOADING &&
next.status !== ResultStatus.ERROR &&
next.rows &&
next.rows !== fetchState.rows
) {
shouldUpdateState = true;
setRows(next.rows);
}
Expand Down Expand Up @@ -152,20 +157,16 @@ export default function DiscoverCanvas({ setHeaderActionMenu, history, optionalR
timeFieldName={timeField}
/>
)}
{fetchState.status === ResultStatus.ERROR && (
<DiscoverNoResults
queryString={data.query.queryString}
query={data.query.queryString.getQuery()}
savedQuery={data.query.savedQueries}
timeFieldName={timeField}
/>
)}
{fetchState.status === ResultStatus.UNINITIALIZED && (
<DiscoverUninitialized onRefresh={() => refetch$.next()} />
)}
{fetchState.status === ResultStatus.LOADING && !rows?.length && <LoadingSpinner />}
{fetchState.status === ResultStatus.ERROR && !rows?.length && (
<DiscoverUninitialized onRefresh={() => refetch$.next()} />

Check warning on line 165 in src/plugins/discover/public/application/view_components/canvas/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/view_components/canvas/index.tsx#L165

Added line #L165 was not covered by tests
)}
{(fetchState.status === ResultStatus.READY ||
(fetchState.status === ResultStatus.LOADING && !!rows?.length)) &&
(fetchState.status === ResultStatus.LOADING && !!rows?.length) ||
(fetchState.status === ResultStatus.ERROR && !!rows?.length)) &&
(isEnhancementsEnabled ? (
<>
<MemoizedDiscoverChartContainer {...fetchState} />
Expand Down

0 comments on commit 5847721

Please sign in to comment.