debugFileRow.tsx 5.8 KB

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