12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import {EventsStats, MultiSeriesEventsStats} from 'sentry/types';
- import EventView, {encodeSort} from 'sentry/utils/discover/eventView';
- import {
- DiscoverQueryProps,
- useGenericDiscoverQuery,
- } from 'sentry/utils/discover/genericDiscoverQuery';
- import {useLocation} from 'sentry/utils/useLocation';
- import useOrganization from 'sentry/utils/useOrganization';
- export function useEventsStatsQuery({
- eventView,
- enabled,
- initialData,
- referrer,
- }: {
- eventView: EventView;
- enabled?: boolean;
- initialData?: any;
- referrer?: string;
- }) {
- const location = useLocation();
- const organization = useOrganization();
- const {isLoading, data, isError} = useGenericDiscoverQuery<
- EventsStats | MultiSeriesEventsStats,
- DiscoverQueryProps
- >({
- route: 'events-stats',
- eventView,
- location,
- orgSlug: organization.slug,
- getRequestPayload: () => ({
- ...eventView.getEventsAPIPayload(location),
- yAxis: eventView.yAxis,
- topEvents: eventView.topEvents,
- excludeOther: 0,
- partial: 1,
- orderby: eventView.sorts?.[0] ? encodeSort(eventView.sorts?.[0]) : undefined,
- interval: eventView.interval,
- }),
- options: {
- enabled,
- retry: false,
- refetchOnWindowFocus: false,
- },
- referrer,
- });
- return {
- isLoading,
- data: isLoading && initialData ? initialData : data,
- isError,
- };
- }
|