repositoryProjectPathConfigRow.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import {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 function RepositoryProjectPathConfigRow({
  19. pathConfig,
  20. project,
  21. onEdit,
  22. onDelete,
  23. }: Props) {
  24. return (
  25. <Fragment>
  26. <NameRepoColumn>
  27. <ProjectRepoHolder>
  28. <RepoName>{pathConfig.repoName}</RepoName>
  29. <ProjectAndBranch>
  30. <IdBadge
  31. project={project}
  32. avatarSize={14}
  33. displayName={project.slug}
  34. avatarProps={{consistentWidth: true}}
  35. />
  36. <BranchWrapper>&nbsp;|&nbsp;{pathConfig.defaultBranch}</BranchWrapper>
  37. </ProjectAndBranch>
  38. </ProjectRepoHolder>
  39. </NameRepoColumn>
  40. <OutputPathColumn>{pathConfig.sourceRoot}</OutputPathColumn>
  41. <InputPathColumn>{pathConfig.stackRoot}</InputPathColumn>
  42. <ButtonWrapper>
  43. <Button
  44. size="sm"
  45. icon={<IconEdit size="sm" />}
  46. aria-label={t('edit')}
  47. onClick={() => onEdit(pathConfig)}
  48. />
  49. <Access access={['org:integrations']}>
  50. {({hasAccess}) => (
  51. <Tooltip
  52. title={t(
  53. 'You must be an organization owner, manager or admin to remove a code mapping.'
  54. )}
  55. disabled={hasAccess}
  56. >
  57. <Confirm
  58. onConfirm={() => onDelete(pathConfig)}
  59. message={t('Are you sure you want to remove this code mapping?')}
  60. disabled={!hasAccess}
  61. >
  62. <Button
  63. size="sm"
  64. icon={<IconDelete size="sm" />}
  65. aria-label={t('delete')}
  66. disabled={!hasAccess}
  67. />
  68. </Confirm>
  69. </Tooltip>
  70. )}
  71. </Access>
  72. </ButtonWrapper>
  73. </Fragment>
  74. );
  75. }
  76. const ProjectRepoHolder = styled('div')`
  77. display: flex;
  78. flex-direction: column;
  79. `;
  80. const RepoName = styled(`span`)`
  81. padding-bottom: ${space(1)};
  82. `;
  83. const ProjectAndBranch = styled('div')`
  84. display: flex;
  85. flex-direction: row;
  86. color: ${p => p.theme.gray300};
  87. `;
  88. // match the line height of the badge
  89. const BranchWrapper = styled('div')`
  90. line-height: 1.2;
  91. `;
  92. // Columns below
  93. const Column = styled('span')`
  94. overflow: hidden;
  95. overflow-wrap: break-word;
  96. `;
  97. export const NameRepoColumn = styled(Column)`
  98. grid-area: name-repo;
  99. `;
  100. export const OutputPathColumn = styled(Column)`
  101. grid-area: output-path;
  102. `;
  103. export const InputPathColumn = styled(Column)`
  104. grid-area: input-path;
  105. `;
  106. export const ButtonWrapper = styled(Column)`
  107. display: flex;
  108. gap: ${space(1)};
  109. `;