Skip to content

Commit

Permalink
Code polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Maja Grubic committed Jan 26, 2022
1 parent 5f46ef4 commit 65b8cd8
Showing 1 changed file with 12 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,29 +60,23 @@ export function DiscoverMainRoute({ services, history }: DiscoverMainProps) {
core.application.navigateToApp('kibanaOverview', { path: '#' });
}, [core.application]);

useEffect(() => {
const fetchIsNewKibanaInstance = async () => {
const hasUserIndexPattern = await data.dataViews.hasUserDataView().catch(() => true);

if (!hasUserIndexPattern) {
navigateToOverview();
}
};

fetchIsNewKibanaInstance();
}, [data.dataViews, navigateToOverview]);
const checkForDataViews = useCallback(async () => {
const hasUserDataView = await data.dataViews.hasUserDataView().catch(() => true);
if (!hasUserDataView) {
navigateToOverview();
}
const defaultDataView = await data.dataViews.getDefaultDataView();
if (!defaultDataView) {
navigateToOverview();
}
}, [navigateToOverview, data.dataViews]);

useEffect(() => {
const savedSearchId = id;

async function loadDefaultOrCurrentIndexPattern(searchSource: ISearchSource) {
try {
const defaultDataView = await data.dataViews.getDefaultDataView();
const hasUserDataView = await data.dataViews.hasUserDataView().catch(() => true);
if (!defaultDataView || !hasUserDataView) {
navigateToOverview();
return;
}
await checkForDataViews();
const { appStateContainer } = getState({ history, uiSettings: config });
const { index } = appStateContainer.getState();
const ip = await loadIndexPattern(index || '', data.indexPatterns, config);
Expand Down Expand Up @@ -165,8 +159,7 @@ export function DiscoverMainRoute({ services, history }: DiscoverMainProps) {
services,
toastNotifications,
core.theme,
data.dataViews,
navigateToOverview,
checkForDataViews,
]);

useEffect(() => {
Expand Down

0 comments on commit 65b8cd8

Please sign in to comment.