apiCalls.tsx 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import {Client} from 'sentry/api';
  2. import {MetricRule} from 'sentry/views/alerts/rules/metric/types';
  3. import type {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. alertRule: string,
  19. start: string,
  20. end: string
  21. ): Promise<Incident[]> {
  22. return uncancellableApi.requestPromise(`/organizations/${orgId}/incidents/`, {
  23. query: {
  24. project: '-1',
  25. alertRule,
  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. }