appStartup.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import {useCallback, useEffect} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import omit from 'lodash/omit';
  5. import Feature from 'sentry/components/acl/feature';
  6. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  7. import ErrorBoundary from 'sentry/components/errorBoundary';
  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 {PageAlert, PageAlertProvider} from 'sentry/utils/performance/contexts/pageAlert';
  18. import {decodeScalar} from 'sentry/utils/queryString';
  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 {ReleaseComparisonSelector} from 'sentry/views/starfish/components/releaseSelector';
  25. import {SpanMetricsField} from 'sentry/views/starfish/types';
  26. import {ROUTE_NAMES} from 'sentry/views/starfish/utils/routeNames';
  27. import AppStartup from 'sentry/views/starfish/views/appStartup';
  28. import {
  29. COLD_START_TYPE,
  30. StartTypeSelector,
  31. } from 'sentry/views/starfish/views/appStartup/screenSummary/startTypeSelector';
  32. export default function InitializationModule() {
  33. const organization = useOrganization();
  34. const onboardingProject = useOnboardingProject();
  35. const location = useLocation();
  36. const appStartType =
  37. decodeScalar(location.query[SpanMetricsField.APP_START_TYPE]) ?? '';
  38. useEffect(() => {
  39. // Default the start type to cold start if not present
  40. if (!appStartType) {
  41. browserHistory.replace({
  42. ...location,
  43. query: {
  44. ...location.query,
  45. [SpanMetricsField.APP_START_TYPE]: COLD_START_TYPE,
  46. },
  47. });
  48. }
  49. }, [location, appStartType]);
  50. const handleProjectChange = useCallback(() => {
  51. browserHistory.replace({
  52. ...location,
  53. query: {
  54. ...omit(location.query, ['primaryRelease', 'secondaryRelease']),
  55. },
  56. });
  57. }, [location]);
  58. return (
  59. <Feature features="starfish-mobile-appstart" organization={organization}>
  60. <SentryDocumentTitle title={ROUTE_NAMES['app-startup']} orgSlug={organization.slug}>
  61. <Layout.Page>
  62. <PageAlertProvider>
  63. <Layout.Header>
  64. <Layout.HeaderContent>
  65. <Breadcrumbs
  66. crumbs={[
  67. {
  68. label: t('Performance'),
  69. to: normalizeUrl(
  70. `/organizations/${organization.slug}/performance/`
  71. ),
  72. preservePageFilters: true,
  73. },
  74. {
  75. label: ROUTE_NAMES['app-startup'],
  76. },
  77. ]}
  78. />
  79. <Layout.Title>{ROUTE_NAMES['app-startup']}</Layout.Title>
  80. </Layout.HeaderContent>
  81. </Layout.Header>
  82. <Layout.Body>
  83. <Layout.Main fullWidth>
  84. <PageAlert />
  85. <PageFiltersContainer>
  86. <Container>
  87. <PageFilterBar condensed>
  88. <ProjectPageFilter onChange={handleProjectChange} />
  89. <EnvironmentPageFilter />
  90. <DatePageFilter />
  91. </PageFilterBar>
  92. <ReleaseComparisonSelector />
  93. <StartTypeSelector />
  94. </Container>
  95. </PageFiltersContainer>
  96. <ErrorBoundary mini>
  97. {onboardingProject && (
  98. <Onboarding organization={organization} project={onboardingProject} />
  99. )}
  100. {!onboardingProject && <AppStartup chartHeight={200} />}
  101. </ErrorBoundary>
  102. </Layout.Main>
  103. </Layout.Body>
  104. </PageAlertProvider>
  105. </Layout.Page>
  106. </SentryDocumentTitle>
  107. </Feature>
  108. );
  109. }
  110. const Container = styled('div')`
  111. display: flex;
  112. gap: ${space(2)};
  113. margin-bottom: ${space(2)};
  114. flex-wrap: wrap;
  115. `;