repositoryProjectPathConfigRow.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import {Component, Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import Access from 'sentry/components/acl/access';
  4. import Button from 'sentry/components/button';
  5. import Confirm from 'sentry/components/confirm';
  6. import IdBadge from 'sentry/components/idBadge';
  7. import Tooltip from 'sentry/components/tooltip';
  8. import {IconDelete, IconEdit} from 'sentry/icons';
  9. import {t} from 'sentry/locale';
  10. import space from 'sentry/styles/space';
  11. import {Project, RepositoryProjectPathConfig} from 'sentry/types';
  12. type Props = {
  13. onDelete: (pathConfig: RepositoryProjectPathConfig) => void;
  14. onEdit: (pathConfig: RepositoryProjectPathConfig) => void;
  15. pathConfig: RepositoryProjectPathConfig;
  16. project: Project;
  17. };
  18. export default class RepositoryProjectPathConfigRow extends Component<Props> {
  19. render() {
  20. const {pathConfig, project, onEdit, onDelete} = this.props;
  21. return (
  22. <Access access={['org:integrations']}>
  23. {({hasAccess}) => (
  24. <Fragment>
  25. <NameRepoColumn>
  26. <ProjectRepoHolder>
  27. <RepoName>{pathConfig.repoName}</RepoName>
  28. <ProjectAndBranch>
  29. <IdBadge
  30. project={project}
  31. avatarSize={14}
  32. displayName={project.slug}
  33. avatarProps={{consistentWidth: true}}
  34. />
  35. <BranchWrapper>&nbsp;|&nbsp;{pathConfig.defaultBranch}</BranchWrapper>
  36. </ProjectAndBranch>
  37. </ProjectRepoHolder>
  38. </NameRepoColumn>
  39. <OutputPathColumn>{pathConfig.sourceRoot}</OutputPathColumn>
  40. <InputPathColumn>{pathConfig.stackRoot}</InputPathColumn>
  41. <ButtonColumn>
  42. <Tooltip
  43. title={t(
  44. 'You must be an organization owner, manager or admin to edit or remove a code mapping.'
  45. )}
  46. disabled={hasAccess}
  47. >
  48. <StyledButton
  49. size="sm"
  50. icon={<IconEdit size="sm" />}
  51. aria-label={t('edit')}
  52. disabled={!hasAccess}
  53. onClick={() => onEdit(pathConfig)}
  54. />
  55. <Confirm
  56. disabled={!hasAccess}
  57. onConfirm={() => onDelete(pathConfig)}
  58. message={t('Are you sure you want to remove this code mapping?')}
  59. >
  60. <StyledButton
  61. size="sm"
  62. icon={<IconDelete size="sm" />}
  63. aria-label={t('delete')}
  64. disabled={!hasAccess}
  65. />
  66. </Confirm>
  67. </Tooltip>
  68. </ButtonColumn>
  69. </Fragment>
  70. )}
  71. </Access>
  72. );
  73. }
  74. }
  75. const ProjectRepoHolder = styled('div')`
  76. display: flex;
  77. flex-direction: column;
  78. `;
  79. const RepoName = styled(`span`)`
  80. padding-bottom: ${space(1)};
  81. `;
  82. const StyledButton = styled(Button)`
  83. margin: ${space(0.5)};
  84. `;
  85. const ProjectAndBranch = styled('div')`
  86. display: flex;
  87. flex-direction: row;
  88. color: ${p => p.theme.gray300};
  89. `;
  90. // match the line height of the badge
  91. const BranchWrapper = styled('div')`
  92. line-height: 1.2;
  93. `;
  94. // Columns below
  95. const Column = styled('span')`
  96. overflow: hidden;
  97. overflow-wrap: break-word;
  98. `;
  99. export const NameRepoColumn = styled(Column)`
  100. grid-area: name-repo;
  101. `;
  102. export const OutputPathColumn = styled(Column)`
  103. grid-area: output-path;
  104. `;
  105. export const InputPathColumn = styled(Column)`
  106. grid-area: input-path;
  107. `;
  108. export const ButtonColumn = styled(Column)`
  109. grid-area: button;
  110. text-align: right;
  111. `;