ownershipRules.tsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. import {Fragment} from 'react';
  2. import {ClassNames} from '@emotion/react';
  3. import styled from '@emotion/styled';
  4. import {openCreateOwnershipRule} from 'sentry/actionCreators/modal';
  5. import Access from 'sentry/components/acl/access';
  6. import GuideAnchor from 'sentry/components/assistant/guideAnchor';
  7. import Button from 'sentry/components/button';
  8. import ButtonBar from 'sentry/components/buttonBar';
  9. import HookOrDefault from 'sentry/components/hookOrDefault';
  10. import {Hovercard} from 'sentry/components/hovercard';
  11. import {Panel} from 'sentry/components/panels';
  12. import {IconClose, IconQuestion} from 'sentry/icons';
  13. import {t} from 'sentry/locale';
  14. import space from 'sentry/styles/space';
  15. import {CodeOwner, Organization, Project} from 'sentry/types';
  16. import {trackIntegrationAnalytics} from 'sentry/utils/integrationUtil';
  17. import SidebarSection from '../sidebarSection';
  18. type Props = {
  19. codeowners: CodeOwner[];
  20. handleCTAClose: () => void;
  21. isDismissed: boolean;
  22. issueId: string;
  23. organization: Organization;
  24. project: Project;
  25. };
  26. const CodeOwnersCTA = HookOrDefault({
  27. hookName: 'component:codeowners-cta',
  28. defaultComponent: ({organization, project}) => (
  29. <SetupButton
  30. size="xsmall"
  31. priority="primary"
  32. to={`/settings/${organization.slug}/projects/${project.slug}/ownership/`}
  33. onClick={() =>
  34. trackIntegrationAnalytics('integrations.code_owners_cta_setup_clicked', {
  35. view: 'stacktrace_issue_details',
  36. project_id: project.id,
  37. organization,
  38. })
  39. }
  40. >
  41. {t('Setup')}
  42. </SetupButton>
  43. ),
  44. });
  45. const OwnershipRules = ({
  46. project,
  47. organization,
  48. issueId,
  49. codeowners,
  50. isDismissed,
  51. handleCTAClose,
  52. }: Props) => {
  53. const handleOpenCreateOwnershipRule = () => {
  54. openCreateOwnershipRule({project, organization, issueId});
  55. };
  56. const showCTA = !codeowners.length && !isDismissed;
  57. const createRuleButton = (
  58. <Access access={['project:write']}>
  59. {({hasAccess}) => (
  60. <GuideAnchor target="owners" position="bottom" offset={space(3)}>
  61. <Button
  62. onClick={handleOpenCreateOwnershipRule}
  63. size="small"
  64. disabled={!hasAccess}
  65. title={t("You don't have permission to create ownership rules.")}
  66. tooltipProps={{disabled: hasAccess}}
  67. >
  68. {t('Create Ownership Rule')}
  69. </Button>
  70. </GuideAnchor>
  71. )}
  72. </Access>
  73. );
  74. const codeOwnersCTA = (
  75. <Container dashedBorder>
  76. <HeaderContainer>
  77. <Header>{t('Codeowners sync')}</Header>{' '}
  78. <DismissButton
  79. icon={<IconClose size="xs" />}
  80. priority="link"
  81. onClick={() => handleCTAClose()}
  82. aria-label={t('Close')}
  83. />
  84. </HeaderContainer>
  85. <Content>
  86. {t(
  87. 'Import GitHub or GitLab CODEOWNERS files to automatically assign issues to the right people.'
  88. )}
  89. </Content>
  90. <ButtonBar gap={1}>
  91. <CodeOwnersCTA organization={organization} project={project} />
  92. <Button
  93. size="xsmall"
  94. external
  95. href="https://docs.sentry.io/product/issues/issue-owners/#code-owners"
  96. onClick={() =>
  97. trackIntegrationAnalytics('integrations.code_owners_cta_docs_clicked', {
  98. view: 'stacktrace_issue_details',
  99. project_id: project.id,
  100. organization,
  101. })
  102. }
  103. >
  104. {t('Read Docs')}
  105. </Button>
  106. </ButtonBar>
  107. </Container>
  108. );
  109. return (
  110. <SidebarSection
  111. title={
  112. <Fragment>
  113. {t('Ownership Rules')}
  114. <ClassNames>
  115. {({css}) => (
  116. <Hovercard
  117. body={
  118. <HelpfulBody>
  119. <p>
  120. {t(
  121. 'Ownership rules allow you to associate file paths and URLs to specific teams or users, so alerts can be routed to the right people.'
  122. )}
  123. </p>
  124. <Button
  125. external
  126. href="https://docs.sentry.io/workflow/issue-owners/"
  127. priority="primary"
  128. >
  129. {t('Learn more')}
  130. </Button>
  131. </HelpfulBody>
  132. }
  133. containerClassName={css`
  134. display: flex;
  135. align-items: center;
  136. `}
  137. >
  138. <StyledIconQuestion size="xs" color="gray200" />
  139. </Hovercard>
  140. )}
  141. </ClassNames>
  142. </Fragment>
  143. }
  144. >
  145. {showCTA ? codeOwnersCTA : createRuleButton}
  146. </SidebarSection>
  147. );
  148. };
  149. export {OwnershipRules};
  150. const StyledIconQuestion = styled(IconQuestion)`
  151. margin-left: ${space(0.5)};
  152. `;
  153. const HelpfulBody = styled('div')`
  154. padding: ${space(1)};
  155. text-align: center;
  156. `;
  157. const Container = styled(Panel)`
  158. background: none;
  159. display: flex;
  160. flex-direction: column;
  161. padding: ${space(2)};
  162. `;
  163. const HeaderContainer = styled('div')`
  164. display: grid;
  165. grid-template-columns: max-content max-content 1fr;
  166. align-items: flex-start;
  167. `;
  168. const Header = styled('h6')`
  169. margin-bottom: ${space(1)};
  170. text-transform: uppercase;
  171. font-weight: bold;
  172. color: ${p => p.theme.gray300};
  173. font-size: ${p => p.theme.fontSizeExtraSmall};
  174. `;
  175. const Content = styled('span')`
  176. color: ${p => p.theme.textColor};
  177. margin-bottom: ${space(2)};
  178. `;
  179. const SetupButton = styled(Button)`
  180. &:focus {
  181. color: ${p => p.theme.white};
  182. }
  183. `;
  184. const DismissButton = styled(Button)`
  185. position: absolute;
  186. top: 0;
  187. right: ${space(1)};
  188. color: ${p => p.theme.gray400};
  189. `;