screensTemplate.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  13. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  14. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  15. import {t} from 'sentry/locale';
  16. import {space} from 'sentry/styles/space';
  17. import {browserHistory} from 'sentry/utils/browserHistory';
  18. import {PageAlert, PageAlertProvider} from 'sentry/utils/performance/contexts/pageAlert';
  19. import {useLocation} from 'sentry/utils/useLocation';
  20. import useOrganization from 'sentry/utils/useOrganization';
  21. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  22. import {useOnboardingProject} from 'sentry/views/performance/browser/webVitals/utils/useOnboardingProject';
  23. import Onboarding from 'sentry/views/performance/onboarding';
  24. import {PlatformCompatibilityChecker} from 'sentry/views/performance/platformCompatibilityChecker';
  25. import {ReleaseComparisonSelector} from 'sentry/views/starfish/components/releaseSelector';
  26. type ScreensTemplateProps = {
  27. compatibilityProps: {
  28. compatibleSDKNames: string[];
  29. docsUrl: string;
  30. };
  31. content: ReactNode;
  32. title: string;
  33. additionalSelectors?: ReactNode;
  34. };
  35. export default function ScreensTemplate({
  36. title,
  37. additionalSelectors,
  38. compatibilityProps,
  39. content,
  40. }: ScreensTemplateProps) {
  41. const organization = useOrganization();
  42. const onboardingProject = useOnboardingProject();
  43. const location = useLocation();
  44. const handleProjectChange = useCallback(() => {
  45. browserHistory.replace({
  46. ...location,
  47. query: {
  48. ...omit(location.query, ['primaryRelease', 'secondaryRelease']),
  49. },
  50. });
  51. }, [location]);
  52. return (
  53. <SentryDocumentTitle title={title} orgSlug={organization.slug}>
  54. <Layout.Page>
  55. <PageAlertProvider>
  56. <Layout.Header>
  57. <Layout.HeaderContent>
  58. <Breadcrumbs
  59. crumbs={[
  60. {
  61. label: t('Performance'),
  62. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  63. preservePageFilters: true,
  64. },
  65. {
  66. label: title,
  67. },
  68. ]}
  69. />
  70. <Layout.Title>{title}</Layout.Title>
  71. </Layout.HeaderContent>
  72. <Layout.HeaderActions>
  73. <ButtonBar gap={1}>
  74. <FeedbackWidgetButton />
  75. </ButtonBar>
  76. </Layout.HeaderActions>
  77. </Layout.Header>
  78. <Layout.Body>
  79. <Layout.Main fullWidth>
  80. <PageFiltersContainer>
  81. <Container>
  82. <PageFilterBar condensed>
  83. <ProjectPageFilter onChange={handleProjectChange} />
  84. <EnvironmentPageFilter />
  85. <DatePageFilter />
  86. </PageFilterBar>
  87. <ReleaseComparisonSelector />
  88. {additionalSelectors}
  89. </Container>
  90. </PageFiltersContainer>
  91. <PageAlert />
  92. <ErrorBoundary mini>
  93. <PlatformCompatibilityChecker {...compatibilityProps}>
  94. {onboardingProject && (
  95. <Onboarding organization={organization} project={onboardingProject} />
  96. )}
  97. {!onboardingProject && content}
  98. </PlatformCompatibilityChecker>
  99. </ErrorBoundary>
  100. </Layout.Main>
  101. </Layout.Body>
  102. </PageAlertProvider>
  103. </Layout.Page>
  104. </SentryDocumentTitle>
  105. );
  106. }
  107. const Container = styled('div')`
  108. display: flex;
  109. gap: ${space(2)};
  110. margin-bottom: ${space(2)};
  111. flex-wrap: wrap;
  112. `;