repositoryProjectPathConfigForm.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import React 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 React.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. deprecatedSelectControl: false,
  55. },
  56. {
  57. name: 'defaultBranch',
  58. type: 'string',
  59. required: true,
  60. label: t('Branch'),
  61. placeholder: t('Type your branch'),
  62. showHelpInTooltip: true,
  63. help: t(
  64. 'If an event does not have a release tied to a commit, we will use this branch when linking to your source code.'
  65. ),
  66. },
  67. {
  68. name: 'stackRoot',
  69. type: 'string',
  70. required: false,
  71. label: t('Stack Trace Root'),
  72. placeholder: t('Type root path of your stack traces'),
  73. showHelpInTooltip: true,
  74. help: t(
  75. 'Any stack trace starting with this path will be mapped with this rule. An empty string will match all paths.'
  76. ),
  77. },
  78. {
  79. name: 'sourceRoot',
  80. type: 'string',
  81. required: false,
  82. label: t('Source Code Root'),
  83. placeholder: t('Type root path of your source code, e.g. `src/`.'),
  84. showHelpInTooltip: true,
  85. help: t(
  86. '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.'
  87. ),
  88. },
  89. ];
  90. }
  91. handlePreSubmit() {
  92. trackIntegrationEvent(
  93. 'integrations.stacktrace_submit_config',
  94. {
  95. setup_type: 'manual',
  96. view: 'integration_configuration_detail',
  97. provider: this.props.integration.provider.key,
  98. },
  99. this.props.organization
  100. );
  101. }
  102. render() {
  103. const {organization, onSubmitSuccess, onCancel, existingConfig} = this.props;
  104. // endpoint changes if we are making a new row or updating an existing one
  105. const baseEndpoint = `/organizations/${organization.slug}/code-mappings/`;
  106. const endpoint = existingConfig
  107. ? `${baseEndpoint}${existingConfig.id}/`
  108. : baseEndpoint;
  109. const apiMethod = existingConfig ? 'PUT' : 'POST';
  110. return (
  111. <Form
  112. onSubmitSuccess={onSubmitSuccess}
  113. onPreSubmit={() => this.handlePreSubmit()}
  114. initialData={this.initialData}
  115. apiEndpoint={endpoint}
  116. apiMethod={apiMethod}
  117. onCancel={onCancel}
  118. >
  119. {this.formFields.map(field => (
  120. <FieldFromConfig
  121. key={field.name}
  122. field={field}
  123. inline={false}
  124. stacked
  125. flexibleControlStateSize
  126. />
  127. ))}
  128. </Form>
  129. );
  130. }
  131. }