useFeatureFlagOnboarding.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import {useCallback, useEffect} from 'react';
  2. import {SidebarPanelKey} from 'sentry/components/sidebar/types';
  3. import SidebarPanelStore from 'sentry/stores/sidebarPanelStore';
  4. import {trackAnalytics} from 'sentry/utils/analytics';
  5. import {useLocation} from 'sentry/utils/useLocation';
  6. import {useNavigate} from 'sentry/utils/useNavigate';
  7. import useOrganization from 'sentry/utils/useOrganization';
  8. const FLAG_HASH = '#flag-sidequest';
  9. export const FLAG_HASH_SKIP_CONFIG = '#flag-sidequest-skip';
  10. export function useFeatureFlagOnboarding() {
  11. const location = useLocation();
  12. const organization = useOrganization();
  13. const navigate = useNavigate();
  14. useEffect(() => {
  15. if (location.hash === FLAG_HASH || location.hash === FLAG_HASH_SKIP_CONFIG) {
  16. SidebarPanelStore.activatePanel(SidebarPanelKey.FEATURE_FLAG_ONBOARDING);
  17. trackAnalytics('flags.view-setup-sidebar', {
  18. organization,
  19. });
  20. }
  21. }, [location.hash, organization]);
  22. const activateSidebar = useCallback((event: React.MouseEvent) => {
  23. event.preventDefault();
  24. window.location.hash = FLAG_HASH;
  25. SidebarPanelStore.activatePanel(SidebarPanelKey.FEATURE_FLAG_ONBOARDING);
  26. }, []);
  27. // if we detect that event.contexts.flags is set, use this hook instead
  28. // to hide the eval tracking SDK configuration.
  29. const activateSidebarSkipConfigure = useCallback(
  30. (event: React.MouseEvent, projectId: string) => {
  31. event.preventDefault();
  32. navigate(
  33. {
  34. pathname: location.pathname,
  35. // Adding the projectId will help pick the correct project in onboarding
  36. query: {...location.query, project: projectId},
  37. hash: FLAG_HASH_SKIP_CONFIG,
  38. },
  39. {replace: true}
  40. );
  41. SidebarPanelStore.activatePanel(SidebarPanelKey.FEATURE_FLAG_ONBOARDING);
  42. },
  43. [navigate, location.pathname, location.query]
  44. );
  45. return {activateSidebar, activateSidebarSkipConfigure};
  46. }