index.tsx 13 KB

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