projectProguardRow.tsx 4.0 KB

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