+
();
+
const kibana = useKibana();
const { uiSettings, data, usageCollection, appName } = kibana.services;
const reportUiCounter = usageCollection?.reportUiCounter.bind(usageCollection, appName);
@@ -39,6 +41,14 @@ export const FilterEditorWrapper = React.memo(function FilterEditorWrapper({
const [newFilter, setNewFilter] = useState(undefined);
const isPinned = uiSettings!.get(UI_SETTINGS.FILTERS_PINNED_BY_DEFAULT);
+ useEffect(() => {
+ fetchIndexAbortController.current = new AbortController();
+
+ return () => {
+ fetchIndexAbortController.current?.abort();
+ };
+ }, []);
+
useEffect(() => {
const fetchDataViews = async () => {
const stringPatterns = indexPatterns?.filter(
@@ -48,15 +58,22 @@ export const FilterEditorWrapper = React.memo(function FilterEditorWrapper({
(indexPattern) => typeof indexPattern !== 'string'
) as DataView[];
+ fetchIndexAbortController.current?.abort();
+ fetchIndexAbortController.current = new AbortController();
+ const currentFetchIndexAbortController = fetchIndexAbortController.current;
+
const objectPatternsFromStrings = (await fetchIndexPatterns(
data.dataViews,
stringPatterns.map((value) => ({ type: 'title', value }))
)) as DataView[];
- setDataviews([...objectPatterns, ...objectPatternsFromStrings]);
- const [dataView] = [...objectPatterns, ...objectPatternsFromStrings];
- const index = dataView && dataView.id;
- const emptyFilter = buildEmptyFilter(isPinned, index);
- setNewFilter(emptyFilter);
+
+ if (!currentFetchIndexAbortController.signal.aborted) {
+ setDataviews([...objectPatterns, ...objectPatternsFromStrings]);
+ const [dataView] = [...objectPatterns, ...objectPatternsFromStrings];
+ const index = dataView && dataView.id;
+ const emptyFilter = buildEmptyFilter(isPinned, index);
+ setNewFilter(emptyFilter);
+ }
};
if (indexPatterns) {
fetchDataViews();
diff --git a/src/plugins/unified_search/public/query_string_input/query_bar_menu.tsx b/src/plugins/unified_search/public/query_string_input/query_bar_menu.tsx
index da3ecd7771cbf..6f7609e781655 100644
--- a/src/plugins/unified_search/public/query_string_input/query_bar_menu.tsx
+++ b/src/plugins/unified_search/public/query_string_input/query_bar_menu.tsx
@@ -168,6 +168,7 @@ export function QueryBarMenu({