repositoryProjectPathConfigForm.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import {Component} from 'react';
  2. import pick from 'lodash/pick';
  3. import {t} from 'app/locale';
  4. import {
  5. Integration,
  6. Organization,
  7. Project,
  8. Repository,
  9. RepositoryProjectPathConfig,
  10. } from 'app/types';
  11. import {trackIntegrationEvent} from 'app/utils/integrationUtil';
  12. import {FieldFromConfig} from 'app/views/settings/components/forms';
  13. import Form from 'app/views/settings/components/forms/form';
  14. import {Field} from 'app/views/settings/components/forms/type';
  15. type Props = {
  16. organization: Organization;
  17. integration: Integration;
  18. projects: Project[];
  19. repos: Repository[];
  20. onSubmitSuccess: Form['props']['onSubmitSuccess'];
  21. onCancel: Form['props']['onCancel'];
  22. existingConfig?: RepositoryProjectPathConfig;
  23. };
  24. export default class RepositoryProjectPathConfigForm extends Component<Props> {
  25. get initialData() {
  26. const {existingConfig, integration} = this.props;
  27. return {
  28. defaultBranch: 'master',
  29. stackRoot: '',
  30. sourceRoot: '',
  31. repositoryId: existingConfig?.repoId,
  32. integrationId: integration.id,
  33. ...pick(existingConfig, ['projectId', 'defaultBranch', 'stackRoot', 'sourceRoot']),
  34. };
  35. }
  36. get formFields(): Field[] {
  37. const {projects, repos} = this.props;
  38. const repoChoices = repos.map(({name, id}) => ({value: id, label: name}));
  39. return [
  40. {
  41. name: 'projectId',
  42. type: 'sentry_project_selector',
  43. required: true,
  44. label: t('Project'),
  45. projects,
  46. },
  47. {
  48. name: 'repositoryId',
  49. type: 'select',
  50. required: true,
  51. label: t('Repo'),
  52. placeholder: t('Choose repo'),
  53. options: repoChoices,
  54. },
  55. {
  56. name: 'defaultBranch',
  57. type: 'string',
  58. required: true,
  59. label: t('Branch'),
  60. placeholder: t('Type your branch'),
  61. showHelpInTooltip: true,
  62. help: t(
  63. 'If an event does not have a release tied to a commit, we will use this branch when linking to your source code.'
  64. ),
  65. },
  66. {
  67. name: 'stackRoot',
  68. type: 'string',
  69. required: false,
  70. label: t('Stack Trace Root'),
  71. placeholder: t('Type root path of your stack traces'),
  72. showHelpInTooltip: true,
  73. help: t(
  74. 'Any stack trace starting with this path will be mapped with this rule. An empty string will match all paths.'
  75. ),
  76. },
  77. {
  78. name: 'sourceRoot',
  79. type: 'string',
  80. required: false,
  81. label: t('Source Code Root'),
  82. placeholder: t('Type root path of your source code, e.g. `src/`.'),
  83. showHelpInTooltip: true,
  84. help: t(
  85. 'When a rule matches, the stack trace root is replaced with this path to get the path in your repository. Leaving this empty means replacing the stack trace root with an empty string.'
  86. ),
  87. },
  88. ];
  89. }
  90. handlePreSubmit() {
  91. trackIntegrationEvent(
  92. 'integrations.stacktrace_submit_config',
  93. {
  94. setup_type: 'manual',
  95. view: 'integration_configuration_detail',
  96. provider: this.props.integration.provider.key,
  97. },
  98. this.props.organization
  99. );
  100. }
  101. render() {
  102. const {organization, onSubmitSuccess, onCancel, existingConfig} = this.props;
  103. // endpoint changes if we are making a new row or updating an existing one
  104. const baseEndpoint = `/organizations/${organization.slug}/code-mappings/`;
  105. const endpoint = existingConfig
  106. ? `${baseEndpoint}${existingConfig.id}/`
  107. : baseEndpoint;
  108. const apiMethod = existingConfig ? 'PUT' : 'POST';
  109. return (
  110. <Form
  111. onSubmitSuccess={onSubmitSuccess}
  112. onPreSubmit={() => this.handlePreSubmit()}
  113. initialData={this.initialData}
  114. apiEndpoint={endpoint}
  115. apiMethod={apiMethod}
  116. onCancel={onCancel}
  117. >
  118. {this.formFields.map(field => (
  119. <FieldFromConfig
  120. key={field.name}
  121. field={field}
  122. inline={false}
  123. stacked
  124. flexibleControlStateSize
  125. />
  126. ))}
  127. </Form>
  128. );
  129. }
  130. }