deploys.tsx 3.1 KB

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