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 @@ -39,8 +39,9 @@ type Params = Pick<NoDataPageProps, 'solution' | 'logo'> & DataServiceFactoryCon

export const PureComponent = (params: Params) => {
const { solution, logo, hasESData, hasUserDataView } = params;

const serviceParams = { hasESData, hasUserDataView, hasDataViews: false };
const services = servicesFactory(serviceParams);
const services = servicesFactory({ ...serviceParams, hasESData, hasUserDataView });
return (
<SharedUxServicesProvider {...services}>
<KibanaNoDataPage
Expand All @@ -51,6 +52,26 @@ export const PureComponent = (params: Params) => {
);
};

export const PureComponentLoadingState = () => {
const dataCheck = () => new Promise<boolean>((resolve, reject) => {});
const services = {
...servicesFactory({ hasESData: false, hasUserDataView: false, hasDataViews: false }),
data: {
hasESData: dataCheck,
hasUserDataView: dataCheck,
hasDataView: dataCheck,
},
};
return (
<SharedUxServicesProvider {...services}>
<KibanaNoDataPage
onDataViewCreated={action('onDataViewCreated')}
noDataConfig={noDataConfig}
/>
</SharedUxServicesProvider>
);
};

PureComponent.argTypes = {
solution: {
control: 'text',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import React from 'react';
import { act } from 'react-dom/test-utils';

import { EuiLoadingElastic } from '@elastic/eui';
import { mountWithIntl } from '@kbn/test-jest-helpers';
import { SharedUxServicesProvider, mockServicesFactory } from '@kbn/shared-ux-services';

Expand Down Expand Up @@ -68,4 +69,28 @@ describe('Kibana No Data Page', () => {
expect(component.find(NoDataViews).length).toBe(1);
expect(component.find(NoDataConfigPage).length).toBe(0);
});

test('renders loading indicator', async () => {
const dataCheck = () => new Promise<boolean>((resolve, reject) => {});
const services = {
...mockServicesFactory(),
data: {
hasESData: dataCheck,
hasUserDataView: dataCheck,
hasDataView: dataCheck,
},
};
const component = mountWithIntl(
<SharedUxServicesProvider {...services}>
<KibanaNoDataPage noDataConfig={noDataConfig} onDataViewCreated={onDataViewCreated} />
</SharedUxServicesProvider>
);

await act(() => new Promise(setImmediate));
component.update();

expect(component.find(EuiLoadingElastic).length).toBe(1);
expect(component.find(NoDataViews).length).toBe(0);
expect(component.find(NoDataConfigPage).length).toBe(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/
import React, { useEffect, useState } from 'react';
import { EuiLoadingElastic } from '@elastic/eui';
import { useData } from '@kbn/shared-ux-services';
import { NoDataConfigPage, NoDataPageProps } from '../page_template';
import { NoDataViews } from './no_data_views';
Expand All @@ -17,19 +18,27 @@ export interface Props {

export const KibanaNoDataPage = ({ onDataViewCreated, noDataConfig }: Props) => {
const { hasESData, hasUserDataView } = useData();
const [isLoading, setIsLoading] = useState(true);
const [dataExists, setDataExists] = useState(false);
const [hasUserDataViews, setHasUserDataViews] = useState(false);

useEffect(() => {
const checkData = async () => {
setDataExists(await hasESData());
setHasUserDataViews(await hasUserDataView());
setIsLoading(false);
};
// TODO: add error handling
// https://github.com/elastic/kibana/issues/130913
checkData().catch(() => {});
checkData().catch(() => {
setIsLoading(false);
});
}, [hasESData, hasUserDataView]);

if (isLoading) {
return <EuiLoadingElastic css={{ margin: 'auto' }} size="xxl" />;
}

if (!dataExists) {
return <NoDataConfigPage noDataConfig={noDataConfig} />;
}
Expand Down