From 581020f02fe5b59e914a36ae8633136cc8020f19 Mon Sep 17 00:00:00 2001 From: Kristen Tian Date: Fri, 21 Oct 2022 17:24:30 -0700 Subject: [PATCH] Apply get indice error handling in step index pattern Error handling only happens before loading the indices to step index pattern but not within. Therefore pass the error handling inside the step as well to render error state. Signed-off-by: Kristen Tian --- CHANGELOG.md | 1 + .../create_index_pattern_wizard.test.tsx.snap | 4 + .../step_index_pattern.test.tsx | 7 ++ .../step_index_pattern/step_index_pattern.tsx | 76 ++++++++++++------- .../create_index_pattern_wizard.tsx | 1 + 5 files changed, 63 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 924aa5280c9e..bda140ef0480 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) * [Multi DataSource] Address UX comments on Edit Data source page ([#2629](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2629)) * [BUG] Fix suggestion list cutoff issue ([#2607](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2607)) * [Multi DataSource] Address UX comments on index pattern management stack ([#2611](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2611)) +* [Multi DataSource] Apply get indices error handling in step index pattern ([#2652](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2652)) ### 🚞 Infrastructure diff --git a/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/__snapshots__/create_index_pattern_wizard.test.tsx.snap b/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/__snapshots__/create_index_pattern_wizard.test.tsx.snap index 1546eda9b552..c27e4d7c1487 100644 --- a/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/__snapshots__/create_index_pattern_wizard.test.tsx.snap +++ b/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/__snapshots__/create_index_pattern_wizard.test.tsx.snap @@ -39,6 +39,7 @@ exports[`CreateIndexPatternWizard renders index pattern step when there are indi }, ] } + catchAndWarn={[Function]} goToNextStep={[Function]} goToPreviousStep={[Function]} indexPatternCreationType={ @@ -90,6 +91,7 @@ exports[`CreateIndexPatternWizard renders the empty state when there are no indi {}; +const catchAndWarn = jest.fn((asyncFn) => asyncFn); const mockContext = mockManagementPlugin.createIndexPatternManagmentContext(); @@ -94,6 +95,7 @@ describe('StepIndexPattern', () => { goToNextStep, indexPatternCreationType: mockIndexPatternCreationType, initialQuery: 'opensearch-dashboards', + catchAndWarn, }, mockContext ); @@ -116,6 +118,7 @@ describe('StepIndexPattern', () => { isIncludingSystemIndices: false, goToNextStep, indexPatternCreationType: mockIndexPatternCreationType, + catchAndWarn, }, mockContext ); @@ -139,6 +142,7 @@ describe('StepIndexPattern', () => { isIncludingSystemIndices: false, goToNextStep, indexPatternCreationType: mockIndexPatternCreationType, + catchAndWarn, }, mockContext ); @@ -163,6 +167,7 @@ describe('StepIndexPattern', () => { isIncludingSystemIndices: false, goToNextStep, indexPatternCreationType: mockIndexPatternCreationType, + catchAndWarn, }, mockContext ); @@ -179,6 +184,7 @@ describe('StepIndexPattern', () => { isIncludingSystemIndices: false, goToNextStep, indexPatternCreationType: mockIndexPatternCreationType, + catchAndWarn, }, mockContext ); @@ -194,6 +200,7 @@ describe('StepIndexPattern', () => { isIncludingSystemIndices: false, goToNextStep, indexPatternCreationType: mockIndexPatternCreationType, + catchAndWarn, }, mockContext ); diff --git a/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.tsx b/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.tsx index e42fc3218dd2..76e47b0875e5 100644 --- a/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.tsx +++ b/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.tsx @@ -28,7 +28,7 @@ * under the License. */ -import React, { Component } from 'react'; +import React, { Component, ReactElement } from 'react'; import { EuiSpacer, EuiCallOut, @@ -65,6 +65,11 @@ interface StepIndexPatternProps { showSystemIndices: boolean; dataSourceRef?: DataSourceRef; stepInfo: StepInfo; + catchAndWarn: ( + asyncFn: Promise, + errorValue: [] | string[], + errorMsg: ReactElement + ) => Promise; } interface StepIndexPatternState { @@ -165,7 +170,7 @@ export class StepIndexPattern extends Component { - const { indexPatternCreationType, dataSourceRef } = this.props; + const { indexPatternCreationType, dataSourceRef, catchAndWarn } = this.props; const dataSourceId = dataSourceRef?.id; const { existingIndexPatterns } = this.state; const { http } = this.context.services; @@ -180,16 +185,27 @@ export class StepIndexPattern extends Component + ); + if (query.endsWith('*')) { const exactMatchedIndices = await ensureMinimumTime( - getIndices({ - http, - getIndexTags, - pattern: query, - showAllIndices, - searchClient, - dataSourceId, - }) + catchAndWarn( + getIndices({ + http, + getIndexTags, + pattern: query, + showAllIndices, + searchClient, + dataSourceId, + }), + [], + indicesFailMsg + ) ); // If the search changed, discard this state if (query !== this.lastQuery) { @@ -200,22 +216,30 @@ export class StepIndexPattern extends Component );