modulePageProviders.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 useOrganization from 'sentry/utils/useOrganization';
  9. import {NoAccess} from 'sentry/views/insights/common/components/noAccess';
  10. import {INSIGHTS_TITLE, MODULE_TITLES} from 'sentry/views/insights/settings';
  11. import type {ModuleName} from 'sentry/views/insights/types';
  12. type ModuleNameStrings = `${ModuleName}`;
  13. export type TitleableModuleNames = Exclude<ModuleNameStrings, '' | 'other'>;
  14. interface Props {
  15. children: React.ReactNode;
  16. features: ComponentProps<typeof Feature>['features'];
  17. moduleName: TitleableModuleNames;
  18. pageTitle?: string;
  19. }
  20. export function ModulePageProviders({moduleName, pageTitle, children, features}: Props) {
  21. const organization = useOrganization();
  22. const moduleTitle = MODULE_TITLES[moduleName];
  23. const fullPageTitle = [pageTitle, moduleTitle, INSIGHTS_TITLE]
  24. .filter(Boolean)
  25. .join(' — ');
  26. const defaultBody = (
  27. <Layout.Page>
  28. <Feature features={features} organization={organization} renderDisabled={NoAccess}>
  29. <NoProjectMessage organization={organization}>{children}</NoProjectMessage>
  30. </Feature>
  31. </Layout.Page>
  32. );
  33. return (
  34. <PageFiltersContainer>
  35. <SentryDocumentTitle title={fullPageTitle} orgSlug={organization.slug}>
  36. <UpsellPageHook moduleName={moduleName}>{defaultBody}</UpsellPageHook>
  37. </SentryDocumentTitle>
  38. </PageFiltersContainer>
  39. );
  40. }
  41. export const UpsellPageHook = HookOrDefault({
  42. hookName: 'component:insights-upsell-page',
  43. defaultComponent: ({children}) => children,
  44. });