Skip to content

Commit fafc0d4

Browse files
Add AbortController to fetchFields and change translation id in annotations_editor
1 parent 129ad49 commit fafc0d4

File tree

3 files changed

+36
-24
lines changed

3 files changed

+36
-24
lines changed

src/plugins/vis_type_timeseries/public/application/components/annotations_editor.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export class AnnotationsEditor extends Component {
129129
helpText={
130130
defaultIndexPattern &&
131131
!model.index_pattern &&
132-
i18n.translate('visTypeTimeseries.indexPattern.searchByDefaultIndex', {
132+
i18n.translate('visTypeTimeseries.annotationsEditor.searchByDefaultIndex', {
133133
defaultMessage: 'Default index pattern is used. To query all indexes use *',
134134
})
135135
}

src/plugins/vis_type_timeseries/public/application/components/vis_editor.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ import { Storage } from '../../../../../plugins/kibana_utils/public';
3636
const VIS_STATE_DEBOUNCE_DELAY = 200;
3737
const APP_NAME = 'VisEditor';
3838

39-
const debouncedFetchFields = debounce(
40-
(extractedIndexPatterns) => fetchFields(extractedIndexPatterns),
41-
VIS_STATE_DEBOUNCE_DELAY,
42-
{ leading: true }
43-
);
44-
4539
export class VisEditor extends Component {
4640
constructor(props) {
4741
super(props);
@@ -82,6 +76,19 @@ export class VisEditor extends Component {
8276
});
8377
}, VIS_STATE_DEBOUNCE_DELAY);
8478

79+
fetchFields = debounce(
80+
(extractedIndexPatterns) => {
81+
if (this.abortControllerFetchFields) {
82+
this.abortControllerFetchFields.abort();
83+
}
84+
this.abortControllerFetchFields = new AbortController();
85+
86+
return fetchFields(extractedIndexPatterns, this.abortControllerFetchFields.signal);
87+
},
88+
VIS_STATE_DEBOUNCE_DELAY,
89+
{ leading: true }
90+
);
91+
8592
handleChange = (partialModel) => {
8693
if (isEmpty(partialModel)) {
8794
return;
@@ -100,7 +107,7 @@ export class VisEditor extends Component {
100107

101108
const extractedIndexPatterns = extractIndexPatterns(nextModel);
102109
if (!isEqual(this.state.extractedIndexPatterns, extractedIndexPatterns)) {
103-
debouncedFetchFields(extractedIndexPatterns).then((visFields) =>
110+
this.fetchFields(extractedIndexPatterns).then((visFields) =>
104111
this.setState({
105112
visFields,
106113
extractedIndexPatterns,

src/plugins/vis_type_timeseries/public/application/lib/fetch_fields.js

+21-16
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,38 @@ import { extractIndexPatterns } from '../../../common/extract_index_patterns';
2121
import { getCoreStart } from '../../services';
2222
import { ROUTES } from '../../../common/constants';
2323

24-
export async function fetchFields(indexPatterns = []) {
24+
export async function fetchFields(indexPatterns = [], signal) {
2525
const patterns = Array.isArray(indexPatterns) ? indexPatterns : [indexPatterns];
2626
try {
2727
const indexFields = await Promise.all(
28-
patterns.map((pattern) => {
29-
return getCoreStart().http.get(ROUTES.FIELDS, {
28+
patterns.map((pattern) =>
29+
getCoreStart().http.get(ROUTES.FIELDS, {
3030
query: {
3131
index: pattern,
3232
},
33-
});
34-
})
33+
signal,
34+
})
35+
)
3536
);
36-
const fields = patterns.reduce((cumulatedFields, currentPattern, index) => {
37-
return {
37+
38+
return patterns.reduce(
39+
(cumulatedFields, currentPattern, index) => ({
3840
...cumulatedFields,
3941
[currentPattern]: indexFields[index],
40-
};
41-
}, {});
42-
return fields;
43-
} catch (error) {
44-
getCoreStart().notifications.toasts.addDanger({
45-
title: i18n.translate('visTypeTimeseries.fetchFields.loadIndexPatternFieldsErrorMessage', {
46-
defaultMessage: 'Unable to load index_pattern fields',
4742
}),
48-
text: error.message,
49-
});
43+
{}
44+
);
45+
} catch (error) {
46+
if (error.name !== 'AbortError') {
47+
getCoreStart().notifications.toasts.addDanger({
48+
title: i18n.translate('visTypeTimeseries.fetchFields.loadIndexPatternFieldsErrorMessage', {
49+
defaultMessage: 'Unable to load index_pattern fields',
50+
}),
51+
text: error.message,
52+
});
53+
}
5054
}
55+
return [];
5156
}
5257

5358
export async function fetchIndexPatternFields({ params, fields = {} }) {

0 commit comments

Comments
 (0)