repositoryEditForm.tsx 2.0 KB

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