debugFileRow.tsx 5.9 KB

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