screensTemplate.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import {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 {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  10. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  11. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  12. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  13. import {PageHeadingQuestionTooltip} from 'sentry/components/pageHeadingQuestionTooltip';
  14. import {space} from 'sentry/styles/space';
  15. import {browserHistory} from 'sentry/utils/browserHistory';
  16. import {PageAlert, PageAlertProvider} from 'sentry/utils/performance/contexts/pageAlert';
  17. import {useLocation} from 'sentry/utils/useLocation';
  18. import useOrganization from 'sentry/utils/useOrganization';
  19. import {ReleaseComparisonSelector} from 'sentry/views/insights/common/components/releaseSelector';
  20. import {useOnboardingProject} from 'sentry/views/insights/common/queries/useOnboardingProject';
  21. import {useModuleBreadcrumbs} from 'sentry/views/insights/common/utils/useModuleBreadcrumbs';
  22. import useCrossPlatformProject from 'sentry/views/insights/mobile/common/queries/useCrossPlatformProject';
  23. import {PlatformSelector} from 'sentry/views/insights/mobile/screenload/components/platformSelector';
  24. import type {ModuleName} from 'sentry/views/insights/types';
  25. import Onboarding from 'sentry/views/performance/onboarding';
  26. type ScreensTemplateProps = {
  27. content: ReactNode;
  28. moduleDescription: string;
  29. moduleDocLink: string;
  30. moduleName: ModuleName.MOBILE_UI | ModuleName.APP_START;
  31. title: string;
  32. additionalSelectors?: ReactNode;
  33. };
  34. export default function ScreensTemplate({
  35. moduleName,
  36. moduleDocLink,
  37. moduleDescription,
  38. title,
  39. additionalSelectors,
  40. content,
  41. }: ScreensTemplateProps) {
  42. const organization = useOrganization();
  43. const onboardingProject = useOnboardingProject();
  44. const location = useLocation();
  45. const {isProjectCrossPlatform} = useCrossPlatformProject();
  46. const handleProjectChange = useCallback(() => {
  47. browserHistory.replace({
  48. ...location,
  49. query: {
  50. ...omit(location.query, ['primaryRelease', 'secondaryRelease']),
  51. },
  52. });
  53. }, [location]);
  54. const crumbs = useModuleBreadcrumbs(moduleName);
  55. return (
  56. <Layout.Page>
  57. <PageAlertProvider>
  58. <Layout.Header>
  59. <Layout.HeaderContent>
  60. <Breadcrumbs crumbs={crumbs} />
  61. <Layout.Title>
  62. {title}
  63. <PageHeadingQuestionTooltip
  64. docsUrl={moduleDocLink}
  65. title={moduleDescription}
  66. />
  67. </Layout.Title>
  68. </Layout.HeaderContent>
  69. <Layout.HeaderActions>
  70. <ButtonBar gap={1}>
  71. {isProjectCrossPlatform && <PlatformSelector />}
  72. <FeedbackWidgetButton />
  73. </ButtonBar>
  74. </Layout.HeaderActions>
  75. </Layout.Header>
  76. <Layout.Body>
  77. <Layout.Main fullWidth>
  78. <Container>
  79. <PageFilterBar condensed>
  80. <ProjectPageFilter onChange={handleProjectChange} />
  81. <EnvironmentPageFilter />
  82. <DatePageFilter />
  83. </PageFilterBar>
  84. <ReleaseComparisonSelector />
  85. {additionalSelectors}
  86. </Container>
  87. <PageAlert />
  88. <ErrorBoundary mini>
  89. {onboardingProject && (
  90. <Onboarding organization={organization} project={onboardingProject} />
  91. )}
  92. {!onboardingProject && content}
  93. </ErrorBoundary>
  94. </Layout.Main>
  95. </Layout.Body>
  96. </PageAlertProvider>
  97. </Layout.Page>
  98. );
  99. }
  100. const Container = styled('div')`
  101. display: flex;
  102. gap: ${space(2)};
  103. margin-bottom: ${space(2)};
  104. flex-wrap: wrap;
  105. `;