index.tsx 14 KB

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