Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -47,31 +47,30 @@ export const EmptyPrompts: FC<Props> = ({ allSources, onCancel, children, loadSo
} = useKibana<IndexPatternEditorContext>();

const [remoteClustersExist, setRemoteClustersExist] = useState<boolean>(false);
const [hasCheckedRemoteClusters, setHasCheckedRemoteClusters] = useState<boolean>(false);

const [goToForm, setGoToForm] = useState<boolean>(false);

const hasDataIndices = allSources.some(isUserDataIndex);
const hasUserIndexPattern = useAsync(() =>
indexPatternService.hasUserIndexPattern().catch(() => true)
);

useCallback(() => {
let isMounted = true;
if (!hasDataIndices)
useEffect(() => {
if (!hasDataIndices && !hasCheckedRemoteClusters) {
setHasCheckedRemoteClusters(true);

getIndices({
http,
isRollupIndex: () => false,
pattern: '*:*',
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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ const IndexPatternEditorFlyoutContentComponent = ({
defaultTypeIsRollup,
requireTimestampField = false,
}: Props) => {
const isMounted = useRef<boolean>(false);
const {
services: { http, indexPatternService, uiSettings, searchClient },
} = useKibana<IndexPatternEditorContext>();
Expand Down Expand Up @@ -156,30 +155,23 @@ 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
useEffect(() => {
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
Expand Down Expand Up @@ -214,10 +206,7 @@ const IndexPatternEditorFlyoutContentComponent = ({
);
timestampOptions = extractTimeFields(fields, requireTimestampField);
}
if (
isMounted.current &&
currentLoadingTimestampFieldsIdx === currentLoadingTimestampFieldsRef.current
) {
if (currentLoadingTimestampFieldsIdx === currentLoadingTimestampFieldsRef.current) {
setIsLoadingTimestampFields(false);
setTimestampFieldOptions(timestampOptions);
}
Expand Down Expand Up @@ -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));
Expand All @@ -291,10 +277,6 @@ const IndexPatternEditorFlyoutContentComponent = ({
[http, allowHidden, allSources, type, rollupIndicesCapabilities, searchClient, isLoadingSources]
);

useEffect(() => {
reloadMatchedIndices(title);
}, [allowHidden, reloadMatchedIndices, title]);

const onTypeChange = useCallback(
(newType) => {
form.setFieldValue('title', '');
Expand Down