useFetchThresholdsListData.tsx 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import {useApiQuery} from 'sentry/utils/queryClient';
  2. import useOrganization from 'sentry/utils/useOrganization';
  3. import type {Threshold, ThresholdQuery} from './types';
  4. export type HookProps = {
  5. selectedEnvs?: string[];
  6. selectedProjectIds?: number[];
  7. };
  8. export default function useFetchThresholdsListData({
  9. selectedEnvs = [],
  10. selectedProjectIds = [],
  11. }: HookProps) {
  12. const organization = useOrganization();
  13. const query: ThresholdQuery = {};
  14. if (selectedProjectIds.length) {
  15. query.project = selectedProjectIds;
  16. } else {
  17. query.project = [-1];
  18. }
  19. if (selectedEnvs.length) {
  20. query.environment = selectedEnvs;
  21. }
  22. return useApiQuery<Threshold[]>(
  23. [
  24. `/organizations/${organization.slug}/release-thresholds/`,
  25. {
  26. query,
  27. },
  28. ],
  29. {
  30. staleTime: 0,
  31. enabled:
  32. (organization.features?.includes('releases-v2-internal') ||
  33. organization.features?.includes('releases-v2') ||
  34. organization.features?.includes('releases-v2-st')) ??
  35. false,
  36. }
  37. );
  38. }