useHasData.tsx 971 B

1234567891011121314151617181920212223242526272829303132
  1. import type {PageFilters} from 'sentry/types';
  2. import type {MutableSearch} from 'sentry/utils/tokenizeSearch';
  3. import usePageFilters from 'sentry/utils/usePageFilters';
  4. import {useSpanMetrics} from 'sentry/views/insights/common/queries/useDiscover';
  5. export function useHasData(mutableSearch: MutableSearch, referrer: string) {
  6. const pageFilters = usePageFilters();
  7. const ninetyDayPageFilters: PageFilters = {
  8. ...pageFilters.selection,
  9. datetime: {
  10. period: '90d',
  11. start: null,
  12. end: null,
  13. utc: pageFilters.selection.datetime.utc,
  14. },
  15. };
  16. const {data, isLoading, error} = useSpanMetrics(
  17. {
  18. search: mutableSearch,
  19. fields: ['count()'],
  20. pageFilters: ninetyDayPageFilters,
  21. },
  22. referrer
  23. );
  24. if (isLoading) {
  25. return {hasData: false, isLoading: true};
  26. }
  27. if (data?.[0]?.['count()'] > 0) {
  28. return {hasData: true, isLoading: false, error};
  29. }
  30. return {hasData: false, isLoading: false, error};
  31. }