releaseCardProjectRow.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. import {useMemo} from 'react';
  2. import LazyLoad from 'react-lazyload';
  3. import {useTheme} from '@emotion/react';
  4. import styled from '@emotion/styled';
  5. import {Location} from 'history';
  6. import GuideAnchor from 'sentry/components/assistant/guideAnchor';
  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 Tag from 'sentry/components/tag';
  18. import {Tooltip} from 'sentry/components/tooltip';
  19. import {IconCheckmark, IconFire, IconWarning} from 'sentry/icons';
  20. import {t, tn} from 'sentry/locale';
  21. import {space} from 'sentry/styles/space';
  22. import {Deploy, Organization, Release, ReleaseProject} from 'sentry/types';
  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 {ThresholdStatus} from '../../utils/types';
  33. import {ReleasesDisplayOption} from '../releasesDisplayOptions';
  34. import {ReleasesRequestRenderProps} from '../releasesRequest';
  35. import {
  36. AdoptionColumn,
  37. AdoptionStageColumn,
  38. CrashFreeRateColumn,
  39. DisplaySmallCol,
  40. NewIssuesColumn,
  41. ReleaseProjectColumn,
  42. ReleaseProjectsLayout,
  43. } from '.';
  44. const CRASH_FREE_DANGER_THRESHOLD = 98;
  45. const CRASH_FREE_WARNING_THRESHOLD = 99.5;
  46. function getCrashFreeIcon(crashFreePercent: number, iconSize: IconSize = 'sm') {
  47. if (crashFreePercent < CRASH_FREE_DANGER_THRESHOLD) {
  48. return <IconFire color="errorText" size={iconSize} />;
  49. }
  50. if (crashFreePercent < CRASH_FREE_WARNING_THRESHOLD) {
  51. return <IconWarning color="warningText" size={iconSize} />;
  52. }
  53. return <IconCheckmark isCircled color="successText" size={iconSize} />;
  54. }
  55. type Props = {
  56. activeDisplay: ReleasesDisplayOption;
  57. getHealthData: ReleasesRequestRenderProps['getHealthData'];
  58. hasThresholds: boolean;
  59. index: number;
  60. isTopRelease: boolean;
  61. location: Location;
  62. organization: Organization;
  63. project: ReleaseProject;
  64. releaseVersion: string;
  65. showPlaceholders: boolean;
  66. showReleaseAdoptionStages: boolean;
  67. thresholdStatuses: ThresholdStatus[];
  68. adoptionStages?: Release['adoptionStages'];
  69. lastDeploy?: Deploy | undefined;
  70. };
  71. function ReleaseCardProjectRow({
  72. activeDisplay,
  73. adoptionStages,
  74. getHealthData,
  75. hasThresholds,
  76. index,
  77. isTopRelease,
  78. lastDeploy,
  79. location,
  80. organization,
  81. project,
  82. releaseVersion,
  83. showPlaceholders,
  84. showReleaseAdoptionStages,
  85. thresholdStatuses,
  86. }: Props) {
  87. const theme = useTheme();
  88. const {id, newGroups} = project;
  89. const crashCount = getHealthData.getCrashCount(
  90. releaseVersion,
  91. id,
  92. ReleasesDisplayOption.SESSIONS
  93. );
  94. const thresholds = useMemo(() => {
  95. return (
  96. thresholdStatuses?.filter(status => {
  97. return status.environment?.name === lastDeploy?.environment;
  98. }) || []
  99. );
  100. }, [thresholdStatuses, lastDeploy]);
  101. const healthyThresholds = thresholds.filter(status => {
  102. return status.is_healthy;
  103. });
  104. const pendingThresholds = thresholds.filter(status => {
  105. return new Date(status.end || '') > new Date();
  106. });
  107. const crashFreeRate = getHealthData.getCrashFreeRate(releaseVersion, id, activeDisplay);
  108. const get24hCountByProject = getHealthData.get24hCountByProject(id, activeDisplay);
  109. const timeSeries = getHealthData.getTimeSeries(releaseVersion, id, activeDisplay);
  110. const adoption = getHealthData.getAdoption(releaseVersion, id, activeDisplay);
  111. const adoptionStage =
  112. showReleaseAdoptionStages &&
  113. adoptionStages?.[project.slug] &&
  114. adoptionStages?.[project.slug].stage;
  115. const adoptionStageLabel =
  116. get24hCountByProject && adoptionStage && isMobileRelease(project.platform)
  117. ? ADOPTION_STAGE_LABELS[adoptionStage]
  118. : null;
  119. return (
  120. <ProjectRow data-test-id="release-card-project-row">
  121. <ReleaseProjectsLayout
  122. showReleaseAdoptionStages={showReleaseAdoptionStages}
  123. hasThresholds={hasThresholds}
  124. >
  125. <ReleaseProjectColumn>
  126. <ProjectBadge project={project} avatarSize={16} />
  127. </ReleaseProjectColumn>
  128. {showReleaseAdoptionStages && (
  129. <AdoptionStageColumn>
  130. {adoptionStageLabel ? (
  131. <Tooltip title={adoptionStageLabel.tooltipTitle} isHoverable>
  132. <Link
  133. to={{
  134. pathname: `/organizations/${organization.slug}/releases/`,
  135. query: {
  136. ...location.query,
  137. query: `release.stage:${adoptionStage}`,
  138. },
  139. }}
  140. >
  141. <Tag type={adoptionStageLabel.type}>{adoptionStageLabel.name}</Tag>
  142. </Link>
  143. </Tooltip>
  144. ) : (
  145. <NotAvailable />
  146. )}
  147. </AdoptionStageColumn>
  148. )}
  149. <AdoptionColumn>
  150. {showPlaceholders ? (
  151. <StyledPlaceholder width="100px" />
  152. ) : (
  153. <AdoptionWrapper>
  154. <span>{adoption ? Math.round(adoption) : '0'}%</span>
  155. <LazyLoad debounce={50} height={20}>
  156. <MiniBarChart
  157. series={timeSeries}
  158. height={20}
  159. isGroupedByDate
  160. showTimeInTooltip
  161. hideDelay={50}
  162. tooltipFormatter={(value: number) => {
  163. const suffix =
  164. activeDisplay === ReleasesDisplayOption.USERS
  165. ? tn('user', 'users', value)
  166. : tn('session', 'sessions', value);
  167. return `${value.toLocaleString()} ${suffix}`;
  168. }}
  169. colors={[theme.purple300, theme.gray200]}
  170. />
  171. </LazyLoad>
  172. </AdoptionWrapper>
  173. )}
  174. </AdoptionColumn>
  175. <CrashFreeRateColumn>
  176. {showPlaceholders ? (
  177. <StyledPlaceholder width="60px" />
  178. ) : defined(crashFreeRate) ? (
  179. <CrashFreeWrapper>
  180. {getCrashFreeIcon(crashFreeRate)}
  181. {displayCrashFreePercent(crashFreeRate)}
  182. </CrashFreeWrapper>
  183. ) : (
  184. <NotAvailable />
  185. )}
  186. </CrashFreeRateColumn>
  187. <DisplaySmallCol>
  188. {showPlaceholders ? (
  189. <StyledPlaceholder width="30px" />
  190. ) : defined(crashCount) ? (
  191. <Tooltip title={t('Open in Issues')}>
  192. <GlobalSelectionLink
  193. to={getReleaseUnhandledIssuesUrl(
  194. organization.slug,
  195. project.id,
  196. releaseVersion
  197. )}
  198. >
  199. <Count value={crashCount} />
  200. </GlobalSelectionLink>
  201. </Tooltip>
  202. ) : (
  203. <NotAvailable />
  204. )}
  205. </DisplaySmallCol>
  206. <NewIssuesColumn>
  207. <Tooltip title={t('Open in Issues')}>
  208. <GlobalSelectionLink
  209. to={getReleaseNewIssuesUrl(organization.slug, project.id, releaseVersion)}
  210. >
  211. <Count value={newGroups || 0} />
  212. </GlobalSelectionLink>
  213. </Tooltip>
  214. </NewIssuesColumn>
  215. {hasThresholds && (
  216. <DisplaySmallCol>
  217. {/* TODO: link to release details page */}
  218. {thresholds && thresholds.length > 0 && (
  219. <Tooltip
  220. title={
  221. <div>
  222. <div>
  223. {pendingThresholds.length !== thresholds.length &&
  224. `${healthyThresholds.length - pendingThresholds.length} / ${
  225. thresholds.length
  226. } ` + t('thresholds succeeded')}
  227. </div>
  228. {pendingThresholds.length > 0 && (
  229. <div>
  230. {`${pendingThresholds.length} / ${thresholds.length} ` +
  231. t('still pending')}
  232. </div>
  233. )}
  234. {t('Open in Release Details')}
  235. </div>
  236. }
  237. >
  238. <ThresholdHealth
  239. allHealthy={healthyThresholds.length === thresholds.length}
  240. allThresholdsFinished={pendingThresholds.length === 0}
  241. >
  242. {healthyThresholds.length} / {thresholds && thresholds.length}
  243. </ThresholdHealth>
  244. </Tooltip>
  245. )}
  246. </DisplaySmallCol>
  247. )}
  248. <ViewColumn>
  249. <GuideAnchor disabled={!isTopRelease || index !== 0} target="view_release">
  250. <Button
  251. size="xs"
  252. to={{
  253. pathname: `/organizations/${
  254. organization.slug
  255. }/releases/${encodeURIComponent(releaseVersion)}/`,
  256. query: {
  257. ...extractSelectionParameters(location.query),
  258. project: project.id,
  259. yAxis: undefined,
  260. },
  261. }}
  262. >
  263. {t('View')}
  264. </Button>
  265. </GuideAnchor>
  266. </ViewColumn>
  267. </ReleaseProjectsLayout>
  268. </ProjectRow>
  269. );
  270. }
  271. export default ReleaseCardProjectRow;
  272. const ProjectRow = styled(PanelItem)`
  273. padding: ${space(1)} ${space(2)};
  274. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  275. font-size: ${p => p.theme.fontSizeMedium};
  276. }
  277. `;
  278. const StyledPlaceholder = styled(Placeholder)`
  279. height: 15px;
  280. display: inline-block;
  281. position: relative;
  282. top: ${space(0.25)};
  283. `;
  284. const AdoptionWrapper = styled('span')`
  285. flex: 1;
  286. display: inline-grid;
  287. grid-template-columns: 30px 1fr;
  288. gap: ${space(1)};
  289. align-items: center;
  290. /* Chart tooltips need overflow */
  291. overflow: visible;
  292. `;
  293. const CrashFreeWrapper = styled('div')`
  294. display: inline-grid;
  295. grid-auto-flow: column;
  296. grid-column-gap: ${space(1)};
  297. align-items: center;
  298. vertical-align: middle;
  299. `;
  300. const ViewColumn = styled('div')`
  301. ${p => p.theme.overflowEllipsis};
  302. line-height: 20px;
  303. text-align: right;
  304. `;
  305. const ThresholdHealth = styled('div')<{
  306. allHealthy?: boolean;
  307. allThresholdsFinished?: boolean;
  308. }>`
  309. color: ${p => {
  310. if (!p.allHealthy) {
  311. return p.theme.errorText;
  312. }
  313. if (p.allThresholdsFinished) {
  314. return p.theme.successText;
  315. }
  316. return p.theme.activeText;
  317. }};
  318. `;