index.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. import {Component} from 'react';
  2. import styled from '@emotion/styled';
  3. import color from 'color';
  4. import {Location} from 'history';
  5. import partition from 'lodash/partition';
  6. import GuideAnchor from 'sentry/components/assistant/guideAnchor';
  7. import {Button} from 'sentry/components/button';
  8. import Collapsible from 'sentry/components/collapsible';
  9. import GlobalSelectionLink from 'sentry/components/globalSelectionLink';
  10. import Panel from 'sentry/components/panels/panel';
  11. import PanelHeader from 'sentry/components/panels/panelHeader';
  12. import TextOverflow from 'sentry/components/textOverflow';
  13. import TimeSince from 'sentry/components/timeSince';
  14. import {Tooltip} from 'sentry/components/tooltip';
  15. import Version from 'sentry/components/version';
  16. import {t, tct, tn} from 'sentry/locale';
  17. import {space} from 'sentry/styles/space';
  18. import {Organization, PageFilters, Release} from 'sentry/types';
  19. import {isVersionInfoSemver} from 'sentry/views/releases/utils';
  20. import {ReleasesDisplayOption} from '../releasesDisplayOptions';
  21. import {ReleasesRequestRenderProps} from '../releasesRequest';
  22. import ReleaseCardCommits from './releaseCardCommits';
  23. import ReleaseCardProjectRow from './releaseCardProjectRow';
  24. import ReleaseCardStatsPeriod from './releaseCardStatsPeriod';
  25. function getReleaseProjectId(release: Release, selection: PageFilters) {
  26. // if a release has only one project
  27. if (release.projects.length === 1) {
  28. return release.projects[0].id;
  29. }
  30. // if only one project is selected in global header and release has it (second condition will prevent false positives like -1)
  31. if (
  32. selection.projects.length === 1 &&
  33. release.projects.map(p => p.id).includes(selection.projects[0])
  34. ) {
  35. return selection.projects[0];
  36. }
  37. // project selector on release detail page will pick it up
  38. return undefined;
  39. }
  40. type Props = {
  41. activeDisplay: ReleasesDisplayOption;
  42. getHealthData: ReleasesRequestRenderProps['getHealthData'];
  43. isTopRelease: boolean;
  44. location: Location;
  45. organization: Organization;
  46. release: Release;
  47. reloading: boolean;
  48. selection: PageFilters;
  49. showHealthPlaceholders: boolean;
  50. showReleaseAdoptionStages: boolean;
  51. };
  52. class ReleaseCard extends Component<Props> {
  53. shouldComponentUpdate(nextProps: Props) {
  54. // we don't want project health rows to reorder/jump while the whole card is loading
  55. if (this.props.reloading && nextProps.reloading) {
  56. return false;
  57. }
  58. return true;
  59. }
  60. render() {
  61. const {
  62. release,
  63. organization,
  64. activeDisplay,
  65. location,
  66. reloading,
  67. selection,
  68. showHealthPlaceholders,
  69. isTopRelease,
  70. getHealthData,
  71. showReleaseAdoptionStages,
  72. } = this.props;
  73. const {version, commitCount, lastDeploy, dateCreated, versionInfo} = release;
  74. // sort health rows inside release card alphabetically by project name,
  75. // show only the ones that are selected in global header
  76. const [projectsToShow, projectsToHide] = partition(
  77. release.projects.sort((a, b) => a.slug.localeCompare(b.slug)),
  78. p =>
  79. // do not filter for My Projects & All Projects
  80. selection.projects.length > 0 && !selection.projects.includes(-1)
  81. ? selection.projects.includes(p.id)
  82. : true
  83. );
  84. function getHiddenProjectsTooltip() {
  85. const limitedProjects = projectsToHide.map(p => p.slug).slice(0, 5);
  86. const remainderLength = projectsToHide.length - limitedProjects.length;
  87. if (remainderLength) {
  88. limitedProjects.push(tn('and %s more', 'and %s more', remainderLength));
  89. }
  90. return limitedProjects.join(', ');
  91. }
  92. return (
  93. <StyledPanel reloading={reloading ? 1 : 0} data-test-id="release-panel">
  94. <ReleaseInfo>
  95. <ReleaseInfoHeader>
  96. <GlobalSelectionLink
  97. to={{
  98. pathname: `/organizations/${
  99. organization.slug
  100. }/releases/${encodeURIComponent(version)}/`,
  101. query: {project: getReleaseProjectId(release, selection)},
  102. }}
  103. >
  104. <GuideAnchor
  105. disabled={!isTopRelease || projectsToShow.length > 1}
  106. target="release_version"
  107. >
  108. <VersionWrapper>
  109. <StyledVersion version={version} tooltipRawVersion anchor={false} />
  110. </VersionWrapper>
  111. </GuideAnchor>
  112. </GlobalSelectionLink>
  113. {commitCount > 0 && (
  114. <ReleaseCardCommits release={release} withHeading={false} />
  115. )}
  116. </ReleaseInfoHeader>
  117. <ReleaseInfoSubheader>
  118. <PackageSemver>
  119. {versionInfo?.package && (
  120. <TextOverflow ellipsisDirection="left">
  121. {versionInfo.package}
  122. </TextOverflow>
  123. )}
  124. {organization.features.includes('issue-release-semver')
  125. ? isVersionInfoSemver(versionInfo.version)
  126. ? t('(semver)')
  127. : t('(timestamp)')
  128. : null}
  129. </PackageSemver>
  130. <TimeSince date={lastDeploy?.dateFinished || dateCreated} />
  131. {lastDeploy?.dateFinished && ` \u007C ${lastDeploy.environment}`}
  132. </ReleaseInfoSubheader>
  133. </ReleaseInfo>
  134. <ReleaseProjects>
  135. <ReleaseProjectsHeader lightText>
  136. <ReleaseProjectsLayout showReleaseAdoptionStages={showReleaseAdoptionStages}>
  137. <ReleaseProjectColumn>{t('Project Name')}</ReleaseProjectColumn>
  138. {showReleaseAdoptionStages && (
  139. <AdoptionStageColumn>{t('Adoption Stage')}</AdoptionStageColumn>
  140. )}
  141. <AdoptionColumn>
  142. <span>{t('Adoption')}</span>
  143. <ReleaseCardStatsPeriod location={location} />
  144. </AdoptionColumn>
  145. <CrashFreeRateColumn>{t('Crash Free Rate')}</CrashFreeRateColumn>
  146. <CrashesColumn>{t('Crashes')}</CrashesColumn>
  147. <NewIssuesColumn>{t('New Issues')}</NewIssuesColumn>
  148. </ReleaseProjectsLayout>
  149. </ReleaseProjectsHeader>
  150. <ProjectRows>
  151. <Collapsible
  152. expandButton={({onExpand, numberOfHiddenItems}) => (
  153. <ExpandButtonWrapper>
  154. <Button priority="primary" size="xs" onClick={onExpand}>
  155. {tct('Show [numberOfHiddenItems] More', {numberOfHiddenItems})}
  156. </Button>
  157. </ExpandButtonWrapper>
  158. )}
  159. collapseButton={({onCollapse}) => (
  160. <CollapseButtonWrapper>
  161. <Button priority="primary" size="xs" onClick={onCollapse}>
  162. {t('Collapse')}
  163. </Button>
  164. </CollapseButtonWrapper>
  165. )}
  166. >
  167. {projectsToShow.map((project, index) => (
  168. <ReleaseCardProjectRow
  169. key={`${release.version}-${project.slug}-row`}
  170. index={index}
  171. organization={organization}
  172. project={project}
  173. location={location}
  174. getHealthData={getHealthData}
  175. releaseVersion={release.version}
  176. activeDisplay={activeDisplay}
  177. showPlaceholders={showHealthPlaceholders}
  178. showReleaseAdoptionStages={showReleaseAdoptionStages}
  179. isTopRelease={isTopRelease}
  180. adoptionStages={release.adoptionStages}
  181. />
  182. ))}
  183. </Collapsible>
  184. </ProjectRows>
  185. {projectsToHide.length > 0 && (
  186. <HiddenProjectsMessage data-test-id="hidden-projects">
  187. <Tooltip title={getHiddenProjectsTooltip()}>
  188. <TextOverflow>
  189. {projectsToHide.length === 1
  190. ? tct('[number:1] hidden project', {number: <strong />})
  191. : tct('[number] hidden projects', {
  192. number: <strong>{projectsToHide.length}</strong>,
  193. })}
  194. </TextOverflow>
  195. </Tooltip>
  196. </HiddenProjectsMessage>
  197. )}
  198. </ReleaseProjects>
  199. </StyledPanel>
  200. );
  201. }
  202. }
  203. const VersionWrapper = styled('div')`
  204. display: flex;
  205. align-items: center;
  206. `;
  207. const StyledVersion = styled(Version)`
  208. ${p => p.theme.overflowEllipsis};
  209. `;
  210. const StyledPanel = styled(Panel)<{reloading: number}>`
  211. opacity: ${p => (p.reloading ? 0.5 : 1)};
  212. pointer-events: ${p => (p.reloading ? 'none' : 'auto')};
  213. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  214. display: flex;
  215. }
  216. `;
  217. const ReleaseInfo = styled('div')`
  218. padding: ${space(1.5)} ${space(2)};
  219. flex-shrink: 0;
  220. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  221. border-right: 1px solid ${p => p.theme.border};
  222. min-width: 260px;
  223. width: 22%;
  224. max-width: 300px;
  225. }
  226. `;
  227. const ReleaseInfoSubheader = styled('div')`
  228. font-size: ${p => p.theme.fontSizeSmall};
  229. color: ${p => p.theme.gray400};
  230. `;
  231. const PackageSemver = styled('div')`
  232. font-size: ${p => p.theme.fontSizeMedium};
  233. color: ${p => p.theme.textColor};
  234. display: flex;
  235. align-items: center;
  236. gap: ${space(0.5)};
  237. `;
  238. const ReleaseProjects = styled('div')`
  239. border-top: 1px solid ${p => p.theme.border};
  240. flex-grow: 1;
  241. display: grid;
  242. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  243. border-top: none;
  244. }
  245. `;
  246. const ReleaseInfoHeader = styled('div')`
  247. font-size: ${p => p.theme.fontSizeExtraLarge};
  248. display: grid;
  249. grid-template-columns: minmax(0, 1fr) max-content;
  250. gap: ${space(2)};
  251. align-items: center;
  252. `;
  253. const ReleaseProjectsHeader = styled(PanelHeader)`
  254. border-top-left-radius: 0;
  255. padding: ${space(1.5)} ${space(2)};
  256. font-size: ${p => p.theme.fontSizeSmall};
  257. `;
  258. const ProjectRows = styled('div')`
  259. position: relative;
  260. `;
  261. const ExpandButtonWrapper = styled('div')`
  262. position: absolute;
  263. width: 100%;
  264. bottom: 0;
  265. display: flex;
  266. align-items: center;
  267. justify-content: center;
  268. background-image: linear-gradient(
  269. 180deg,
  270. ${p => color(p.theme.background).alpha(0).string()} 0,
  271. ${p => p.theme.background}
  272. );
  273. background-repeat: repeat-x;
  274. border-bottom: ${space(1)} solid ${p => p.theme.background};
  275. border-top: ${space(1)} solid transparent;
  276. border-bottom-right-radius: ${p => p.theme.borderRadius};
  277. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  278. border-bottom-left-radius: ${p => p.theme.borderRadius};
  279. }
  280. `;
  281. const CollapseButtonWrapper = styled('div')`
  282. display: flex;
  283. align-items: center;
  284. justify-content: center;
  285. height: 41px;
  286. `;
  287. export const ReleaseProjectsLayout = styled('div')<{showReleaseAdoptionStages?: boolean}>`
  288. display: grid;
  289. grid-template-columns: 1fr 1.4fr 0.6fr 0.7fr;
  290. grid-column-gap: ${space(1)};
  291. align-items: center;
  292. width: 100%;
  293. @media (min-width: ${p => p.theme.breakpoints.small}) {
  294. grid-template-columns: 1fr 1fr 1fr 0.5fr 0.5fr 0.5fr;
  295. }
  296. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  297. grid-template-columns: 1fr 1fr 1fr 0.5fr 0.5fr 0.5fr;
  298. }
  299. @media (min-width: ${p => p.theme.breakpoints.xlarge}) {
  300. ${p =>
  301. p.showReleaseAdoptionStages
  302. ? `
  303. grid-template-columns: 1fr 0.7fr 1fr 1fr 0.7fr 0.7fr 0.5fr;
  304. `
  305. : `
  306. grid-template-columns: 1fr 1fr 1fr 0.7fr 0.7fr 0.5fr;
  307. `}
  308. }
  309. `;
  310. export const ReleaseProjectColumn = styled('div')`
  311. ${p => p.theme.overflowEllipsis};
  312. line-height: 20px;
  313. `;
  314. export const NewIssuesColumn = styled(ReleaseProjectColumn)`
  315. font-variant-numeric: tabular-nums;
  316. @media (min-width: ${p => p.theme.breakpoints.small}) {
  317. text-align: right;
  318. }
  319. `;
  320. export const AdoptionColumn = styled(ReleaseProjectColumn)`
  321. display: none;
  322. font-variant-numeric: tabular-nums;
  323. @media (min-width: ${p => p.theme.breakpoints.small}) {
  324. display: flex;
  325. /* Chart tooltips need overflow */
  326. overflow: visible;
  327. }
  328. & > * {
  329. flex: 1;
  330. }
  331. `;
  332. export const AdoptionStageColumn = styled(ReleaseProjectColumn)`
  333. display: none;
  334. font-variant-numeric: tabular-nums;
  335. @media (min-width: ${p => p.theme.breakpoints.xlarge}) {
  336. display: flex;
  337. /* Need to show the edges of the tags */
  338. overflow: visible;
  339. }
  340. `;
  341. export const CrashFreeRateColumn = styled(ReleaseProjectColumn)`
  342. font-variant-numeric: tabular-nums;
  343. @media (min-width: ${p => p.theme.breakpoints.small}) {
  344. text-align: center;
  345. }
  346. @media (min-width: ${p => p.theme.breakpoints.xlarge}) {
  347. text-align: right;
  348. }
  349. `;
  350. export const CrashesColumn = styled(ReleaseProjectColumn)`
  351. display: none;
  352. font-variant-numeric: tabular-nums;
  353. @media (min-width: ${p => p.theme.breakpoints.small}) {
  354. display: block;
  355. text-align: right;
  356. }
  357. `;
  358. const HiddenProjectsMessage = styled('div')`
  359. display: flex;
  360. align-items: center;
  361. font-size: ${p => p.theme.fontSizeSmall};
  362. padding: 0 ${space(2)};
  363. border-top: 1px solid ${p => p.theme.border};
  364. overflow: hidden;
  365. height: 24px;
  366. line-height: 24px;
  367. color: ${p => p.theme.gray300};
  368. background-color: ${p => p.theme.backgroundSecondary};
  369. border-bottom-right-radius: ${p => p.theme.borderRadius};
  370. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  371. border-bottom-left-radius: ${p => p.theme.borderRadius};
  372. }
  373. `;
  374. export default ReleaseCard;