SIGN IN SIGN UP

Refactor FE API v2 interface + current visitors bugfix (#6351)

* more specific type to event:props:* dimension

* rename use-order-by.ts -> use-metric-order-by.ts

* SortDirection: use string union type from query-api-schema instead of enum

* use query-api-schema pagination type too

* add proper OrderBy type (with dimensions) and separate MetricOrderBy

* use NonTimeDimension type in v2 breakdown components

* also create a Dimension type (incl time dims)

* create use-query-api.ts

- usePaginatedQueryApi -> useSearchAndPaginateQueryApi (include addSearchFilter logic in the hook)
- enforce dimensions on ReportParams type and make it a part of queryKey
- define explicit StatsReportQueryKey type

* add a useQueryApi hook and use it in IndexBreakdown

The new hook also includes automatic realtime re-fetch logic.

* Add CurrentVisitorsContext

- fixes a bug: current visitors in realtime top stats, in shared links limited to segment, are fetched from /query api which enforces segment filter -> 400 Bad Request
- uses Tanstack useQuery against the old GET endpoint
- The value is now also cached for 30s (CACHE_TTL_REALTIME)
- Do not fetch current visitors at all when not needed (i.e. not realtime and dashboard has filters applied).
- The same context value is now used by both top-stats.js and current-visitors.js

* top stats and main graph to useQueryApi

* DetailsBreakdown: addSearchFilter -> searchEnabled

* extractIntervalFromDimensions utility

* create new statsQuery with spread

* remove redundant useMemo

* remove redundant as type casts

* move and improve comment
R
RobertJoonas committed
82c7b0eaa3af2d2df2bd67a49b764d87407be6de
Parent: f428d38
Committed by GitHub <noreply@github.com> on 5/14/2026, 11:49:44 AM