projectProguardRow.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 TimeSince from 'sentry/components/timeSince';
  10. import Tooltip from 'sentry/components/tooltip';
  11. import {IconClock, IconDelete, IconDownload} from 'sentry/icons';
  12. import {t} from 'sentry/locale';
  13. import space from 'sentry/styles/space';
  14. import {DebugFile} from 'sentry/types/debugFiles';
  15. type Props = {
  16. mapping: DebugFile;
  17. onDelete: (id: string) => void;
  18. downloadUrl: string;
  19. downloadRole: string;
  20. };
  21. const ProjectProguardRow = ({mapping, onDelete, downloadUrl, downloadRole}: Props) => {
  22. const {id, debugId, uuid, size, dateCreated} = mapping;
  23. const handleDeleteClick = () => {
  24. onDelete(id);
  25. };
  26. return (
  27. <Fragment>
  28. <NameColumn>
  29. <Name>{debugId || uuid || `(${t('empty')})`}</Name>
  30. <TimeWrapper>
  31. <IconClock size="sm" />
  32. <TimeSince date={dateCreated} />
  33. </TimeWrapper>
  34. </NameColumn>
  35. <SizeColumn>
  36. <FileSize bytes={size} />
  37. </SizeColumn>
  38. <ActionsColumn>
  39. <ButtonBar gap={0.5}>
  40. <Role role={downloadRole}>
  41. {({hasRole}) => (
  42. <Tooltip
  43. title={t('You do not have permission to download mappings.')}
  44. disabled={hasRole}
  45. >
  46. <Button
  47. size="small"
  48. icon={<IconDownload size="sm" />}
  49. disabled={!hasRole}
  50. href={downloadUrl}
  51. title={hasRole ? t('Download Mapping') : undefined}
  52. />
  53. </Tooltip>
  54. )}
  55. </Role>
  56. <Access access={['project:releases']}>
  57. {({hasAccess}) => (
  58. <Tooltip
  59. disabled={hasAccess}
  60. title={t('You do not have permission to delete mappings.')}
  61. >
  62. <Confirm
  63. message={t('Are you sure you want to remove this mapping?')}
  64. onConfirm={handleDeleteClick}
  65. disabled={!hasAccess}
  66. >
  67. <Button
  68. size="small"
  69. icon={<IconDelete size="sm" />}
  70. title={hasAccess ? t('Remove Mapping') : undefined}
  71. label={t('Remove Mapping')}
  72. disabled={!hasAccess}
  73. />
  74. </Confirm>
  75. </Tooltip>
  76. )}
  77. </Access>
  78. </ButtonBar>
  79. </ActionsColumn>
  80. </Fragment>
  81. );
  82. };
  83. const NameColumn = styled('div')`
  84. display: flex;
  85. flex-direction: column;
  86. align-items: flex-start;
  87. justify-content: center;
  88. `;
  89. const SizeColumn = styled('div')`
  90. display: flex;
  91. justify-content: flex-end;
  92. text-align: right;
  93. align-items: center;
  94. `;
  95. const ActionsColumn = styled(SizeColumn)``;
  96. const Name = styled('div')`
  97. padding-right: ${space(4)};
  98. overflow-wrap: break-word;
  99. word-break: break-all;
  100. `;
  101. const TimeWrapper = styled('div')`
  102. display: grid;
  103. gap: ${space(0.5)};
  104. grid-template-columns: min-content 1fr;
  105. font-size: ${p => p.theme.fontSizeMedium};
  106. align-items: center;
  107. color: ${p => p.theme.subText};
  108. margin-top: ${space(1)};
  109. `;
  110. export default ProjectProguardRow;