mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 09:05:45 -06:00
* Datasource Onboarding: Prevent flickering of onboarding page after first load * add loading state to loadDatasources & refactor * fix test * avoid loading state when loading datasources on add * fix test * add explainer on why fetching datasources is needed
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import React, { useState } from 'react';
|
|
|
|
import { config } from '@grafana/runtime';
|
|
import { GrafanaRouteComponentProps } from 'app/core/navigation/types';
|
|
import { EmptyStateNoDatasource } from 'app/features/datasources/components/EmptyStateNoDatasource';
|
|
import { ExploreQueryParams, useSelector } from 'app/types';
|
|
|
|
import { useLoadDataSources } from '../datasources/state';
|
|
|
|
import { ExplorePage } from './ExplorePage';
|
|
|
|
export default function EmptyStateWrapper(props: GrafanaRouteComponentProps<{}, ExploreQueryParams>) {
|
|
const { isLoading } = useLoadDataSources();
|
|
|
|
const { hasDatasource } = useSelector((state) => ({
|
|
hasDatasource: state.dataSources.dataSourcesCount > 0,
|
|
}));
|
|
const [showOnboarding, setShowOnboarding] = useState(config.featureToggles.datasourceOnboarding);
|
|
const showExplorePage = hasDatasource || !showOnboarding;
|
|
|
|
return showExplorePage ? (
|
|
<ExplorePage {...props} />
|
|
) : (
|
|
<EmptyStateNoDatasource
|
|
onCTAClick={() => setShowOnboarding(false)}
|
|
loading={isLoading}
|
|
title="Welcome to Grafana Explore!"
|
|
CTAText="Or explore sample data"
|
|
navId="explore"
|
|
/>
|
|
);
|
|
}
|