health.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import {Fragment, useEffect} from 'react';
  2. import {RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import * as Layout from 'sentry/components/layouts/thirds';
  5. import LoadingIndicator from 'sentry/components/loadingIndicator';
  6. import NoProjectMessage from 'sentry/components/noProjectMessage';
  7. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  8. import {t} from 'sentry/locale';
  9. import {TeamWithProjects} from 'sentry/types';
  10. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  11. import localStorage from 'sentry/utils/localStorage';
  12. import useOrganization from 'sentry/utils/useOrganization';
  13. import useTeams from 'sentry/utils/useTeams';
  14. import Header from '../header';
  15. import TeamStatsControls from './controls';
  16. import DescriptionCard from './descriptionCard';
  17. import TeamAlertsTriggered from './teamAlertsTriggered';
  18. import TeamMisery from './teamMisery';
  19. import TeamReleases from './teamReleases';
  20. import TeamStability from './teamStability';
  21. import {dataDatetime} from './utils';
  22. type Props = RouteComponentProps<{orgId: string}, {}>;
  23. function TeamStatsHealth({location, router}: Props) {
  24. const organization = useOrganization();
  25. const {teams, initiallyLoaded} = useTeams({provideUserTeams: true});
  26. const query = location?.query ?? {};
  27. const localStorageKey = `teamInsightsSelectedTeamId:${organization.slug}`;
  28. let localTeamId: string | null | undefined =
  29. query.team ?? localStorage.getItem(localStorageKey);
  30. if (localTeamId && !teams.find(team => team.id === localTeamId)) {
  31. localTeamId = null;
  32. }
  33. const currentTeamId = localTeamId ?? teams[0]?.id;
  34. const currentTeam = teams.find(team => team.id === currentTeamId) as
  35. | TeamWithProjects
  36. | undefined;
  37. const projects = currentTeam?.projects ?? [];
  38. useEffect(() => {
  39. trackAdvancedAnalyticsEvent('team_insights.viewed', {
  40. organization,
  41. });
  42. }, [organization]);
  43. const {period, start, end, utc} = dataDatetime(query);
  44. if (teams.length === 0) {
  45. return (
  46. <NoProjectMessage organization={organization} superuserNeedsToBeProjectMember />
  47. );
  48. }
  49. return (
  50. <Fragment>
  51. <SentryDocumentTitle title={t('Project Health')} orgSlug={organization.slug} />
  52. <Header organization={organization} activeTab="health" />
  53. <Body>
  54. <TeamStatsControls
  55. location={location}
  56. router={router}
  57. currentTeam={currentTeam}
  58. />
  59. {!initiallyLoaded && <LoadingIndicator />}
  60. {initiallyLoaded && (
  61. <Layout.Main fullWidth>
  62. <DescriptionCard
  63. title={t('Crash Free Sessions')}
  64. description={t(
  65. 'The percentage of healthy, errored, and abnormal sessions that didn’t cause a crash.'
  66. )}
  67. >
  68. <TeamStability
  69. projects={projects}
  70. organization={organization}
  71. period={period}
  72. start={start}
  73. end={end}
  74. utc={utc}
  75. />
  76. </DescriptionCard>
  77. <DescriptionCard
  78. title={t('User Misery')}
  79. description={t(
  80. 'The number of unique users that experienced load times 4x the project’s configured threshold.'
  81. )}
  82. >
  83. <TeamMisery
  84. organization={organization}
  85. projects={projects}
  86. teamId={currentTeam!.id}
  87. period={period}
  88. start={start?.toString()}
  89. end={end?.toString()}
  90. location={location}
  91. />
  92. </DescriptionCard>
  93. <DescriptionCard
  94. title={t('Metric Alerts Triggered')}
  95. description={t('Alerts triggered from the Alert Rules your team created.')}
  96. >
  97. <TeamAlertsTriggered
  98. organization={organization}
  99. projects={projects}
  100. teamSlug={currentTeam!.slug}
  101. period={period}
  102. start={start?.toString()}
  103. end={end?.toString()}
  104. location={location}
  105. />
  106. </DescriptionCard>
  107. <DescriptionCard
  108. title={t('Number of Releases')}
  109. description={t('The releases that were created in your team’s projects.')}
  110. >
  111. <TeamReleases
  112. projects={projects}
  113. organization={organization}
  114. teamSlug={currentTeam!.slug}
  115. period={period}
  116. start={start}
  117. end={end}
  118. utc={utc}
  119. />
  120. </DescriptionCard>
  121. </Layout.Main>
  122. )}
  123. </Body>
  124. </Fragment>
  125. );
  126. }
  127. export default TeamStatsHealth;
  128. const Body = styled(Layout.Body)`
  129. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  130. display: block;
  131. }
  132. `;