sentryAppExternalIssueForm.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import {Component} from 'react';
  2. import {t} from 'sentry/locale';
  3. import ExternalIssueStore from 'sentry/stores/externalIssueStore';
  4. import {Group, PlatformExternalIssue, SentryAppInstallation} from 'sentry/types';
  5. import {Event} from 'sentry/types/event';
  6. import getStacktraceBody from 'sentry/utils/getStacktraceBody';
  7. import {addQueryParamsToExistingUrl} from 'sentry/utils/queryString';
  8. import SentryAppExternalForm, {
  9. FieldFromSchema,
  10. SchemaFormConfig,
  11. } from 'sentry/views/organizationIntegrations/sentryAppExternalForm';
  12. type Props = {
  13. action: 'create' | 'link';
  14. appName: string;
  15. config: SchemaFormConfig;
  16. event: Event;
  17. group: Group;
  18. onSubmitSuccess: (externalIssue: PlatformExternalIssue) => void;
  19. sentryAppInstallation: SentryAppInstallation;
  20. };
  21. export class SentryAppExternalIssueForm extends Component<Props> {
  22. onSubmitSuccess = (issue: PlatformExternalIssue) => {
  23. ExternalIssueStore.add(issue);
  24. this.props.onSubmitSuccess(issue);
  25. };
  26. getStacktrace() {
  27. const evt = this.props.event;
  28. const contentArr = getStacktraceBody(evt);
  29. if (contentArr && contentArr.length > 0) {
  30. return '\n\n```\n' + contentArr[0] + '\n```';
  31. }
  32. return '';
  33. }
  34. getFieldDefault(field: FieldFromSchema) {
  35. const {group, appName} = this.props;
  36. if (field.type === 'textarea') {
  37. field.maxRows = 10;
  38. field.autosize = true;
  39. }
  40. switch (field.default) {
  41. case 'issue.title':
  42. return group.title;
  43. case 'issue.description':
  44. const stacktrace = this.getStacktrace();
  45. const queryParams = {referrer: appName};
  46. const url = addQueryParamsToExistingUrl(group.permalink, queryParams);
  47. const shortId = group.shortId;
  48. return t('Sentry Issue: [%s](%s)%s', shortId, url, stacktrace);
  49. default:
  50. return '';
  51. }
  52. }
  53. render() {
  54. return (
  55. <SentryAppExternalForm
  56. sentryAppInstallationUuid={this.props.sentryAppInstallation.uuid}
  57. appName={this.props.appName}
  58. config={this.props.config}
  59. action={this.props.action}
  60. element="issue-link"
  61. extraFields={{groupId: this.props.group.id}}
  62. extraRequestBody={{projectId: this.props.group.project.id}}
  63. onSubmitSuccess={this.onSubmitSuccess}
  64. // Needs to bind to access this.props
  65. getFieldDefault={field => this.getFieldDefault(field)}
  66. />
  67. );
  68. }
  69. }
  70. export default SentryAppExternalIssueForm;