useFetchThresholdsListData.tsx 978 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import {useApiQuery} from 'sentry/utils/queryClient';
  2. import useOrganization from 'sentry/utils/useOrganization';
  3. import {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') ||
  33. organization.features?.includes('releases-v2-st')) ??
  34. false,
  35. }
  36. );
  37. }