monitors.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import {
  2. addErrorMessage,
  3. addLoadingMessage,
  4. clearIndicators,
  5. } from 'sentry/actionCreators/indicator';
  6. import {Client} from 'sentry/api';
  7. import {t} from 'sentry/locale';
  8. import {logException} from 'sentry/utils/logging';
  9. import {Monitor} from 'sentry/views/monitors/types';
  10. export async function deleteMonitor(api: Client, orgId: string, monitorSlug: string) {
  11. addLoadingMessage(t('Deleting Monitor...'));
  12. try {
  13. await api.requestPromise(`/organizations/${orgId}/monitors/${monitorSlug}/`, {
  14. method: 'DELETE',
  15. });
  16. clearIndicators();
  17. } catch {
  18. addErrorMessage(t('Unable to remove monitor.'));
  19. }
  20. }
  21. export async function deleteMonitorEnvironment(
  22. api: Client,
  23. orgId: string,
  24. monitorSlug: string,
  25. environment: string
  26. ): Promise<boolean> {
  27. addLoadingMessage(t('Deleting Environment...'));
  28. try {
  29. await api.requestPromise(`/organizations/${orgId}/monitors/${monitorSlug}/`, {
  30. method: 'DELETE',
  31. query: {
  32. environment,
  33. },
  34. });
  35. clearIndicators();
  36. return true;
  37. } catch {
  38. addErrorMessage(t('Unable to remove environment from monitor.'));
  39. }
  40. return false;
  41. }
  42. export async function updateMonitor(
  43. api: Client,
  44. orgId: string,
  45. monitorSlug: string,
  46. data: Partial<Monitor>
  47. ): Promise<Monitor | null> {
  48. addLoadingMessage();
  49. try {
  50. const resp = await api.requestPromise(
  51. `/organizations/${orgId}/monitors/${monitorSlug}/`,
  52. {method: 'PUT', data}
  53. );
  54. clearIndicators();
  55. return resp;
  56. } catch (err) {
  57. logException(err);
  58. addErrorMessage(t('Unable to update monitor.'));
  59. }
  60. return null;
  61. }
  62. export async function setEnvironmentIsMuted(
  63. api: Client,
  64. orgId: string,
  65. monitorSlug: string,
  66. environment: string,
  67. isMuted: boolean
  68. ) {
  69. addLoadingMessage();
  70. try {
  71. const resp = await api.requestPromise(
  72. `/organizations/${orgId}/monitors/${monitorSlug}/environments/${environment}`,
  73. {method: 'PUT', data: {isMuted}}
  74. );
  75. clearIndicators();
  76. return resp;
  77. } catch (err) {
  78. logException(err);
  79. addErrorMessage(
  80. isMuted ? t('Unable to mute environment.') : t('Unable to unmute environment.')
  81. );
  82. }
  83. return null;
  84. }