repositoryProjectPathConfigForm.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import {Component} from 'react';
  2. import pick from 'lodash/pick';
  3. import {t} from 'sentry/locale';
  4. import {
  5. Integration,
  6. Organization,
  7. Project,
  8. Repository,
  9. RepositoryProjectPathConfig,
  10. } from 'sentry/types';
  11. import {trackIntegrationAnalytics} from 'sentry/utils/integrationUtil';
  12. import {FieldFromConfig} from 'sentry/views/settings/components/forms';
  13. import Form from 'sentry/views/settings/components/forms/form';
  14. import {Field} from 'sentry/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. trackIntegrationAnalytics('integrations.stacktrace_submit_config', {
  92. setup_type: 'manual',
  93. view: 'integration_configuration_detail',
  94. provider: this.props.integration.provider.key,
  95. organization: this.props.organization,
  96. });
  97. }
  98. render() {
  99. const {organization, onSubmitSuccess, onCancel, existingConfig} = this.props;
  100. // endpoint changes if we are making a new row or updating an existing one
  101. const baseEndpoint = `/organizations/${organization.slug}/code-mappings/`;
  102. const endpoint = existingConfig
  103. ? `${baseEndpoint}${existingConfig.id}/`
  104. : baseEndpoint;
  105. const apiMethod = existingConfig ? 'PUT' : 'POST';
  106. return (
  107. <Form
  108. onSubmitSuccess={onSubmitSuccess}
  109. onPreSubmit={() => this.handlePreSubmit()}
  110. initialData={this.initialData}
  111. apiEndpoint={endpoint}
  112. apiMethod={apiMethod}
  113. onCancel={onCancel}
  114. >
  115. {this.formFields.map(field => (
  116. <FieldFromConfig
  117. key={field.name}
  118. field={field}
  119. inline={false}
  120. stacked
  121. flexibleControlStateSize
  122. />
  123. ))}
  124. </Form>
  125. );
  126. }
  127. }