modulePageProviders.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 {useModuleTitles} from 'sentry/views/insights/common/utils/useModuleTitle';
  13. import {useDomainViewFilters} from 'sentry/views/insights/pages/useFilters';
  14. import {INSIGHTS_TITLE, QUERY_DATE_RANGE_LIMIT} from 'sentry/views/insights/settings';
  15. import type {ModuleName} from 'sentry/views/insights/types';
  16. type ModuleNameStrings = `${ModuleName}`;
  17. export type TitleableModuleNames = Exclude<ModuleNameStrings, '' | 'other'>;
  18. interface Props {
  19. children: React.ReactNode;
  20. features: ComponentProps<typeof Feature>['features'];
  21. moduleName: TitleableModuleNames;
  22. analyticEventName?: InsightEventKey;
  23. pageTitle?: string;
  24. }
  25. export function ModulePageProviders({
  26. moduleName,
  27. pageTitle,
  28. children,
  29. features,
  30. analyticEventName,
  31. }: Props) {
  32. const organization = useOrganization();
  33. const moduleTitles = useModuleTitles();
  34. const {isInDomainView} = useDomainViewFilters();
  35. const hasDateRangeQueryLimit = organization.features.includes(
  36. 'insights-query-date-range-limit'
  37. );
  38. useHasDataTrackAnalytics(moduleName as ModuleName, analyticEventName);
  39. const moduleTitle = moduleTitles[moduleName];
  40. const shouldUseUpsellHook = !isInDomainView;
  41. const fullPageTitle = [pageTitle, moduleTitle, INSIGHTS_TITLE]
  42. .filter(Boolean)
  43. .join(' — ');
  44. return (
  45. <PageFiltersContainer
  46. maxPickableDays={hasDateRangeQueryLimit ? QUERY_DATE_RANGE_LIMIT : undefined}
  47. >
  48. <SentryDocumentTitle title={fullPageTitle} orgSlug={organization.slug}>
  49. {shouldUseUpsellHook && (
  50. <UpsellPageHook moduleName={moduleName}>
  51. <Layout.Page>
  52. <Feature
  53. features={features}
  54. organization={organization}
  55. renderDisabled={NoAccess}
  56. >
  57. <NoProjectMessage organization={organization}>
  58. {children}
  59. </NoProjectMessage>
  60. </Feature>
  61. </Layout.Page>
  62. </UpsellPageHook>
  63. )}
  64. {!shouldUseUpsellHook && (
  65. <Layout.Page>
  66. <Feature
  67. features={['insights-entry-points']}
  68. organization={organization}
  69. renderDisabled={NoAccess}
  70. >
  71. <NoProjectMessage organization={organization}>{children}</NoProjectMessage>
  72. </Feature>
  73. </Layout.Page>
  74. )}
  75. </SentryDocumentTitle>
  76. </PageFiltersContainer>
  77. );
  78. }
  79. export const UpsellPageHook = HookOrDefault({
  80. hookName: 'component:insights-upsell-page',
  81. defaultComponent: ({children}) => children,
  82. });