useMonitorCheckIns.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import {
  2. type ApiQueryKey,
  3. useApiQuery,
  4. type UseApiQueryOptions,
  5. } from 'sentry/utils/queryClient';
  6. import type {CheckIn} from 'sentry/views/monitors/types';
  7. interface MonitorChecksParameters {
  8. monitorIdOrSlug: string;
  9. orgSlug: string;
  10. projectSlug: string;
  11. cursor?: string;
  12. environment?: string[];
  13. expand?: 'groups';
  14. limit?: number;
  15. // Allows passing in arbitrary location query params
  16. queryParams?: Record<string, string | string[] | null | undefined>;
  17. }
  18. export function makeMonitorCheckInsQueryKey({
  19. orgSlug,
  20. projectSlug,
  21. monitorIdOrSlug,
  22. cursor,
  23. limit,
  24. environment,
  25. expand,
  26. queryParams,
  27. }: MonitorChecksParameters): ApiQueryKey {
  28. return [
  29. `/projects/${orgSlug}/${projectSlug}/monitors/${monitorIdOrSlug}/checkins/`,
  30. {query: {per_page: limit, cursor, environment, expand, ...queryParams}},
  31. ];
  32. }
  33. export function useMonitorCheckIns(
  34. params: MonitorChecksParameters,
  35. options: Partial<UseApiQueryOptions<CheckIn[]>> = {}
  36. ) {
  37. const queryKey = makeMonitorCheckInsQueryKey(params);
  38. return useApiQuery<CheckIn[]>(queryKey, {staleTime: 0, ...options});
  39. }