deploys.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import Button from 'sentry/components/button';
  4. import TextOverflow from 'sentry/components/textOverflow';
  5. import TimeSince from 'sentry/components/timeSince';
  6. import Version from 'sentry/components/version';
  7. import {IconReleases} from 'sentry/icons';
  8. import {t} from 'sentry/locale';
  9. import space from 'sentry/styles/space';
  10. import {Deploy as DeployType, Project} from 'sentry/types';
  11. import getDynamicText from 'sentry/utils/getDynamicText';
  12. const DEPLOY_COUNT = 2;
  13. type Props = {
  14. project: Project;
  15. shorten?: boolean;
  16. };
  17. const Deploys = ({project, shorten}: Props) => {
  18. const flattenedDeploys = Object.entries(project.latestDeploys || {}).map(
  19. ([environment, value]): Pick<
  20. DeployType,
  21. 'version' | 'dateFinished' | 'environment'
  22. > => ({environment, ...value})
  23. );
  24. const deploys = (flattenedDeploys || [])
  25. .sort(
  26. (a, b) => new Date(b.dateFinished).getTime() - new Date(a.dateFinished).getTime()
  27. )
  28. .slice(0, DEPLOY_COUNT);
  29. if (!deploys.length) {
  30. return <NoDeploys />;
  31. }
  32. return (
  33. <DeployRows>
  34. {deploys.map(deploy => (
  35. <Deploy
  36. key={`${deploy.environment}-${deploy.version}`}
  37. deploy={deploy}
  38. project={project}
  39. shorten={shorten}
  40. />
  41. ))}
  42. </DeployRows>
  43. );
  44. };
  45. export default Deploys;
  46. type DeployProps = Props & {
  47. deploy: Pick<DeployType, 'version' | 'dateFinished' | 'environment'>;
  48. };
  49. const Deploy = ({deploy, project, shorten}: DeployProps) => (
  50. <Fragment>
  51. <IconReleases size="sm" />
  52. <TextOverflow>
  53. <Environment>{deploy.environment}</Environment>
  54. <Version
  55. version={deploy.version}
  56. projectId={project.id}
  57. tooltipRawVersion
  58. truncate
  59. />
  60. </TextOverflow>
  61. <DeployTime>
  62. {getDynamicText({
  63. fixed: '3 hours ago',
  64. value: (
  65. <TimeSince date={deploy.dateFinished} shorten={shorten ? shorten : false} />
  66. ),
  67. })}
  68. </DeployTime>
  69. </Fragment>
  70. );
  71. const NoDeploys = () => (
  72. <GetStarted>
  73. <Button size="sm" href="https://docs.sentry.io/product/releases/" external>
  74. {t('Track Deploys')}
  75. </Button>
  76. </GetStarted>
  77. );
  78. const DeployContainer = styled('div')`
  79. padding: ${space(2)};
  80. height: 115px;
  81. `;
  82. const DeployRows = styled(DeployContainer)`
  83. display: grid;
  84. grid-template-columns: 30px 1fr 1fr;
  85. grid-template-rows: auto;
  86. grid-column-gap: ${space(1)};
  87. grid-row-gap: ${space(1)};
  88. font-size: ${p => p.theme.fontSizeMedium};
  89. line-height: 1.2;
  90. `;
  91. const Environment = styled('div')`
  92. color: ${p => p.theme.textColor};
  93. margin: 0;
  94. `;
  95. const DeployTime = styled('div')`
  96. color: ${p => p.theme.gray300};
  97. overflow: hidden;
  98. text-align: right;
  99. text-overflow: ellipsis;
  100. `;
  101. const GetStarted = styled(DeployContainer)`
  102. display: flex;
  103. align-items: center;
  104. justify-content: center;
  105. `;
  106. export {DeployRows, GetStarted, TextOverflow};