grafana/public/app/features/search/hooks/useShowDashboardPreviews.ts
Artur Wierzbicki 6e1615b42a
Analytics: send dashboard_list_viewed events to rudderstack (#44589)
* #44449: report interactions with showPreviews toggle

* #44449: hookify showPreviews

* #44449: report dashboard_list_viewed event rather than enabled/disabled_dashboard_previews
2022-01-31 22:17:05 +04:00

14 lines
625 B
TypeScript

import { PREVIEWS_LOCAL_STORAGE_KEY } from '../constants';
import { config } from '@grafana/runtime/src';
import { useLocalStorage } from 'react-use';
export const useShowDashboardPreviews = () => {
const previewFeatureEnabled = Boolean(config.featureToggles.dashboardPreviews);
const [showPreviews, setShowPreviews] = useLocalStorage<boolean>(PREVIEWS_LOCAL_STORAGE_KEY, previewFeatureEnabled);
const onShowPreviewsChange = (showPreviews: boolean) => {
setShowPreviews(showPreviews);
};
return { showPreviews: Boolean(showPreviews && previewFeatureEnabled), previewFeatureEnabled, onShowPreviewsChange };
};