useReleases.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import {Release} from 'sentry/types';
  2. import {useApiQuery} from 'sentry/utils/queryClient';
  3. import {decodeScalar} from 'sentry/utils/queryString';
  4. import {useLocation} from 'sentry/utils/useLocation';
  5. import useOrganization from 'sentry/utils/useOrganization';
  6. import usePageFilters from 'sentry/utils/usePageFilters';
  7. export function useReleases() {
  8. const organization = useOrganization();
  9. const {selection} = usePageFilters();
  10. const {environments, projects} = selection;
  11. return useApiQuery<Release[]>(
  12. [
  13. `/organizations/${organization.slug}/releases/`,
  14. {
  15. query: {
  16. sort: 'date',
  17. project: projects,
  18. per_page: 50,
  19. environment: environments,
  20. },
  21. },
  22. ],
  23. {staleTime: Infinity}
  24. );
  25. }
  26. export function useReleaseSelection() {
  27. const location = useLocation();
  28. const {data: releases, isLoading} = useReleases();
  29. const primaryRelease =
  30. decodeScalar(location.query.primaryRelease) ?? releases?.[0]?.version ?? undefined;
  31. const secondaryRelease =
  32. decodeScalar(location.query.secondaryRelease) ??
  33. (releases && releases.length > 1 ? releases?.[1]?.version : undefined);
  34. return {primaryRelease, secondaryRelease, isLoading};
  35. }