incident.tsx 2.4 KB

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