screensTemplate.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 type {ModuleName} from 'sentry/views/insights/types';
  21. type ScreensTemplateProps = {
  22. content: ReactNode;
  23. moduleDescription: string;
  24. moduleDocLink: string;
  25. moduleName: ModuleName.MOBILE_UI | ModuleName.APP_START;
  26. title: string;
  27. additionalSelectors?: ReactNode;
  28. };
  29. export default function ScreensTemplate({
  30. moduleName,
  31. moduleDocLink,
  32. moduleDescription,
  33. title,
  34. additionalSelectors,
  35. content,
  36. }: ScreensTemplateProps) {
  37. const location = useLocation();
  38. const {isProjectCrossPlatform} = useCrossPlatformProject();
  39. const handleProjectChange = useCallback(() => {
  40. browserHistory.replace({
  41. ...location,
  42. query: {
  43. ...omit(location.query, ['primaryRelease', 'secondaryRelease']),
  44. },
  45. });
  46. }, [location]);
  47. const crumbs = useModuleBreadcrumbs(moduleName);
  48. return (
  49. <Layout.Page>
  50. <PageAlertProvider>
  51. <Layout.Header>
  52. <Layout.HeaderContent>
  53. <Breadcrumbs crumbs={crumbs} />
  54. <Layout.Title>
  55. {title}
  56. <PageHeadingQuestionTooltip
  57. docsUrl={moduleDocLink}
  58. title={moduleDescription}
  59. />
  60. </Layout.Title>
  61. </Layout.HeaderContent>
  62. <Layout.HeaderActions>
  63. <ButtonBar gap={1}>
  64. {isProjectCrossPlatform && <PlatformSelector />}
  65. <FeedbackWidgetButton />
  66. </ButtonBar>
  67. </Layout.HeaderActions>
  68. </Layout.Header>
  69. <Layout.Body>
  70. <Layout.Main fullWidth>
  71. <Container>
  72. <ModulePageFilterBar
  73. moduleName={moduleName}
  74. onProjectChange={handleProjectChange}
  75. extraFilters={
  76. <Fragment>
  77. <ReleaseComparisonSelector />
  78. {additionalSelectors}
  79. </Fragment>
  80. }
  81. />
  82. </Container>
  83. <PageAlert />
  84. <ErrorBoundary mini>
  85. <ModulesOnboarding moduleName={moduleName}>{content}</ModulesOnboarding>
  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. `;