releaseCardProjectRow.tsx 8.3 KB

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