screensTemplate.tsx 4.3 KB

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