monitors.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. ) {
  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. }