useMetricIncidents.tsx 972 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import {
  2. type ApiQueryKey,
  3. useApiQuery,
  4. type UseApiQueryOptions,
  5. } from 'sentry/utils/queryClient';
  6. import type {Incident} from 'sentry/views/alerts/types';
  7. interface MetricIncidentsParams {
  8. orgSlug: string;
  9. query?: {
  10. alertRule?: string;
  11. end?: string;
  12. expand?: string[];
  13. includeSnapshots?: boolean;
  14. project?: string;
  15. start?: string;
  16. };
  17. }
  18. export function makeMetricIncidentsQueryKey(params: MetricIncidentsParams): ApiQueryKey {
  19. const {orgSlug, query} = params;
  20. return [
  21. `/organizations/${orgSlug}/incidents/`,
  22. {
  23. query: {
  24. project: '-1',
  25. includeSnapshots: true,
  26. expand: ['activities', 'original_alert_rule'],
  27. ...query,
  28. },
  29. },
  30. ];
  31. }
  32. export function useMetricIncidents(
  33. params: MetricIncidentsParams,
  34. options: Partial<UseApiQueryOptions<Incident[]>> = {}
  35. ) {
  36. return useApiQuery<Incident[]>(makeMetricIncidentsQueryKey(params), {
  37. staleTime: 0,
  38. ...options,
  39. });
  40. }