screensTemplate.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import {Fragment, type ReactNode, useCallback} from 'react';
  2. import styled from '@emotion/styled';
  3. import omit from 'lodash/omit';
  4. import ErrorBoundary from 'sentry/components/errorBoundary';
  5. import * as Layout from 'sentry/components/layouts/thirds';
  6. import {PageHeadingQuestionTooltip} from 'sentry/components/pageHeadingQuestionTooltip';
  7. import {space} from 'sentry/styles/space';
  8. import {browserHistory} from 'sentry/utils/browserHistory';
  9. import {PageAlert, PageAlertProvider} from 'sentry/utils/performance/contexts/pageAlert';
  10. import {useLocation} from 'sentry/utils/useLocation';
  11. import {ModulePageFilterBar} from 'sentry/views/insights/common/components/modulePageFilterBar';
  12. import {ModulesOnboarding} from 'sentry/views/insights/common/components/modulesOnboarding';
  13. import {ModuleBodyUpsellHook} from 'sentry/views/insights/common/components/moduleUpsellHookWrapper';
  14. import {ReleaseComparisonSelector} from 'sentry/views/insights/common/components/releaseSelector';
  15. import useCrossPlatformProject from 'sentry/views/insights/mobile/common/queries/useCrossPlatformProject';
  16. import {PlatformSelector} from 'sentry/views/insights/mobile/screenload/components/platformSelector';
  17. import {MobileHeader} from 'sentry/views/insights/pages/mobile/mobilePageHeader';
  18. import {ModuleName} from 'sentry/views/insights/types';
  19. type ScreensTemplateProps = {
  20. content: ReactNode;
  21. moduleDescription: string;
  22. moduleDocLink: string;
  23. moduleName: ModuleName.MOBILE_UI | ModuleName.APP_START;
  24. title: string;
  25. additionalSelectors?: ReactNode;
  26. };
  27. export default function ScreensTemplate({
  28. moduleName,
  29. moduleDocLink,
  30. moduleDescription,
  31. title,
  32. additionalSelectors,
  33. content,
  34. }: ScreensTemplateProps) {
  35. const location = useLocation();
  36. const {isProjectCrossPlatform} = useCrossPlatformProject();
  37. const handleProjectChange = useCallback(() => {
  38. browserHistory.replace({
  39. ...location,
  40. query: {
  41. ...omit(location.query, ['primaryRelease', 'secondaryRelease']),
  42. },
  43. });
  44. }, [location]);
  45. return (
  46. <Layout.Page>
  47. <PageAlertProvider>
  48. <MobileHeader
  49. headerTitle={
  50. <Fragment>
  51. {title}
  52. <PageHeadingQuestionTooltip
  53. docsUrl={moduleDocLink}
  54. title={moduleDescription}
  55. />
  56. </Fragment>
  57. }
  58. module={ModuleName.APP_START}
  59. headerActions={isProjectCrossPlatform && <PlatformSelector />}
  60. />
  61. <ModuleBodyUpsellHook moduleName={moduleName}>
  62. <Layout.Body>
  63. <Layout.Main fullWidth>
  64. <Container>
  65. <ModulePageFilterBar
  66. moduleName={moduleName}
  67. onProjectChange={handleProjectChange}
  68. extraFilters={
  69. <Fragment>
  70. <ReleaseComparisonSelector />
  71. {additionalSelectors}
  72. </Fragment>
  73. }
  74. />
  75. </Container>
  76. <PageAlert />
  77. <ErrorBoundary mini>
  78. <ModulesOnboarding moduleName={moduleName}>{content}</ModulesOnboarding>
  79. </ErrorBoundary>
  80. </Layout.Main>
  81. </Layout.Body>
  82. </ModuleBodyUpsellHook>
  83. </PageAlertProvider>
  84. </Layout.Page>
  85. );
  86. }
  87. const Container = styled('div')`
  88. display: flex;
  89. gap: ${space(2)};
  90. margin-bottom: ${space(2)};
  91. flex-wrap: wrap;
  92. `;