grafana/public/app/features/explore/EmptyStateWrapper.tsx
Giordano Ricci 9ff3bf4849
Explore: Use Datasource Onboarding page when visiting without any datasource set up (#60399)
* allow DatasourceOnboarding title and cta text customization

* Explore: use Datasource Onboarding page when visiting without any datasource set up

* move & rename DatasourceOnboarding

* Rename component
2022-12-29 15:38:40 +00:00

40 lines
1.3 KiB
TypeScript

import React, { useState } from 'react';
import { useEffectOnce } from 'react-use';
import { config } from '@grafana/runtime';
import { GrafanaRouteComponentProps } from 'app/core/navigation/types';
import { EmptyStateNoDatasource } from 'app/features/datasources/components/EmptyStateNoDatasource';
import { ExploreQueryParams, useDispatch, useSelector } from 'app/types';
import { loadDataSources } from '../datasources/state';
import { ExplorePage } from './ExplorePage';
export default function EmptyStateWrapper(props: GrafanaRouteComponentProps<{}, ExploreQueryParams>) {
const dispatch = useDispatch();
useEffectOnce(() => {
if (config.featureToggles.datasourceOnboarding) {
dispatch(loadDataSources());
}
});
const { hasDatasource, loading } = useSelector((state) => ({
hasDatasource: state.dataSources.dataSourcesCount > 0,
loading: !state.dataSources.hasFetched,
}));
const [showOnboarding, setShowOnboarding] = useState(config.featureToggles.datasourceOnboarding);
const showExplorePage = hasDatasource || !showOnboarding;
return showExplorePage ? (
<ExplorePage {...props} />
) : (
<EmptyStateNoDatasource
onCTAClick={() => setShowOnboarding(false)}
loading={loading}
title="Welcome to Grafana Explore!"
CTAText="Or explore sample data"
navId="explore"
/>
);
}