repositoryEditForm.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import {Component} from 'react';
  2. import {FieldFromConfig} from 'sentry/components/forms';
  3. import Form from 'sentry/components/forms/form';
  4. import {Field} from 'sentry/components/forms/type';
  5. import ExternalLink from 'sentry/components/links/externalLink';
  6. import {t, tct} from 'sentry/locale';
  7. import {Repository} from 'sentry/types';
  8. import Alert from './alert';
  9. type Props = Pick<Form['props'], 'onSubmitSuccess' | 'onCancel'> & {
  10. closeModal: () => void;
  11. onSubmitSuccess: (data: any) => void;
  12. orgSlug: string;
  13. repository: Repository;
  14. };
  15. export default class RepositoryEditForm extends Component<Props> {
  16. get initialData() {
  17. const {repository} = this.props;
  18. return {
  19. name: repository.name,
  20. url: repository.url || '',
  21. };
  22. }
  23. get formFields(): Field[] {
  24. const fields: any[] = [
  25. {
  26. name: 'name',
  27. type: 'string',
  28. required: true,
  29. label: t('Name of your repository.'),
  30. },
  31. {
  32. name: 'url',
  33. type: 'string',
  34. required: false,
  35. label: t('Full URL to your repository.'),
  36. placeholder: t('https://github.com/my-org/my-repo/'),
  37. },
  38. ];
  39. return fields;
  40. }
  41. render() {
  42. const {onCancel, orgSlug, repository} = this.props;
  43. const endpoint = `/organizations/${orgSlug}/repos/${repository.id}/`;
  44. return (
  45. <Form
  46. initialData={this.initialData}
  47. onSubmitSuccess={data => {
  48. this.props.onSubmitSuccess(data);
  49. this.props.closeModal();
  50. }}
  51. apiEndpoint={endpoint}
  52. apiMethod="PUT"
  53. onCancel={onCancel}
  54. >
  55. <Alert type="warning" showIcon>
  56. {tct(
  57. 'Changing the [name:repo name] may have consequences if it no longer matches the repo name used when [link:sending commits with releases].',
  58. {
  59. link: (
  60. <ExternalLink href="https://docs.sentry.io/product/cli/releases/#sentry-cli-commit-integration" />
  61. ),
  62. name: <strong>repo name</strong>,
  63. }
  64. )}
  65. </Alert>
  66. {this.formFields.map(field => (
  67. <FieldFromConfig
  68. key={field.name}
  69. field={field}
  70. inline={false}
  71. stacked
  72. flexibleControlStateSize
  73. />
  74. ))}
  75. </Form>
  76. );
  77. }
  78. }