screensTemplate.tsx 3.6 KB

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