releaseCardProjectRow.tsx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. import LazyLoad from 'react-lazyload';
  2. import {useTheme} from '@emotion/react';
  3. import styled from '@emotion/styled';
  4. import type {Location} from 'history';
  5. import GuideAnchor from 'sentry/components/assistant/guideAnchor';
  6. import Tag from 'sentry/components/badge/tag';
  7. import {LinkButton} from 'sentry/components/button';
  8. import MiniBarChart from 'sentry/components/charts/miniBarChart';
  9. import Count from 'sentry/components/count';
  10. import GlobalSelectionLink from 'sentry/components/globalSelectionLink';
  11. import ProjectBadge from 'sentry/components/idBadge/projectBadge';
  12. import Link from 'sentry/components/links/link';
  13. import NotAvailable from 'sentry/components/notAvailable';
  14. import {extractSelectionParameters} from 'sentry/components/organizations/pageFilters/utils';
  15. import PanelItem from 'sentry/components/panels/panelItem';
  16. import Placeholder from 'sentry/components/placeholder';
  17. import {Tooltip} from 'sentry/components/tooltip';
  18. import {IconCheckmark, IconFire, IconWarning} from 'sentry/icons';
  19. import {t, tn} from 'sentry/locale';
  20. import {space} from 'sentry/styles/space';
  21. import type {Organization} from 'sentry/types/organization';
  22. import type {Release, ReleaseProject} from 'sentry/types/release';
  23. import {defined} from 'sentry/utils';
  24. import type {IconSize} from 'sentry/utils/theme';
  25. import {
  26. ADOPTION_STAGE_LABELS,
  27. displayCrashFreePercent,
  28. getReleaseNewIssuesUrl,
  29. getReleaseUnhandledIssuesUrl,
  30. isMobileRelease,
  31. } from '../../utils';
  32. import {ReleasesDisplayOption} from '../releasesDisplayOptions';
  33. import type {ReleasesRequestRenderProps} from '../releasesRequest';
  34. import {
  35. AdoptionColumn,
  36. AdoptionStageColumn,
  37. CrashFreeRateColumn,
  38. DisplaySmallCol,
  39. NewIssuesColumn,
  40. ReleaseProjectColumn,
  41. ReleaseProjectsLayout,
  42. } from '.';
  43. const CRASH_FREE_DANGER_THRESHOLD = 98;
  44. const CRASH_FREE_WARNING_THRESHOLD = 99.5;
  45. function getCrashFreeIcon(crashFreePercent: number, iconSize: IconSize = 'sm') {
  46. if (crashFreePercent < CRASH_FREE_DANGER_THRESHOLD) {
  47. return <IconFire color="errorText" size={iconSize} />;
  48. }
  49. if (crashFreePercent < CRASH_FREE_WARNING_THRESHOLD) {
  50. return <IconWarning color="warningText" size={iconSize} />;
  51. }
  52. return <IconCheckmark isCircled color="successText" size={iconSize} />;
  53. }
  54. type Props = {
  55. activeDisplay: ReleasesDisplayOption;
  56. getHealthData: ReleasesRequestRenderProps['getHealthData'];
  57. index: number;
  58. isTopRelease: boolean;
  59. location: Location;
  60. organization: Organization;
  61. project: ReleaseProject;
  62. releaseVersion: string;
  63. showPlaceholders: boolean;
  64. showReleaseAdoptionStages: boolean;
  65. adoptionStages?: Release['adoptionStages'];
  66. };
  67. function ReleaseCardProjectRow({
  68. activeDisplay,
  69. adoptionStages,
  70. getHealthData,
  71. index,
  72. isTopRelease,
  73. location,
  74. organization,
  75. project,
  76. releaseVersion,
  77. showPlaceholders,
  78. showReleaseAdoptionStages,
  79. }: Props) {
  80. const theme = useTheme();
  81. const {id, newGroups} = project;
  82. const crashCount = getHealthData.getCrashCount(
  83. releaseVersion,
  84. id,
  85. ReleasesDisplayOption.SESSIONS
  86. );
  87. const crashFreeRate = getHealthData.getCrashFreeRate(releaseVersion, id, activeDisplay);
  88. const get24hCountByProject = getHealthData.get24hCountByProject(id, activeDisplay);
  89. const timeSeries = getHealthData.getTimeSeries(releaseVersion, id, activeDisplay);
  90. const adoption = getHealthData.getAdoption(releaseVersion, id, activeDisplay);
  91. const adoptionStage =
  92. showReleaseAdoptionStages &&
  93. adoptionStages?.[project.slug] &&
  94. adoptionStages?.[project.slug].stage;
  95. const adoptionStageLabel =
  96. get24hCountByProject && adoptionStage && isMobileRelease(project.platform)
  97. ? ADOPTION_STAGE_LABELS[adoptionStage]
  98. : null;
  99. return (
  100. <ProjectRow data-test-id="release-card-project-row">
  101. <ReleaseProjectsLayout showReleaseAdoptionStages={showReleaseAdoptionStages}>
  102. <ReleaseProjectColumn>
  103. <ProjectBadge project={project} avatarSize={16} />
  104. </ReleaseProjectColumn>
  105. {showReleaseAdoptionStages && (
  106. <AdoptionStageColumn>
  107. {adoptionStageLabel ? (
  108. <Tooltip title={adoptionStageLabel.tooltipTitle} isHoverable>
  109. <Link
  110. to={{
  111. pathname: `/organizations/${organization.slug}/releases/`,
  112. query: {
  113. ...location.query,
  114. query: `release.stage:${adoptionStage}`,
  115. },
  116. }}
  117. >
  118. <Tag type={adoptionStageLabel.type}>{adoptionStageLabel.name}</Tag>
  119. </Link>
  120. </Tooltip>
  121. ) : (
  122. <NotAvailable />
  123. )}
  124. </AdoptionStageColumn>
  125. )}
  126. <AdoptionColumn>
  127. {showPlaceholders ? (
  128. <StyledPlaceholder width="100px" />
  129. ) : (
  130. <AdoptionWrapper>
  131. <span>{adoption ? Math.round(adoption) : '0'}%</span>
  132. <LazyLoad debounce={50} height={20}>
  133. <MiniBarChart
  134. series={timeSeries}
  135. height={20}
  136. isGroupedByDate
  137. showTimeInTooltip
  138. hideDelay={50}
  139. tooltipFormatter={(value: number) => {
  140. const suffix =
  141. activeDisplay === ReleasesDisplayOption.USERS
  142. ? tn('user', 'users', value)
  143. : tn('session', 'sessions', value);
  144. return `${value.toLocaleString()} ${suffix}`;
  145. }}
  146. colors={[theme.purple300, theme.gray200]}
  147. />
  148. </LazyLoad>
  149. </AdoptionWrapper>
  150. )}
  151. </AdoptionColumn>
  152. <CrashFreeRateColumn>
  153. {showPlaceholders ? (
  154. <StyledPlaceholder width="60px" />
  155. ) : defined(crashFreeRate) ? (
  156. <CrashFreeWrapper>
  157. {getCrashFreeIcon(crashFreeRate)}
  158. {displayCrashFreePercent(crashFreeRate)}
  159. </CrashFreeWrapper>
  160. ) : (
  161. <NotAvailable />
  162. )}
  163. </CrashFreeRateColumn>
  164. <DisplaySmallCol>
  165. {showPlaceholders ? (
  166. <StyledPlaceholder width="30px" />
  167. ) : defined(crashCount) ? (
  168. <Tooltip title={t('Open in Issues')}>
  169. <GlobalSelectionLink
  170. to={getReleaseUnhandledIssuesUrl(
  171. organization.slug,
  172. project.id,
  173. releaseVersion
  174. )}
  175. >
  176. <Count value={crashCount} />
  177. </GlobalSelectionLink>
  178. </Tooltip>
  179. ) : (
  180. <NotAvailable />
  181. )}
  182. </DisplaySmallCol>
  183. <NewIssuesColumn>
  184. <Tooltip title={t('Open in Issues')}>
  185. <GlobalSelectionLink
  186. to={getReleaseNewIssuesUrl(organization.slug, project.id, releaseVersion)}
  187. >
  188. <Count value={newGroups || 0} />
  189. </GlobalSelectionLink>
  190. </Tooltip>
  191. </NewIssuesColumn>
  192. <ViewColumn>
  193. <GuideAnchor disabled={!isTopRelease || index !== 0} target="view_release">
  194. <LinkButton
  195. size="xs"
  196. to={{
  197. pathname: `/organizations/${
  198. organization.slug
  199. }/releases/${encodeURIComponent(releaseVersion)}/`,
  200. query: {
  201. ...extractSelectionParameters(location.query),
  202. project: project.id,
  203. yAxis: undefined,
  204. },
  205. }}
  206. >
  207. {t('View')}
  208. </LinkButton>
  209. </GuideAnchor>
  210. </ViewColumn>
  211. </ReleaseProjectsLayout>
  212. </ProjectRow>
  213. );
  214. }
  215. export default ReleaseCardProjectRow;
  216. const ProjectRow = styled(PanelItem)`
  217. padding: ${space(1)} ${space(2)};
  218. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  219. font-size: ${p => p.theme.fontSizeMedium};
  220. }
  221. `;
  222. const StyledPlaceholder = styled(Placeholder)`
  223. height: 15px;
  224. display: inline-block;
  225. position: relative;
  226. top: ${space(0.25)};
  227. `;
  228. const AdoptionWrapper = styled('span')`
  229. flex: 1;
  230. display: inline-grid;
  231. grid-template-columns: 30px 1fr;
  232. gap: ${space(1)};
  233. align-items: center;
  234. /* Chart tooltips need overflow */
  235. overflow: visible;
  236. `;
  237. const CrashFreeWrapper = styled('div')`
  238. display: inline-grid;
  239. grid-auto-flow: column;
  240. grid-column-gap: ${space(1)};
  241. align-items: center;
  242. vertical-align: middle;
  243. `;
  244. const ViewColumn = styled('div')`
  245. ${p => p.theme.overflowEllipsis};
  246. line-height: 20px;
  247. text-align: right;
  248. `;