modulePageProviders.tsx 2.3 KB

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