Skip to content

Commit

Permalink
PoC for shared Analytics no data view
Browse files Browse the repository at this point in the history
  • Loading branch information
ryankeairns committed Sep 16, 2021
1 parent 70632e2 commit cac4d50
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import React, { useCallback, useEffect } from 'react';
import { History } from 'history';
import React, { useCallback, useState, useEffect } from 'react';
import { AnalyticsNoData } from '../../../../../kibana_react/public';
import { DiscoverLayout } from './components/layout';
import { setBreadcrumbsTitle } from '../../helpers/breadcrumbs';
import { addHelpMenuToAppChrome } from '../../components/help_menu/help_menu_util';
Expand Down Expand Up @@ -38,8 +39,10 @@ export interface DiscoverMainProps {
}

export function DiscoverMainApp(props: DiscoverMainProps) {
const [isNewKibanaInstance, setNewKibanaInstance] = useState(false);
const { services, history, indexPatternList } = props;
const { chrome, docLinks, uiSettings: config, data } = services;
const indexPatternService = data.indexPatterns;
const navigateTo = useCallback(
(path: string) => {
history.push(path);
Expand Down Expand Up @@ -96,7 +99,20 @@ export function DiscoverMainApp(props: DiscoverMainProps) {
resetSavedSearch(savedSearch.id);
}, [resetSavedSearch, savedSearch]);

return (
/**
* Check if any user indices exist
*/
useEffect(() => {
const fetchIsNewKibanaInstance = async () => {
const hasUserIndexPattern = await indexPatternService.hasUserIndexPattern().catch(() => true);

setNewKibanaInstance(!hasUserIndexPattern);
};

fetchIsNewKibanaInstance();
}, [indexPatternService]);

return isNewKibanaInstance ? (
<DiscoverLayoutMemoized
indexPattern={indexPattern}
indexPatternList={indexPatternList}
Expand All @@ -113,5 +129,7 @@ export function DiscoverMainApp(props: DiscoverMainProps) {
state={state}
stateContainer={stateContainer}
/>
) : (
<AnalyticsNoData />
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import React from 'react';

import { i18n } from '@kbn/i18n';
import { DocLinksStart, HttpStart } from 'src/core/public';
import { KibanaPageTemplate, KibanaPageTemplateProps } from '../';
import { useKibana } from '../../../../kibana_react/public';

export function AnalyticsNoData() {
const { services } = useKibana<{ docLinks: DocLinksStart; http: HttpStart }>();

const noDataConfig: KibanaPageTemplateProps['noDataConfig'] = {
solution: i18n.translate('kibanaOverview.noDataConfig.solutionName', {
defaultMessage: `Analytics`,
}),
logo: 'logoKibana',
actions: {
beats: {
href: services.http.basePath.prepend(`home#/tutorial_directory`),
},
},
docsLink: services.docLinks.links.kibana,
};

return <KibanaPageTemplate noDataConfig={noDataConfig} template="empty" />;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export { AnalyticsNoData } from './analytics_no_data';
1 change: 1 addition & 0 deletions src/plugins/kibana_react/public/page_template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
export { KibanaPageTemplate, KibanaPageTemplateProps } from './page_template';
export { KibanaPageTemplateSolutionNavAvatar } from './solution_nav';
export * from './no_data_page';
export { AnalyticsNoData } from './analytics_no_data';

0 comments on commit cac4d50

Please sign in to comment.