appStartup.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 ErrorBoundary from 'sentry/components/errorBoundary';
  7. import * as Layout from 'sentry/components/layouts/thirds';
  8. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  9. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  10. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  11. import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  12. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  13. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  14. import {space} from 'sentry/styles/space';
  15. import {PageAlert, PageAlertProvider} from 'sentry/utils/performance/contexts/pageAlert';
  16. import {decodeScalar} from 'sentry/utils/queryString';
  17. import {useLocation} from 'sentry/utils/useLocation';
  18. import useOrganization from 'sentry/utils/useOrganization';
  19. import {ReleaseComparisonSelector} from 'sentry/views/starfish/components/releaseSelector';
  20. import {SpanMetricsField} from 'sentry/views/starfish/types';
  21. import {ROUTE_NAMES} from 'sentry/views/starfish/utils/routeNames';
  22. import AppStartup from 'sentry/views/starfish/views/appStartup';
  23. import {
  24. COLD_START_TYPE,
  25. StartTypeSelector,
  26. } from 'sentry/views/starfish/views/appStartup/screenSummary/startTypeSelector';
  27. export default function InitializationModule() {
  28. const organization = useOrganization();
  29. const location = useLocation();
  30. const appStartType =
  31. decodeScalar(location.query[SpanMetricsField.APP_START_TYPE]) ?? '';
  32. useEffect(() => {
  33. // Default the start type to cold start if not present
  34. if (!appStartType) {
  35. browserHistory.replace({
  36. ...location,
  37. query: {
  38. ...location.query,
  39. [SpanMetricsField.APP_START_TYPE]: COLD_START_TYPE,
  40. },
  41. });
  42. }
  43. }, [location, appStartType]);
  44. const handleProjectChange = useCallback(() => {
  45. browserHistory.replace({
  46. ...location,
  47. query: {
  48. ...omit(location.query, ['primaryRelease', 'secondaryRelease']),
  49. },
  50. });
  51. }, [location]);
  52. return (
  53. <Feature features="starfish-mobile-appstart" organization={organization}>
  54. <SentryDocumentTitle title={ROUTE_NAMES['app-startup']} orgSlug={organization.slug}>
  55. <Layout.Page>
  56. <PageAlertProvider>
  57. <Layout.Header>
  58. <Layout.HeaderContent>
  59. <Layout.Title>{ROUTE_NAMES['app-startup']}</Layout.Title>
  60. </Layout.HeaderContent>
  61. </Layout.Header>
  62. <Layout.Body>
  63. <Layout.Main fullWidth>
  64. <PageAlert />
  65. <PageFiltersContainer>
  66. <Container>
  67. <PageFilterBar condensed>
  68. <ProjectPageFilter onChange={handleProjectChange} />
  69. <EnvironmentPageFilter />
  70. <DatePageFilter />
  71. </PageFilterBar>
  72. <ReleaseComparisonSelector />
  73. <StartTypeSelector />
  74. </Container>
  75. </PageFiltersContainer>
  76. <ErrorBoundary mini>
  77. <AppStartup chartHeight={200} />
  78. </ErrorBoundary>
  79. </Layout.Main>
  80. </Layout.Body>
  81. </PageAlertProvider>
  82. </Layout.Page>
  83. </SentryDocumentTitle>
  84. </Feature>
  85. );
  86. }
  87. const Container = styled('div')`
  88. display: flex;
  89. gap: ${space(2)};
  90. margin-bottom: ${space(2)};
  91. flex-wrap: wrap;
  92. `;