monitors.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. ) {
  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. } catch {
  37. addErrorMessage(t('Unable to remove environment from monitor.'));
  38. }
  39. }
  40. export async function updateMonitor(
  41. api: Client,
  42. orgId: string,
  43. monitorSlug: string,
  44. data: Partial<Monitor>
  45. ) {
  46. addLoadingMessage();
  47. try {
  48. const resp = await api.requestPromise(
  49. `/organizations/${orgId}/monitors/${monitorSlug}/`,
  50. {method: 'PUT', data}
  51. );
  52. clearIndicators();
  53. return resp;
  54. } catch (err) {
  55. logException(err);
  56. addErrorMessage(t('Unable to update monitor.'));
  57. }
  58. return null;
  59. }