index.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import React from 'react';
  2. import {RouteComponentProps} from 'react-router';
  3. import {openEditOwnershipRules} from 'app/actionCreators/modal';
  4. import Feature from 'app/components/acl/feature';
  5. import Button from 'app/components/button';
  6. import ExternalLink from 'app/components/links/externalLink';
  7. import {t, tct} from 'app/locale';
  8. import {Organization, Project} from 'app/types';
  9. import routeTitleGen from 'app/utils/routeTitle';
  10. import AsyncView from 'app/views/asyncView';
  11. import Form from 'app/views/settings/components/forms/form';
  12. import JsonForm from 'app/views/settings/components/forms/jsonForm';
  13. import SettingsPageHeader from 'app/views/settings/components/settingsPageHeader';
  14. import PermissionAlert from 'app/views/settings/project/permissionAlert';
  15. import CodeOwnersPanel from 'app/views/settings/project/projectOwnership/codeowners';
  16. import RulesPanel from 'app/views/settings/project/projectOwnership/rulesPanel';
  17. type Props = {
  18. organization: Organization;
  19. project: Project;
  20. } & RouteComponentProps<{orgId: string; projectId: string}, {}>;
  21. type State = {
  22. ownership: null | any;
  23. } & AsyncView['state'];
  24. class ProjectOwnership extends AsyncView<Props, State> {
  25. getTitle() {
  26. const {project} = this.props;
  27. return routeTitleGen(t('Issue Owners'), project.slug, false);
  28. }
  29. getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
  30. const {organization, project} = this.props;
  31. return [['ownership', `/projects/${organization.slug}/${project.slug}/ownership/`]];
  32. }
  33. getPlaceholder() {
  34. return `#example usage
  35. path:src/example/pipeline/* person@sentry.io #infra
  36. url:http://example.com/settings/* #product
  37. tags.sku_class:enterprise #enterprise`;
  38. }
  39. getDetail() {
  40. return tct(
  41. `Automatically assign issues and send alerts to the right people based on issue properties. [link:Learn more].`,
  42. {
  43. link: (
  44. <ExternalLink href="https://docs.sentry.io/product/error-monitoring/issue-owners/" />
  45. ),
  46. }
  47. );
  48. }
  49. handleOwnershipSave = (text: string | null) => {
  50. this.setState(prevState => ({
  51. ownership: {
  52. ...prevState.ownership,
  53. raw: text,
  54. },
  55. }));
  56. };
  57. renderBody() {
  58. const {project, organization} = this.props;
  59. const {ownership} = this.state;
  60. const disabled = !organization.access.includes('project:write');
  61. return (
  62. <React.Fragment>
  63. <SettingsPageHeader
  64. title={t('Issue Owners')}
  65. action={
  66. <Button
  67. to={{
  68. pathname: `/organizations/${organization.slug}/issues/`,
  69. query: {project: project.id},
  70. }}
  71. size="small"
  72. >
  73. {t('View Issues')}
  74. </Button>
  75. }
  76. />
  77. <PermissionAlert />
  78. <RulesPanel
  79. data-test-id="issueowners-panel"
  80. type="issueowners"
  81. raw={ownership.raw || ''}
  82. dateUpdated={ownership.lastUpdated}
  83. placeholder={this.getPlaceholder()}
  84. detail={this.getDetail()}
  85. controls={[
  86. <Button
  87. key="edit"
  88. size="small"
  89. onClick={() =>
  90. openEditOwnershipRules({
  91. organization,
  92. project,
  93. ownership,
  94. onSave: this.handleOwnershipSave,
  95. })
  96. }
  97. disabled={disabled}
  98. >
  99. {t('Edit')}
  100. </Button>,
  101. ]}
  102. />
  103. <Feature features={['import-codeowners']}>
  104. <CodeOwnersPanel {...this.props} />
  105. </Feature>
  106. <Form
  107. apiEndpoint={`/projects/${organization.slug}/${project.slug}/ownership/`}
  108. apiMethod="PUT"
  109. saveOnBlur
  110. initialData={{fallthrough: ownership.fallthrough}}
  111. hideFooter
  112. >
  113. <JsonForm
  114. forms={[
  115. {
  116. title: t('If ownership cannot be determined for an issue...'),
  117. fields: [
  118. {
  119. name: 'fallthrough',
  120. type: 'boolean',
  121. label: t('All users with access to this project are issue owners'),
  122. help: t(
  123. 'Issue owners will receive notifications for issues they are responsible for.'
  124. ),
  125. disabled,
  126. },
  127. ],
  128. },
  129. ]}
  130. />
  131. </Form>
  132. <Form
  133. apiEndpoint={`/projects/${organization.slug}/${project.slug}/ownership/`}
  134. apiMethod="PUT"
  135. saveOnBlur
  136. initialData={{autoAssignment: ownership.autoAssignment}}
  137. hideFooter
  138. >
  139. <JsonForm
  140. forms={[
  141. {
  142. title: t('If a new event matches any of the ownership rules...'),
  143. fields: [
  144. {
  145. name: 'autoAssignment',
  146. type: 'boolean',
  147. label: t('The issue is assigned to the team or user'),
  148. help: t('Issue owners will be automatically assigned.'),
  149. disabled,
  150. },
  151. ],
  152. },
  153. ]}
  154. />
  155. </Form>
  156. </React.Fragment>
  157. );
  158. }
  159. }
  160. export default ProjectOwnership;