mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 06:07:17 +01:00
Refactor part 2: Electric Boogaloo. Standardize way of passing filter parameters.
This commit is contained in:
parent
f26f1b0581
commit
cdf391d5c2
90 changed files with 867 additions and 709 deletions
|
|
@ -1,15 +1,17 @@
|
|||
import { useApi } from '../useApi';
|
||||
import { useFilterParams } from '../useFilterParams';
|
||||
import { useFilterParameters } from '../useFilterParameters';
|
||||
import { ReactQueryOptions } from '@/lib/types';
|
||||
import { useDateParameters } from '@/components/hooks/useDateParameters';
|
||||
|
||||
export function useResultQuery<T = any>(
|
||||
type: string,
|
||||
params?: Record<string, any>,
|
||||
options?: ReactQueryOptions<T>,
|
||||
) {
|
||||
const { websiteId } = params;
|
||||
const { websiteId, ...parameters } = params;
|
||||
const { post, useQuery } = useApi();
|
||||
const filters = useFilterParams(websiteId);
|
||||
const { startDate, endDate, timezone } = useDateParameters(websiteId);
|
||||
const filters = useFilterParameters();
|
||||
|
||||
return useQuery<T>({
|
||||
queryKey: [
|
||||
|
|
@ -17,11 +19,25 @@ export function useResultQuery<T = any>(
|
|||
{
|
||||
type,
|
||||
websiteId,
|
||||
...filters,
|
||||
startDate,
|
||||
endDate,
|
||||
timezone,
|
||||
...params,
|
||||
...filters,
|
||||
},
|
||||
],
|
||||
queryFn: () => post(`/reports/${type}`, { type, filters, ...params }),
|
||||
queryFn: () =>
|
||||
post(`/reports/${type}`, {
|
||||
websiteId,
|
||||
type,
|
||||
filters,
|
||||
parameters: {
|
||||
startDate,
|
||||
endDate,
|
||||
timezone,
|
||||
...parameters,
|
||||
},
|
||||
}),
|
||||
enabled: !!type,
|
||||
...options,
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue