modulePageProviders.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import type {ComponentProps} from 'react';
  2. import Feature from 'sentry/components/acl/feature';
  3. import HookOrDefault from 'sentry/components/hookOrDefault';
  4. import * as Layout from 'sentry/components/layouts/thirds';
  5. import NoProjectMessage from 'sentry/components/noProjectMessage';
  6. import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  7. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  8. import type {InsightEventKey} from 'sentry/utils/analytics/insightAnalyticEvents';
  9. import useOrganization from 'sentry/utils/useOrganization';
  10. import {NoAccess} from 'sentry/views/insights/common/components/noAccess';
  11. import {useHasDataTrackAnalytics} from 'sentry/views/insights/common/utils/useHasDataTrackAnalytics';
  12. import {INSIGHTS_TITLE, MODULE_TITLES} from 'sentry/views/insights/settings';
  13. import type {ModuleName} from 'sentry/views/insights/types';
  14. type ModuleNameStrings = `${ModuleName}`;
  15. export type TitleableModuleNames = Exclude<ModuleNameStrings, '' | 'other'>;
  16. interface Props {
  17. children: React.ReactNode;
  18. features: ComponentProps<typeof Feature>['features'];
  19. moduleName: TitleableModuleNames;
  20. analyticEventName?: InsightEventKey;
  21. pageTitle?: string;
  22. }
  23. export function ModulePageProviders({
  24. moduleName,
  25. pageTitle,
  26. children,
  27. features,
  28. analyticEventName,
  29. }: Props) {
  30. const organization = useOrganization();
  31. useHasDataTrackAnalytics(moduleName as ModuleName, analyticEventName);
  32. const moduleTitle = MODULE_TITLES[moduleName];
  33. const fullPageTitle = [pageTitle, moduleTitle, INSIGHTS_TITLE]
  34. .filter(Boolean)
  35. .join(' — ');
  36. const defaultBody = (
  37. <Layout.Page>
  38. <Feature features={features} organization={organization} renderDisabled={NoAccess}>
  39. <NoProjectMessage organization={organization}>{children}</NoProjectMessage>
  40. </Feature>
  41. </Layout.Page>
  42. );
  43. return (
  44. <PageFiltersContainer>
  45. <SentryDocumentTitle title={fullPageTitle} orgSlug={organization.slug}>
  46. <UpsellPageHook moduleName={moduleName}>{defaultBody}</UpsellPageHook>
  47. </SentryDocumentTitle>
  48. </PageFiltersContainer>
  49. );
  50. }
  51. export const UpsellPageHook = HookOrDefault({
  52. hookName: 'component:insights-upsell-page',
  53. defaultComponent: ({children}) => children,
  54. });