index.tsx 13 KB

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