Skip to content

Commit 76d30ec

Browse files
authored
Apply get indice error handling in step index pattern (#2652)
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 <tyarong@amazon.com>
1 parent 68baac1 commit 76d30ec

File tree

5 files changed

+63
-26
lines changed

5 files changed

+63
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
3939
* [Multi DataSource] Address UX comments on Edit Data source page ([#2629](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2629))
4040
* [BUG] Fix suggestion list cutoff issue ([#2607](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2607))
4141
* [Multi DataSource] Address UX comments on index pattern management stack ([#2611](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2611))
42+
* [Multi DataSource] Apply get indices error handling in step index pattern ([#2652](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2652))
4243

4344
### 🚞 Infrastructure
4445

src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/__snapshots__/create_index_pattern_wizard.test.tsx.snap

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.test.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const allIndices = [
6262
];
6363

6464
const goToNextStep = () => {};
65+
const catchAndWarn = jest.fn(async (asyncFn) => await asyncFn);
6566

6667
const mockContext = mockManagementPlugin.createIndexPatternManagmentContext();
6768

@@ -94,6 +95,7 @@ describe('StepIndexPattern', () => {
9495
goToNextStep,
9596
indexPatternCreationType: mockIndexPatternCreationType,
9697
initialQuery: 'opensearch-dashboards',
98+
catchAndWarn,
9799
},
98100
mockContext
99101
);
@@ -116,6 +118,7 @@ describe('StepIndexPattern', () => {
116118
isIncludingSystemIndices: false,
117119
goToNextStep,
118120
indexPatternCreationType: mockIndexPatternCreationType,
121+
catchAndWarn,
119122
},
120123
mockContext
121124
);
@@ -139,6 +142,7 @@ describe('StepIndexPattern', () => {
139142
isIncludingSystemIndices: false,
140143
goToNextStep,
141144
indexPatternCreationType: mockIndexPatternCreationType,
145+
catchAndWarn,
142146
},
143147
mockContext
144148
);
@@ -163,6 +167,7 @@ describe('StepIndexPattern', () => {
163167
isIncludingSystemIndices: false,
164168
goToNextStep,
165169
indexPatternCreationType: mockIndexPatternCreationType,
170+
catchAndWarn,
166171
},
167172
mockContext
168173
);
@@ -179,6 +184,7 @@ describe('StepIndexPattern', () => {
179184
isIncludingSystemIndices: false,
180185
goToNextStep,
181186
indexPatternCreationType: mockIndexPatternCreationType,
187+
catchAndWarn,
182188
},
183189
mockContext
184190
);
@@ -194,6 +200,7 @@ describe('StepIndexPattern', () => {
194200
isIncludingSystemIndices: false,
195201
goToNextStep,
196202
indexPatternCreationType: mockIndexPatternCreationType,
203+
catchAndWarn,
197204
},
198205
mockContext
199206
);

src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.tsx

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* under the License.
2929
*/
3030

31-
import React, { Component } from 'react';
31+
import React, { Component, ReactElement } from 'react';
3232
import {
3333
EuiSpacer,
3434
EuiCallOut,
@@ -65,6 +65,11 @@ interface StepIndexPatternProps {
6565
showSystemIndices: boolean;
6666
dataSourceRef?: DataSourceRef;
6767
stepInfo: StepInfo;
68+
catchAndWarn: (
69+
asyncFn: Promise<MatchedItem[]>,
70+
errorValue: [] | string[],
71+
errorMsg: ReactElement
72+
) => Promise<unknown>;
6873
}
6974

7075
interface StepIndexPatternState {
@@ -165,7 +170,7 @@ export class StepIndexPattern extends Component<StepIndexPatternProps, StepIndex
165170
};
166171

167172
fetchIndices = async (query: string) => {
168-
const { indexPatternCreationType, dataSourceRef } = this.props;
173+
const { indexPatternCreationType, dataSourceRef, catchAndWarn } = this.props;
169174
const dataSourceId = dataSourceRef?.id;
170175
const { existingIndexPatterns } = this.state;
171176
const { http } = this.context.services;
@@ -180,16 +185,27 @@ export class StepIndexPattern extends Component<StepIndexPatternProps, StepIndex
180185

181186
this.setState({ isLoadingIndices: true, indexPatternExists: false });
182187

188+
const indicesFailMsg = (
189+
<FormattedMessage
190+
id="indexPatternManagement.createIndexPattern.loadIndicesFailMsg"
191+
defaultMessage="Failed to load indices"
192+
/>
193+
);
194+
183195
if (query.endsWith('*')) {
184196
const exactMatchedIndices = await ensureMinimumTime(
185-
getIndices({
186-
http,
187-
getIndexTags,
188-
pattern: query,
189-
showAllIndices,
190-
searchClient,
191-
dataSourceId,
192-
})
197+
catchAndWarn(
198+
getIndices({
199+
http,
200+
getIndexTags,
201+
pattern: query,
202+
showAllIndices,
203+
searchClient,
204+
dataSourceId,
205+
}),
206+
[],
207+
indicesFailMsg
208+
)
193209
);
194210
// If the search changed, discard this state
195211
if (query !== this.lastQuery) {
@@ -200,22 +216,30 @@ export class StepIndexPattern extends Component<StepIndexPatternProps, StepIndex
200216
}
201217

202218
const [partialMatchedIndices, exactMatchedIndices] = await ensureMinimumTime([
203-
getIndices({
204-
http,
205-
getIndexTags,
206-
pattern: `${query}*`,
207-
showAllIndices,
208-
searchClient,
209-
dataSourceId,
210-
}),
211-
getIndices({
212-
http,
213-
getIndexTags,
214-
pattern: query,
215-
showAllIndices,
216-
searchClient,
217-
dataSourceId,
218-
}),
219+
catchAndWarn(
220+
getIndices({
221+
http,
222+
getIndexTags,
223+
pattern: `${query}*`,
224+
showAllIndices,
225+
searchClient,
226+
dataSourceId,
227+
}),
228+
[],
229+
indicesFailMsg
230+
),
231+
catchAndWarn(
232+
getIndices({
233+
http,
234+
getIndexTags,
235+
pattern: query,
236+
showAllIndices,
237+
searchClient,
238+
dataSourceId,
239+
}),
240+
[],
241+
indicesFailMsg
242+
),
219243
]);
220244

221245
// If the search changed, discard this state

src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/create_index_pattern_wizard.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ export class CreateIndexPatternWizard extends Component<
317317
}
318318
dataSourceRef={dataSourceRef}
319319
stepInfo={stepInfo}
320+
catchAndWarn={this.catchAndWarn}
320321
/>
321322
</EuiPageContent>
322323
);

0 commit comments

Comments
 (0)