releaseCardProjectRow.tsx 11 KB

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