sentryAppExternalIssueModal.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import {Component, Fragment} from 'react';
  2. import {ModalRenderProps} from 'sentry/actionCreators/modal';
  3. import {Client} from 'sentry/api';
  4. import SentryAppExternalIssueForm from 'sentry/components/group/sentryAppExternalIssueForm';
  5. import NavTabs from 'sentry/components/navTabs';
  6. import {t, tct} from 'sentry/locale';
  7. import {
  8. Group,
  9. PlatformExternalIssue,
  10. SentryAppComponent,
  11. SentryAppInstallation,
  12. } from 'sentry/types';
  13. import {Event} from 'sentry/types/event';
  14. import withApi from 'sentry/utils/withApi';
  15. type Props = ModalRenderProps & {
  16. api: Client;
  17. event: Event;
  18. group: Group;
  19. onSubmitSuccess: (externalIssue: PlatformExternalIssue) => void;
  20. sentryAppComponent: SentryAppComponent;
  21. sentryAppInstallation: SentryAppInstallation;
  22. };
  23. type State = {
  24. action: 'create' | 'link';
  25. };
  26. class SentryAppExternalIssueModal extends Component<Props, State> {
  27. state: State = {
  28. action: 'create',
  29. };
  30. showLink = () => {
  31. this.setState({action: 'link'});
  32. };
  33. showCreate = () => {
  34. this.setState({action: 'create'});
  35. };
  36. onSubmitSuccess = (externalIssue: PlatformExternalIssue) => {
  37. this.props.onSubmitSuccess(externalIssue);
  38. this.props.closeModal();
  39. };
  40. render() {
  41. const {Header, Body, sentryAppComponent, sentryAppInstallation, group} = this.props;
  42. const {action} = this.state;
  43. const name = sentryAppComponent.sentryApp.name;
  44. const config = sentryAppComponent.schema[action];
  45. return (
  46. <Fragment>
  47. <Header closeButton>{tct('[name] Issue', {name})}</Header>
  48. <NavTabs underlined>
  49. <li className={action === 'create' ? 'active create' : 'create'}>
  50. <a onClick={this.showCreate}>{t('Create')}</a>
  51. </li>
  52. <li className={action === 'link' ? 'active link' : 'link'}>
  53. <a onClick={this.showLink}>{t('Link')}</a>
  54. </li>
  55. </NavTabs>
  56. <Body>
  57. <SentryAppExternalIssueForm
  58. group={group}
  59. sentryAppInstallation={sentryAppInstallation}
  60. appName={name}
  61. config={config}
  62. action={action}
  63. onSubmitSuccess={this.onSubmitSuccess}
  64. event={this.props.event}
  65. />
  66. </Body>
  67. </Fragment>
  68. );
  69. }
  70. }
  71. export default withApi(SentryAppExternalIssueModal);