modulePageProviders.tsx 1.9 KB

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