debugFileRow.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 {DebugFile} from 'sentry/types/debugFiles';
  17. import {getFeatureTooltip, getPrettyFileType} from './utils';
  18. type Props = {
  19. debugFile: DebugFile;
  20. downloadRole: string;
  21. downloadUrl: string;
  22. onDelete: (id: string) => void;
  23. orgSlug: string;
  24. showDetails: boolean;
  25. };
  26. function DebugFileRow({
  27. debugFile,
  28. showDetails,
  29. downloadUrl,
  30. downloadRole,
  31. onDelete,
  32. orgSlug,
  33. }: Props) {
  34. const {id, data, debugId, uuid, size, dateCreated, objectName, symbolType, codeId} =
  35. debugFile;
  36. const {features} = data || {};
  37. return (
  38. <Fragment>
  39. <Column>
  40. <div>
  41. <DebugId>{debugId || uuid}</DebugId>
  42. </div>
  43. <TimeAndSizeWrapper>
  44. <StyledFileSize bytes={size} />
  45. <TimeWrapper>
  46. <IconClock size="xs" />
  47. <TimeSince date={dateCreated} />
  48. </TimeWrapper>
  49. </TimeAndSizeWrapper>
  50. </Column>
  51. <Column>
  52. <Name>
  53. {symbolType === 'proguard' && objectName === 'proguard-mapping'
  54. ? '\u2015'
  55. : objectName}
  56. </Name>
  57. <Description>
  58. <DescriptionText>{getPrettyFileType(debugFile)}</DescriptionText>
  59. {features && (
  60. <FeatureTags>
  61. {features.map(feature => (
  62. <StyledTag key={feature} tooltipText={getFeatureTooltip(feature)}>
  63. {feature}
  64. </StyledTag>
  65. ))}
  66. </FeatureTags>
  67. )}
  68. {showDetails && (
  69. <div>
  70. {/* there will be more stuff here in the future */}
  71. {codeId && (
  72. <DetailsItem>
  73. {t('Code ID')}: {codeId}
  74. </DetailsItem>
  75. )}
  76. </div>
  77. )}
  78. </Description>
  79. </Column>
  80. <RightColumn>
  81. <ButtonBar gap={0.5}>
  82. <Role role={downloadRole}>
  83. {({hasRole}) => (
  84. <Tooltip
  85. disabled={hasRole}
  86. title={tct(
  87. 'Debug files can only be downloaded by users with organization [downloadRole] role[orHigher]. This can be changed in [settingsLink:Debug Files Access] settings.',
  88. {
  89. downloadRole,
  90. orHigher: downloadRole !== 'owner' ? ` ${t('or higher')}` : '',
  91. settingsLink: <Link to={`/settings/${orgSlug}/#debugFilesRole`} />,
  92. }
  93. )}
  94. isHoverable
  95. >
  96. <Button
  97. size="xs"
  98. icon={<IconDownload size="xs" />}
  99. href={downloadUrl}
  100. disabled={!hasRole}
  101. >
  102. {t('Download')}
  103. </Button>
  104. </Tooltip>
  105. )}
  106. </Role>
  107. <Access access={['project:write']}>
  108. {({hasAccess}) => (
  109. <Tooltip
  110. disabled={hasAccess}
  111. title={t('You do not have permission to delete debug files.')}
  112. >
  113. <Confirm
  114. confirmText={t('Delete')}
  115. message={t('Are you sure you wish to delete this file?')}
  116. onConfirm={() => onDelete(id)}
  117. disabled={!hasAccess}
  118. >
  119. <Button
  120. priority="danger"
  121. icon={<IconDelete size="xs" />}
  122. size="xs"
  123. disabled={!hasAccess}
  124. data-test-id="delete-dif"
  125. aria-label={t('Delete')}
  126. />
  127. </Confirm>
  128. </Tooltip>
  129. )}
  130. </Access>
  131. </ButtonBar>
  132. </RightColumn>
  133. </Fragment>
  134. );
  135. }
  136. const DescriptionText = styled('span')`
  137. display: inline-flex;
  138. margin: 0 ${space(1)} ${space(1)} 0;
  139. `;
  140. const FeatureTags = styled('div')`
  141. display: inline-flex;
  142. flex-wrap: wrap;
  143. margin: -${space(0.5)};
  144. `;
  145. const StyledTag = styled(Tag)`
  146. padding: ${space(0.5)};
  147. `;
  148. const Column = styled('div')`
  149. display: flex;
  150. flex-direction: column;
  151. align-items: flex-start;
  152. `;
  153. const RightColumn = styled('div')`
  154. display: flex;
  155. justify-content: flex-end;
  156. align-items: flex-start;
  157. margin-top: ${space(1)};
  158. `;
  159. const DebugId = styled('code')`
  160. font-size: ${p => p.theme.fontSizeSmall};
  161. `;
  162. const TimeAndSizeWrapper = styled('div')`
  163. width: 100%;
  164. display: flex;
  165. font-size: ${p => p.theme.fontSizeSmall};
  166. margin-top: ${space(1)};
  167. color: ${p => p.theme.subText};
  168. align-items: center;
  169. `;
  170. const StyledFileSize = styled(FileSize)`
  171. flex: 1;
  172. padding-left: ${space(0.5)};
  173. `;
  174. const TimeWrapper = styled('div')`
  175. display: grid;
  176. gap: ${space(0.5)};
  177. grid-template-columns: min-content 1fr;
  178. flex: 2;
  179. align-items: center;
  180. padding-left: ${space(0.5)};
  181. `;
  182. const Name = styled('div')`
  183. font-size: ${p => p.theme.fontSizeMedium};
  184. margin-bottom: ${space(1)};
  185. `;
  186. const Description = styled('div')`
  187. font-size: ${p => p.theme.fontSizeSmall};
  188. color: ${p => p.theme.subText};
  189. @media (max-width: ${p => p.theme.breakpoints.large}) {
  190. line-height: 1.7;
  191. }
  192. `;
  193. const DetailsItem = styled('div')`
  194. ${p => p.theme.overflowEllipsis}
  195. margin-top: ${space(1)}
  196. `;
  197. export default DebugFileRow;