sourceMapsArtifactRow.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import Access from 'sentry/components/acl/access';
  4. import {Role} from 'sentry/components/acl/role';
  5. import Button from 'sentry/components/button';
  6. import ButtonBar from 'sentry/components/buttonBar';
  7. import Confirm from 'sentry/components/confirm';
  8. import FileSize from 'sentry/components/fileSize';
  9. import Link from 'sentry/components/links/link';
  10. import Tag from 'sentry/components/tag';
  11. import TimeSince from 'sentry/components/timeSince';
  12. import Tooltip from 'sentry/components/tooltip';
  13. import {IconClock, IconDelete, IconDownload} from 'sentry/icons';
  14. import {t, tct} from 'sentry/locale';
  15. import space from 'sentry/styles/space';
  16. import {Artifact} from 'sentry/types';
  17. type Props = {
  18. artifact: Artifact;
  19. downloadRole: string;
  20. downloadUrl: string;
  21. onDelete: (id: string) => void;
  22. orgSlug: string;
  23. };
  24. const SourceMapsArtifactRow = ({
  25. artifact,
  26. onDelete,
  27. downloadUrl,
  28. downloadRole,
  29. orgSlug,
  30. }: Props) => {
  31. const {name, size, dateCreated, id, dist} = artifact;
  32. const handleDeleteClick = () => {
  33. onDelete(id);
  34. };
  35. return (
  36. <Fragment>
  37. <NameColumn>
  38. <Name>{name || `(${t('empty')})`}</Name>
  39. <TimeAndDistWrapper>
  40. <TimeWrapper>
  41. <IconClock size="sm" />
  42. <TimeSince date={dateCreated} />
  43. </TimeWrapper>
  44. <StyledTag
  45. type={dist ? 'info' : undefined}
  46. tooltipText={dist ? undefined : t('No distribution set')}
  47. >
  48. {dist ?? t('none')}
  49. </StyledTag>
  50. </TimeAndDistWrapper>
  51. </NameColumn>
  52. <SizeColumn>
  53. <FileSize bytes={size} />
  54. </SizeColumn>
  55. <ActionsColumn>
  56. <ButtonBar gap={0.5}>
  57. <Role role={downloadRole}>
  58. {({hasRole}) => (
  59. <Tooltip
  60. title={tct(
  61. 'Artifacts can only be downloaded by users with organization [downloadRole] role[orHigher]. This can be changed in [settingsLink:Debug Files Access] settings.',
  62. {
  63. downloadRole,
  64. orHigher: downloadRole !== 'owner' ? ` ${t('or higher')}` : '',
  65. settingsLink: <Link to={`/settings/${orgSlug}/#debugFilesRole`} />,
  66. }
  67. )}
  68. disabled={hasRole}
  69. isHoverable
  70. >
  71. <Button
  72. size="sm"
  73. icon={<IconDownload size="sm" />}
  74. disabled={!hasRole}
  75. href={downloadUrl}
  76. title={hasRole ? t('Download Artifact') : undefined}
  77. aria-label={t('Download Artifact')}
  78. />
  79. </Tooltip>
  80. )}
  81. </Role>
  82. <Access access={['project:releases']}>
  83. {({hasAccess}) => (
  84. <Tooltip
  85. disabled={hasAccess}
  86. title={t('You do not have permission to delete artifacts.')}
  87. >
  88. <Confirm
  89. message={t('Are you sure you want to remove this artifact?')}
  90. onConfirm={handleDeleteClick}
  91. disabled={!hasAccess}
  92. >
  93. <Button
  94. size="sm"
  95. icon={<IconDelete size="sm" />}
  96. title={hasAccess ? t('Remove Artifact') : undefined}
  97. aria-label={t('Remove Artifact')}
  98. disabled={!hasAccess}
  99. />
  100. </Confirm>
  101. </Tooltip>
  102. )}
  103. </Access>
  104. </ButtonBar>
  105. </ActionsColumn>
  106. </Fragment>
  107. );
  108. };
  109. const NameColumn = styled('div')`
  110. display: flex;
  111. flex-direction: column;
  112. align-items: flex-start;
  113. justify-content: center;
  114. `;
  115. const SizeColumn = styled('div')`
  116. display: flex;
  117. justify-content: flex-end;
  118. text-align: right;
  119. align-items: center;
  120. `;
  121. const ActionsColumn = styled(SizeColumn)``;
  122. const Name = styled('div')`
  123. padding-right: ${space(4)};
  124. overflow-wrap: break-word;
  125. word-break: break-all;
  126. `;
  127. const TimeAndDistWrapper = styled('div')`
  128. width: 100%;
  129. display: flex;
  130. margin-top: ${space(1)};
  131. align-items: center;
  132. `;
  133. const TimeWrapper = styled('div')`
  134. display: grid;
  135. gap: ${space(0.5)};
  136. grid-template-columns: min-content 1fr;
  137. font-size: ${p => p.theme.fontSizeMedium};
  138. align-items: center;
  139. color: ${p => p.theme.subText};
  140. `;
  141. const StyledTag = styled(Tag)`
  142. margin-left: ${space(1)};
  143. `;
  144. export default SourceMapsArtifactRow;