debugFileRow.tsx 6.1 KB

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