From 213ac6a8c762ff3df2473bbbdd7876a681b9e889 Mon Sep 17 00:00:00 2001 From: Anton Dosov Date: Wed, 25 Aug 2021 15:12:58 +0200 Subject: [PATCH 1/3] fix checking remote cluster for empty state --- .../empty_prompts/empty_prompts.tsx | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/plugins/index_pattern_editor/public/components/empty_prompts/empty_prompts.tsx b/src/plugins/index_pattern_editor/public/components/empty_prompts/empty_prompts.tsx index 2f1631694e952..696194d8113c7 100644 --- a/src/plugins/index_pattern_editor/public/components/empty_prompts/empty_prompts.tsx +++ b/src/plugins/index_pattern_editor/public/components/empty_prompts/empty_prompts.tsx @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import React, { useState, useCallback, FC } from 'react'; +import React, { useState, FC, useEffect } from 'react'; import useAsync from 'react-use/lib/useAsync'; import { useKibana } from '../../shared_imports'; @@ -47,6 +47,8 @@ export const EmptyPrompts: FC = ({ allSources, onCancel, children, loadSo } = useKibana(); const [remoteClustersExist, setRemoteClustersExist] = useState(false); + const [hasCheckedRemoteClusters, setHasCheckedRemoteClusters] = useState(false); + const [goToForm, setGoToForm] = useState(false); const hasDataIndices = allSources.some(isUserDataIndex); @@ -54,9 +56,10 @@ export const EmptyPrompts: FC = ({ allSources, onCancel, children, loadSo indexPatternService.hasUserIndexPattern().catch(() => true) ); - useCallback(() => { - let isMounted = true; - if (!hasDataIndices) + useEffect(() => { + if (!hasDataIndices && !hasCheckedRemoteClusters) { + setHasCheckedRemoteClusters(true); + getIndices({ http, isRollupIndex: () => false, @@ -64,14 +67,10 @@ export const EmptyPrompts: FC = ({ allSources, onCancel, children, loadSo showAllIndices: false, searchClient, }).then((dataSources) => { - if (isMounted) { - setRemoteClustersExist(!!dataSources.filter(removeAliases).length); - } + setRemoteClustersExist(!!dataSources.filter(removeAliases).length); }); - return () => { - isMounted = false; - }; - }, [http, hasDataIndices, searchClient]); + } + }, [http, hasDataIndices, searchClient, hasCheckedRemoteClusters]); if (hasUserIndexPattern.loading) return null; // return null to prevent UI flickering while loading From 927bdeef90494fa3f03df537fdd763598a81892c Mon Sep 17 00:00:00 2001 From: Anton Dosov Date: Wed, 25 Aug 2021 15:13:28 +0200 Subject: [PATCH 2/3] remote redundant effect --- .../public/components/index_pattern_editor_flyout_content.tsx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/plugins/index_pattern_editor/public/components/index_pattern_editor_flyout_content.tsx b/src/plugins/index_pattern_editor/public/components/index_pattern_editor_flyout_content.tsx index 0eed74053f667..5c5d01fcb4704 100644 --- a/src/plugins/index_pattern_editor/public/components/index_pattern_editor_flyout_content.tsx +++ b/src/plugins/index_pattern_editor/public/components/index_pattern_editor_flyout_content.tsx @@ -291,10 +291,6 @@ const IndexPatternEditorFlyoutContentComponent = ({ [http, allowHidden, allSources, type, rollupIndicesCapabilities, searchClient, isLoadingSources] ); - useEffect(() => { - reloadMatchedIndices(title); - }, [allowHidden, reloadMatchedIndices, title]); - const onTypeChange = useCallback( (newType) => { form.setFieldValue('title', ''); From 68753743d78c194374bc3b024940271be1f06ad8 Mon Sep 17 00:00:00 2001 From: Anton Dosov Date: Wed, 25 Aug 2021 15:21:40 +0200 Subject: [PATCH 3/3] remove redundant isMounted checks to avoid potential bugs --- .../index_pattern_editor_flyout_content.tsx | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/src/plugins/index_pattern_editor/public/components/index_pattern_editor_flyout_content.tsx b/src/plugins/index_pattern_editor/public/components/index_pattern_editor_flyout_content.tsx index 5c5d01fcb4704..c4d8ed11fe7c2 100644 --- a/src/plugins/index_pattern_editor/public/components/index_pattern_editor_flyout_content.tsx +++ b/src/plugins/index_pattern_editor/public/components/index_pattern_editor_flyout_content.tsx @@ -69,7 +69,6 @@ const IndexPatternEditorFlyoutContentComponent = ({ defaultTypeIsRollup, requireTimestampField = false, }: Props) => { - const isMounted = useRef(false); const { services: { http, indexPatternService, uiSettings, searchClient }, } = useKibana(); @@ -156,19 +155,14 @@ const IndexPatternEditorFlyoutContentComponent = ({ // loading list of index patterns useEffect(() => { - isMounted.current = true; loadSources(); const getTitles = async () => { const indexPatternTitles = await indexPatternService.getTitles(); - if (isMounted.current) { - setExistingIndexPatterns(indexPatternTitles); - setIsLoadingIndexPatterns(false); - } + + setExistingIndexPatterns(indexPatternTitles); + setIsLoadingIndexPatterns(false); }; getTitles(); - return () => { - isMounted.current = false; - }; }, [http, indexPatternService, loadSources]); // loading rollup info @@ -176,10 +170,8 @@ const IndexPatternEditorFlyoutContentComponent = ({ const getRollups = async () => { try { const response = await http.get('/api/rollup/indices'); - if (isMounted.current) { - if (response) { - setRollupIndicesCapabilities(response); - } + if (response) { + setRollupIndicesCapabilities(response); } } catch (e) { // Silently swallow failure responses such as expired trials @@ -214,10 +206,7 @@ const IndexPatternEditorFlyoutContentComponent = ({ ); timestampOptions = extractTimeFields(fields, requireTimestampField); } - if ( - isMounted.current && - currentLoadingTimestampFieldsIdx === currentLoadingTimestampFieldsRef.current - ) { + if (currentLoadingTimestampFieldsIdx === currentLoadingTimestampFieldsRef.current) { setIsLoadingTimestampFields(false); setTimestampFieldOptions(timestampOptions); } @@ -266,10 +255,7 @@ const IndexPatternEditorFlyoutContentComponent = ({ exactMatched: [], }; - if ( - currentLoadingMatchedIndicesIdx === currentLoadingMatchedIndicesRef.current && - isMounted.current - ) { + if (currentLoadingMatchedIndicesIdx === currentLoadingMatchedIndicesRef.current) { // we are still interested in this result if (type === INDEX_PATTERN_TYPE.ROLLUP) { const rollupIndices = exactMatched.filter((index) => isRollupIndex(index.name));