incident.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import {addErrorMessage, clearIndicators} from 'sentry/actionCreators/indicator';
  2. import {Client} from 'sentry/api';
  3. import {t} from 'sentry/locale';
  4. import {NoteType} from 'sentry/types/alerts';
  5. /**
  6. * Fetches a list of activities for an incident
  7. */
  8. export async function fetchIncidentActivities(
  9. api: Client,
  10. orgId: string,
  11. alertId: string
  12. ) {
  13. return api.requestPromise(`/organizations/${orgId}/incidents/${alertId}/activity/`);
  14. }
  15. /**
  16. * Creates a note for an incident
  17. */
  18. export async function createIncidentNote(
  19. api: Client,
  20. orgId: string,
  21. alertId: string,
  22. note: NoteType
  23. ) {
  24. try {
  25. const result = await api.requestPromise(
  26. `/organizations/${orgId}/incidents/${alertId}/comments/`,
  27. {
  28. method: 'POST',
  29. data: {
  30. mentions: note.mentions,
  31. comment: note.text,
  32. },
  33. }
  34. );
  35. return result;
  36. } catch (err) {
  37. addErrorMessage(t('Unable to post comment'));
  38. throw err;
  39. }
  40. }
  41. /**
  42. * Deletes a note for an incident
  43. */
  44. export async function deleteIncidentNote(
  45. api: Client,
  46. orgId: string,
  47. alertId: string,
  48. noteId: string
  49. ) {
  50. try {
  51. const result = await api.requestPromise(
  52. `/organizations/${orgId}/incidents/${alertId}/comments/${noteId}/`,
  53. {
  54. method: 'DELETE',
  55. }
  56. );
  57. return result;
  58. } catch (err) {
  59. addErrorMessage(t('Failed to delete comment'));
  60. throw err;
  61. }
  62. }
  63. /**
  64. * Updates a note for an incident
  65. */
  66. export async function updateIncidentNote(
  67. api: Client,
  68. orgId: string,
  69. alertId: string,
  70. noteId: string,
  71. note: NoteType
  72. ) {
  73. try {
  74. const result = await api.requestPromise(
  75. `/organizations/${orgId}/incidents/${alertId}/comments/${noteId}/`,
  76. {
  77. method: 'PUT',
  78. data: {
  79. mentions: note.mentions,
  80. comment: note.text,
  81. },
  82. }
  83. );
  84. clearIndicators();
  85. return result;
  86. } catch (err) {
  87. addErrorMessage(t('Unable to update comment'));
  88. throw err;
  89. }
  90. }
  91. // This doesn't return anything because you shouldn't need to do anything with
  92. // the result success or fail
  93. export async function markIncidentAsSeen(api: Client, orgId: string, incident) {
  94. if (!incident || incident.hasSeen) {
  95. return;
  96. }
  97. try {
  98. await api.requestPromise(
  99. `/organizations/${orgId}/incidents/${incident.identifier}/seen/`,
  100. {
  101. method: 'POST',
  102. data: {
  103. hasSeen: true,
  104. },
  105. }
  106. );
  107. } catch (err) {
  108. // do nothing
  109. }
  110. }