releaseStats.tsx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import {Fragment, memo} from 'react';
  2. import styled from '@emotion/styled';
  3. import AlertLink from 'sentry/components/alertLink';
  4. import GuideAnchor from 'sentry/components/assistant/guideAnchor';
  5. import GroupReleaseChart from 'sentry/components/group/releaseChart';
  6. import SeenInfo from 'sentry/components/group/seenInfo';
  7. import Placeholder from 'sentry/components/placeholder';
  8. import * as SidebarSection from 'sentry/components/sidebarSection';
  9. import {t} from 'sentry/locale';
  10. import {space} from 'sentry/styles/space';
  11. import type {CurrentRelease, Group, Organization, Project, Release} from 'sentry/types';
  12. import {defined} from 'sentry/utils';
  13. import getDynamicText from 'sentry/utils/getDynamicText';
  14. import {useApiQuery} from 'sentry/utils/queryClient';
  15. import QuestionTooltip from '../questionTooltip';
  16. type Props = {
  17. environments: string[];
  18. organization: Organization;
  19. project: Project;
  20. allEnvironments?: Group;
  21. currentRelease?: CurrentRelease;
  22. group?: Group;
  23. };
  24. type GroupRelease = {
  25. firstRelease: Release;
  26. lastRelease: Release;
  27. };
  28. function GroupReleaseStats({
  29. organization,
  30. project,
  31. environments,
  32. allEnvironments,
  33. group,
  34. currentRelease,
  35. }: Props) {
  36. const environment = environments.length > 0 ? environments.join(', ') : undefined;
  37. const environmentLabel = environment ? environment : t('All Environments');
  38. const shortEnvironmentLabel =
  39. environments.length > 1
  40. ? t('selected environments')
  41. : environments.length === 1
  42. ? environments[0]
  43. : undefined;
  44. const {data: groupReleaseData} = useApiQuery<GroupRelease>(
  45. [
  46. defined(group)
  47. ? `/organizations/${organization.slug}/issues/${group.id}/first-last-release/`
  48. : '',
  49. ],
  50. {
  51. staleTime: 30000,
  52. cacheTime: 30000,
  53. }
  54. );
  55. const firstRelease = groupReleaseData?.firstRelease;
  56. const lastRelease = groupReleaseData?.lastRelease;
  57. const projectId = project.id;
  58. const projectSlug = project.slug;
  59. const hasRelease = project.features.includes('releases');
  60. const releaseTrackingUrl = `/settings/${organization.slug}/projects/${project.slug}/release-tracking/`;
  61. return (
  62. <div>
  63. {!group || !allEnvironments ? (
  64. <Placeholder height="346px" bottomGutter={4} />
  65. ) : (
  66. <Fragment>
  67. <GraphContainer>
  68. <GroupReleaseChart
  69. group={allEnvironments}
  70. environment={environment}
  71. environmentLabel={environmentLabel}
  72. environmentStats={group.stats}
  73. release={currentRelease?.release}
  74. releaseStats={currentRelease?.stats}
  75. statsPeriod="24h"
  76. title={t('Last 24 Hours')}
  77. firstSeen={group.firstSeen}
  78. lastSeen={group.lastSeen}
  79. />
  80. </GraphContainer>
  81. <GraphContainer>
  82. <GroupReleaseChart
  83. group={allEnvironments}
  84. environment={environment}
  85. environmentLabel={environmentLabel}
  86. environmentStats={group.stats}
  87. release={currentRelease?.release}
  88. releaseStats={currentRelease?.stats}
  89. statsPeriod="30d"
  90. title={t('Last 30 Days')}
  91. className="bar-chart-small"
  92. firstSeen={group.firstSeen}
  93. lastSeen={group.lastSeen}
  94. />
  95. </GraphContainer>
  96. <SidebarSection.Wrap>
  97. <SidebarSection.Title>
  98. <GuideAnchor target="issue_sidebar_releases" position="left">
  99. {t('Last Seen')}
  100. </GuideAnchor>
  101. <QuestionTooltip
  102. title={t('When the most recent event in this issue was captured.')}
  103. size="xs"
  104. />
  105. </SidebarSection.Title>
  106. <StyledSidebarSectionContent>
  107. <SeenInfo
  108. organization={organization}
  109. projectId={projectId}
  110. projectSlug={projectSlug}
  111. date={getDynamicText({
  112. value: group.lastSeen,
  113. fixed: '2016-01-13T03:08:25Z',
  114. })}
  115. dateGlobal={allEnvironments.lastSeen}
  116. hasRelease={hasRelease}
  117. environment={shortEnvironmentLabel}
  118. release={lastRelease}
  119. title={t('Last Seen')}
  120. />
  121. </StyledSidebarSectionContent>
  122. </SidebarSection.Wrap>
  123. <SidebarSection.Wrap>
  124. <SidebarSection.Title>
  125. {t('First Seen')}
  126. <QuestionTooltip
  127. title={t('When the first event in this issue was captured.')}
  128. size="xs"
  129. />
  130. </SidebarSection.Title>
  131. <StyledSidebarSectionContent>
  132. <SeenInfo
  133. organization={organization}
  134. projectId={projectId}
  135. projectSlug={projectSlug}
  136. date={getDynamicText({
  137. value: group.firstSeen,
  138. fixed: '2015-08-13T03:08:25Z',
  139. })}
  140. dateGlobal={allEnvironments.firstSeen}
  141. hasRelease={hasRelease}
  142. environment={shortEnvironmentLabel}
  143. release={firstRelease}
  144. title={t('First seen')}
  145. />
  146. </StyledSidebarSectionContent>
  147. </SidebarSection.Wrap>
  148. {!hasRelease ? (
  149. <SidebarSection.Wrap>
  150. <SidebarSection.Title>{t('Releases')}</SidebarSection.Title>
  151. <SidebarSection.Content>
  152. <AlertLink priority="muted" size="small" to={releaseTrackingUrl}>
  153. {t('See which release caused this issue ')}
  154. </AlertLink>
  155. </SidebarSection.Content>
  156. </SidebarSection.Wrap>
  157. ) : null}
  158. </Fragment>
  159. )}
  160. </div>
  161. );
  162. }
  163. export default memo(GroupReleaseStats);
  164. const GraphContainer = styled('div')`
  165. margin-bottom: ${space(3)};
  166. `;
  167. const StyledSidebarSectionContent = styled(SidebarSection.Content)`
  168. margin-top: ${space(0.5)};
  169. `;