releaseCardProjectRow.tsx 8.4 KB

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