Add sparklines to Website, Pixel, Link tables
This commit is contained in:
1 parent
1fb565bc27
commit
86b35475c0
11 files changed
+625
-20
No files matched your search
@@ -70,6 +70,7 @@ export * from './queries/useWebsiteEventsSeriesQuery';
|
||||
export * from './queries/useWebsiteExpandedMetricsQuery';
|
||||
export * from './queries/useWebsiteMetricsQuery';
|
||||
export * from './queries/useWebsitePageviewsQuery';
|
||||
export * from './queries/useWebsiteListChartsQuery';
|
||||
export * from './queries/useWebsiteQuery';
|
||||
export * from './queries/useWebsiteSegmentQuery';
|
||||
export * from './queries/useWebsiteSegmentsQuery';
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import { useMemo } from 'react';
|
||||
import type { WebsiteListChartData } from '@/queries/sql/getWebsiteListCharts';
|
||||
import { useApi } from '../useApi';
|
||||
import { useTimezone } from '../useTimezone';
|
||||
|
||||
export interface WebsiteListChartsResponse {
|
||||
data: Record<string, WebsiteListChartData>;
|
||||
}
|
||||
|
||||
function useListChartsQuery(queryKey: string, path: string, idsInput: string[]) {
|
||||
const { get, useQuery } = useApi();
|
||||
const { timezone, canonicalizeTimezone } = useTimezone();
|
||||
|
||||
const ids = useMemo(
|
||||
() => Array.from(new Set(idsInput.map(id => id?.trim()).filter(Boolean))),
|
||||
[idsInput],
|
||||
);
|
||||
const resolvedTimezone = canonicalizeTimezone(timezone);
|
||||
|
||||
return useQuery<WebsiteListChartsResponse>({
|
||||
queryKey: [queryKey, { ids, timezone: resolvedTimezone }],
|
||||
queryFn: () =>
|
||||
get(path, {
|
||||
ids: ids.join(','),
|
||||
timezone: resolvedTimezone,
|
||||
}),
|
||||
enabled: ids.length > 0,
|
||||
});
|
||||
}
|
||||
|
||||
export function useWebsiteListChartsQuery(websiteIds: string[]) {
|
||||
return useListChartsQuery('websites:list:charts', '/websites/charts', websiteIds);
|
||||
}
|
||||
|
||||
export function useLinkListChartsQuery(linkIds: string[]) {
|
||||
return useListChartsQuery('links:list:charts', '/links/charts', linkIds);
|
||||
}
|
||||
|
||||
export function usePixelListChartsQuery(pixelIds: string[]) {
|
||||
return useListChartsQuery('pixels:list:charts', '/pixels/charts', pixelIds);
|
||||
}
|
||||
Reference in new issue
Block a user