issues.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 TeamIssuesAge from './teamIssuesAge';
  18. import TeamIssuesBreakdown from './teamIssuesBreakdown';
  19. import TeamResolutionTime from './teamResolutionTime';
  20. import TeamUnresolvedIssues from './teamUnresolvedIssues';
  21. import {dataDatetime} from './utils';
  22. type Props = RouteComponentProps<{orgId: string}, {}>;
  23. function TeamStatsIssues({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. const environment = query.environment;
  39. useEffect(() => {
  40. trackAdvancedAnalyticsEvent('team_insights.viewed', {
  41. organization,
  42. });
  43. }, [organization]);
  44. const {period, start, end, utc} = dataDatetime(query);
  45. if (teams.length === 0) {
  46. return (
  47. <NoProjectMessage organization={organization} superuserNeedsToBeProjectMember />
  48. );
  49. }
  50. return (
  51. <Fragment>
  52. <SentryDocumentTitle title={t('Team Issues')} orgSlug={organization.slug} />
  53. <Header organization={organization} activeTab="issues" />
  54. <Body>
  55. <TeamStatsControls
  56. showEnvironment
  57. location={location}
  58. router={router}
  59. currentTeam={currentTeam}
  60. currentEnvironment={environment}
  61. />
  62. {!initiallyLoaded && <LoadingIndicator />}
  63. {initiallyLoaded && (
  64. <Layout.Main fullWidth>
  65. <DescriptionCard
  66. title={t('All Unresolved Issues')}
  67. description={t(
  68. 'This includes New and Returning issues in the last 7 days as well as those that haven’t been resolved or ignored in the past.'
  69. )}
  70. >
  71. <TeamUnresolvedIssues
  72. projects={projects}
  73. organization={organization}
  74. teamSlug={currentTeam!.slug}
  75. environment={environment}
  76. period={period}
  77. start={start}
  78. end={end}
  79. utc={utc}
  80. />
  81. </DescriptionCard>
  82. <DescriptionCard
  83. title={t('New and Returning Issues')}
  84. description={t(
  85. 'The new, regressed, and unignored issues that were assigned to your team.'
  86. )}
  87. >
  88. <TeamIssuesBreakdown
  89. organization={organization}
  90. projects={projects}
  91. teamSlug={currentTeam!.slug}
  92. environment={environment}
  93. period={period}
  94. start={start?.toString()}
  95. end={end?.toString()}
  96. location={location}
  97. statuses={['new', 'regressed', 'unignored']}
  98. />
  99. </DescriptionCard>
  100. <DescriptionCard
  101. title={t('Issues Triaged')}
  102. description={t(
  103. 'How many new and returning issues were reviewed by your team each week. Reviewing an issue includes marking as reviewed, resolving, assigning to another team, or deleting.'
  104. )}
  105. >
  106. <TeamIssuesBreakdown
  107. organization={organization}
  108. projects={projects}
  109. teamSlug={currentTeam!.slug}
  110. environment={environment}
  111. period={period}
  112. start={start?.toString()}
  113. end={end?.toString()}
  114. location={location}
  115. statuses={['resolved', 'ignored', 'deleted']}
  116. />
  117. </DescriptionCard>
  118. <DescriptionCard
  119. title={t('Age of Unresolved Issues')}
  120. description={t('How long ago since unresolved issues were first created.')}
  121. >
  122. <TeamIssuesAge organization={organization} teamSlug={currentTeam!.slug} />
  123. </DescriptionCard>
  124. <DescriptionCard
  125. title={t('Time to Resolution')}
  126. description={t(
  127. `The mean time it took for issues to be resolved by your team.`
  128. )}
  129. >
  130. <TeamResolutionTime
  131. organization={organization}
  132. environment={environment}
  133. teamSlug={currentTeam!.slug}
  134. period={period}
  135. start={start?.toString()}
  136. end={end?.toString()}
  137. location={location}
  138. />
  139. </DescriptionCard>
  140. </Layout.Main>
  141. )}
  142. </Body>
  143. </Fragment>
  144. );
  145. }
  146. export default TeamStatsIssues;
  147. const Body = styled(Layout.Body)`
  148. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  149. display: block;
  150. }
  151. `;