projectProguardRow.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 {Button, LinkButton} 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 type {DebugFile} from 'sentry/types/debugFiles';
  16. import type {ProguardMappingAssociation} from 'sentry/views/settings/projectProguard';
  17. import {ProguardAssociations} from 'sentry/views/settings/projectProguard/associations';
  18. type Props = {
  19. downloadUrl: string;
  20. mapping: DebugFile;
  21. onDelete: (id: string) => void;
  22. orgSlug: string;
  23. associations?: ProguardMappingAssociation;
  24. };
  25. function ProjectProguardRow({
  26. associations = {releases: []},
  27. mapping,
  28. onDelete,
  29. downloadUrl,
  30. orgSlug,
  31. }: Props) {
  32. const {hasRole, roleRequired: downloadRole} = useRole({role: 'debugFilesRole'});
  33. const {id, debugId, uuid, size, dateCreated} = mapping;
  34. const handleDeleteClick = () => {
  35. onDelete(id);
  36. };
  37. return (
  38. <Fragment>
  39. <NameColumn>
  40. <Name>{debugId || uuid || `(${t('empty')})`}</Name>
  41. <ProguardAssociations associations={associations} />
  42. <TimeWrapper>
  43. <IconClock size="sm" />
  44. <TimeSince date={dateCreated} />
  45. </TimeWrapper>
  46. </NameColumn>
  47. <SizeColumn>
  48. <FileSize bytes={size} />
  49. </SizeColumn>
  50. <ActionsColumn>
  51. <ButtonBar gap={0.5}>
  52. <Tooltip
  53. title={tct(
  54. 'Mappings can only be downloaded by users with organization [downloadRole] role[orHigher]. This can be changed in [settingsLink:Debug Files Access] settings.',
  55. {
  56. downloadRole,
  57. orHigher: downloadRole !== 'owner' ? ` ${t('or higher')}` : '',
  58. settingsLink: <Link to={`/settings/${orgSlug}/#debugFilesRole`} />,
  59. }
  60. )}
  61. disabled={hasRole}
  62. isHoverable
  63. >
  64. <LinkButton
  65. size="sm"
  66. icon={<IconDownload size="sm" />}
  67. disabled={!hasRole}
  68. href={downloadUrl}
  69. title={hasRole ? t('Download Mapping') : undefined}
  70. aria-label={t('Download Mapping')}
  71. />
  72. </Tooltip>
  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;