useFetchThresholdsListData.tsx 901 B

123456789101112131415161718192021222324252627282930313233343536373839
  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.id}/release-thresholds/`,
  25. {
  26. query,
  27. },
  28. ],
  29. {
  30. staleTime: 0,
  31. enabled: organization.features?.includes('event-attachments') ?? false,
  32. }
  33. );
  34. }