apiCalls.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import {Client} from 'sentry/api';
  2. import type {MetricRule} from 'sentry/views/alerts/rules/metric/types';
  3. import type {Anomaly, Incident} from '../types';
  4. // Use this api for requests that are getting cancelled
  5. const uncancellableApi = new Client();
  6. export function fetchAlertRule(
  7. orgId: string,
  8. ruleId: string,
  9. query?: Record<string, string>
  10. ): Promise<MetricRule> {
  11. return uncancellableApi.requestPromise(
  12. `/organizations/${orgId}/alert-rules/${ruleId}/`,
  13. {query}
  14. );
  15. }
  16. export function fetchIncidentsForRule(
  17. orgId: string,
  18. ruleId: string,
  19. start: string,
  20. end: string
  21. ): Promise<Incident[]> {
  22. return uncancellableApi.requestPromise(`/organizations/${orgId}/incidents/`, {
  23. query: {
  24. project: '-1',
  25. alertRule: ruleId,
  26. includeSnapshots: true,
  27. start,
  28. end,
  29. expand: ['activities', 'seen_by', 'original_alert_rule'],
  30. },
  31. });
  32. }
  33. export function fetchIncident(
  34. api: Client,
  35. orgId: string,
  36. alertId: string
  37. ): Promise<Incident> {
  38. return api.requestPromise(`/organizations/${orgId}/incidents/${alertId}/`);
  39. }
  40. export function fetchAnomaliesForRule(
  41. orgId: string,
  42. ruleId: string,
  43. start: string,
  44. end: string
  45. ): Promise<Anomaly[]> {
  46. return uncancellableApi.requestPromise(
  47. `/organizations/${orgId}/alert-rules/${ruleId}/anomalies/`,
  48. {
  49. query: {
  50. start,
  51. end,
  52. },
  53. }
  54. );
  55. }