Merge branch 'dev' of https://github.com/umami-software/umami into dev
This commit is contained in:
commit
6c2155d496
157 files changed
+1389
-643
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { MAX_PAGING_RESULTS } from '@/lib/constants';
|
||||
import { serializeEventPropertyFilters } from '@/lib/params';
|
||||
import type { EventPropertyFilter, ReactQueryOptions } from '@/lib/types';
|
||||
import { useApi } from '../useApi';
|
||||
@@ -28,6 +29,7 @@ export function useEventDataPivotQuery(
|
||||
timezone,
|
||||
...serializeEventPropertyFilters(eventFilters),
|
||||
...params,
|
||||
maxResults: MAX_PAGING_RESULTS,
|
||||
}),
|
||||
enabled: !!(websiteId && eventName),
|
||||
...options,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { MAX_PAGING_RESULTS } from '@/lib/constants';
|
||||
import { useApi } from '../useApi';
|
||||
import { useDateParameters } from '../useDateParameters';
|
||||
import { useFilterParameters } from '../useFilterParameters';
|
||||
@@ -24,7 +25,7 @@ export function useReplaysQuery(websiteId: string, params?: Record<string, strin
|
||||
...filters,
|
||||
...pageParams,
|
||||
...params,
|
||||
pageSize: 20,
|
||||
maxResults: MAX_PAGING_RESULTS,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { MAX_PAGING_RESULTS } from '@/lib/constants';
|
||||
import { useApi } from '../useApi';
|
||||
import { useDateParameters } from '../useDateParameters';
|
||||
import { useFilterParameters } from '../useFilterParameters';
|
||||
@@ -29,7 +30,7 @@ export function useRevenueSessionsQuery(
|
||||
...filters,
|
||||
...pageParams,
|
||||
...params,
|
||||
pageSize: 20,
|
||||
maxResults: MAX_PAGING_RESULTS,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -11,7 +11,6 @@ export function useSavedReplaysQuery(websiteId: string) {
|
||||
queryFn: pageParams => {
|
||||
return get(`/websites/${websiteId}/replays/saved`, {
|
||||
...pageParams,
|
||||
pageSize: 20,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { MAX_PAGING_RESULTS } from '@/lib/constants';
|
||||
import { serializePropertyFilters } from '@/lib/params';
|
||||
import type { PropertyFilter, ReactQueryOptions } from '@/lib/types';
|
||||
import { useApi } from '../useApi';
|
||||
@@ -28,6 +29,7 @@ export function useSessionDataPivotQuery(
|
||||
propertyName,
|
||||
...serializePropertyFilters(propertyFilters),
|
||||
...params,
|
||||
maxResults: MAX_PAGING_RESULTS,
|
||||
}),
|
||||
enabled: !!(websiteId && propertyName),
|
||||
...options,
|
||||
|
||||
@@ -8,7 +8,7 @@ import { useFilterParameters } from '../useFilterParameters';
|
||||
export function useSessionDataPropertiesQuery(
|
||||
websiteId: string,
|
||||
params?: {
|
||||
selectedPropertyName?: string;
|
||||
propertyName?: string;
|
||||
propertyFilters?: PropertyFilter[];
|
||||
},
|
||||
options?: ReactQueryOptions,
|
||||
@@ -16,14 +16,14 @@ export function useSessionDataPropertiesQuery(
|
||||
const { get, useQuery } = useApi();
|
||||
const { startAt, endAt, unit, timezone } = useDateParameters();
|
||||
const filters = useFilterParameters({ includePagination: false });
|
||||
const { selectedPropertyName, propertyFilters = [] } = params || {};
|
||||
const { propertyName, propertyFilters = [] } = params || {};
|
||||
|
||||
return useQuery<any>({
|
||||
queryKey: [
|
||||
'websites:session-data:properties',
|
||||
{
|
||||
websiteId,
|
||||
selectedPropertyName,
|
||||
propertyName,
|
||||
propertyFilters,
|
||||
startAt,
|
||||
endAt,
|
||||
@@ -38,7 +38,7 @@ export function useSessionDataPropertiesQuery(
|
||||
endAt,
|
||||
unit,
|
||||
timezone,
|
||||
selectedPropertyName,
|
||||
propertyName,
|
||||
...serializePropertyFilters(propertyFilters),
|
||||
...filters,
|
||||
}),
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import { useApi } from '../useApi';
|
||||
import { useModified } from '../useModified';
|
||||
import { usePagedQuery } from '../usePagedQuery';
|
||||
|
||||
export function useUserTeamsQuery(userId: string) {
|
||||
const { get, useQuery } = useApi();
|
||||
const { get } = useApi();
|
||||
const { modified } = useModified(`teams`);
|
||||
|
||||
return useQuery({
|
||||
return usePagedQuery({
|
||||
queryKey: ['teams', { userId, modified }],
|
||||
queryFn: () => {
|
||||
return get(`/users/${userId}/teams`);
|
||||
queryFn: params => {
|
||||
return get(`/users/${userId}/teams`, params);
|
||||
},
|
||||
enabled: !!userId,
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { MAX_PAGING_RESULTS } from '@/lib/constants';
|
||||
import type { ReactQueryOptions } from '@/lib/types';
|
||||
import { useApi } from '../useApi';
|
||||
import { useDateParameters } from '../useDateParameters';
|
||||
@@ -32,6 +33,7 @@ export function useWebsiteEventsQuery(
|
||||
...filters,
|
||||
...pageParams,
|
||||
eventType: EVENT_TYPES[params.view],
|
||||
maxResults: MAX_PAGING_RESULTS,
|
||||
}),
|
||||
enabled: !!websiteId,
|
||||
...options,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { MAX_PAGING_RESULTS } from '@/lib/constants';
|
||||
import { useApi } from '../useApi';
|
||||
import { useDateParameters } from '../useDateParameters';
|
||||
import { useFilterParameters } from '../useFilterParameters';
|
||||
@@ -27,7 +28,7 @@ export function useWebsiteSessionsQuery(
|
||||
...filters,
|
||||
...pageParams,
|
||||
...params,
|
||||
pageSize: 20,
|
||||
maxResults: MAX_PAGING_RESULTS,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,27 +1,32 @@
|
||||
import { useMemo } from 'react';
|
||||
import { FILTER_COLUMNS } from '@/lib/constants';
|
||||
import { useShare } from './context/useShare';
|
||||
import { useNavigation } from './useNavigation';
|
||||
|
||||
export function useFilterParameters({ includePagination = true }: { includePagination?: boolean } = {}) {
|
||||
const { query } = useNavigation();
|
||||
const share = useShare();
|
||||
const allowFilter = share?.parameters?.allowFilter !== false;
|
||||
|
||||
return useMemo(() => {
|
||||
const filterParams: Record<string, any> = {};
|
||||
|
||||
for (const key of Object.keys(query)) {
|
||||
const baseName = key.replace(/\d+$/, '');
|
||||
if (FILTER_COLUMNS[baseName]) {
|
||||
filterParams[key] = query[key];
|
||||
if (allowFilter) {
|
||||
for (const key of Object.keys(query)) {
|
||||
const baseName = key.replace(/\d+$/, '');
|
||||
if (FILTER_COLUMNS[baseName]) {
|
||||
filterParams[key] = query[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const params = {
|
||||
...filterParams,
|
||||
search: query.search,
|
||||
segment: query.segment,
|
||||
cohort: query.cohort,
|
||||
excludeBounce: query.excludeBounce,
|
||||
match: query.match,
|
||||
segment: allowFilter ? query.segment : undefined,
|
||||
cohort: allowFilter ? query.cohort : undefined,
|
||||
excludeBounce: allowFilter ? query.excludeBounce : undefined,
|
||||
match: allowFilter ? query.match : undefined,
|
||||
} as Record<string, any>;
|
||||
|
||||
if (includePagination) {
|
||||
@@ -30,5 +35,5 @@ export function useFilterParameters({ includePagination = true }: { includePagin
|
||||
}
|
||||
|
||||
return params;
|
||||
}, [query, includePagination]);
|
||||
}, [allowFilter, includePagination, query]);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { FILTER_COLUMNS, OPERATORS } from '@/lib/constants';
|
||||
import { safeDecodeURIComponent } from '@/lib/url';
|
||||
import { useShare } from './context/useShare';
|
||||
import { useFields } from './useFields';
|
||||
import { useMessages } from './useMessages';
|
||||
import { useNavigation } from './useNavigation';
|
||||
@@ -10,6 +11,8 @@ export function useFilters() {
|
||||
const { query } = useNavigation();
|
||||
const { fields } = useFields();
|
||||
const operatorLabels = useOperatorLabels();
|
||||
const share = useShare();
|
||||
const allowFilter = share?.parameters?.allowFilter !== false;
|
||||
|
||||
const operators = [
|
||||
{ name: 'eq', type: 'string', label: t(labels.is) },
|
||||
@@ -56,30 +59,32 @@ export function useFilters() {
|
||||
uuid: [OPERATORS.equals],
|
||||
};
|
||||
|
||||
const filters = Object.keys(query).reduce((arr, key) => {
|
||||
const baseName = key.replace(/\d+$/, '');
|
||||
if (FILTER_COLUMNS[baseName]) {
|
||||
let operator = 'eq';
|
||||
let value = safeDecodeURIComponent(query[key]);
|
||||
const label = fields.find(({ name }) => name === baseName)?.label;
|
||||
const filters = allowFilter
|
||||
? Object.keys(query).reduce((arr, key) => {
|
||||
const baseName = key.replace(/\d+$/, '');
|
||||
if (FILTER_COLUMNS[baseName]) {
|
||||
let operator = 'eq';
|
||||
let value = safeDecodeURIComponent(query[key]);
|
||||
const label = fields.find(({ name }) => name === baseName)?.label;
|
||||
|
||||
const match = value.match(/^([a-z]+)\.(.*)/);
|
||||
const match = value.match(/^([a-z]+)\.(.*)/);
|
||||
|
||||
if (match) {
|
||||
operator = match[1];
|
||||
value = match[2];
|
||||
}
|
||||
if (match) {
|
||||
operator = match[1];
|
||||
value = match[2];
|
||||
}
|
||||
|
||||
return arr.concat({
|
||||
name: key,
|
||||
type: baseName,
|
||||
operator,
|
||||
value,
|
||||
label,
|
||||
});
|
||||
}
|
||||
return arr;
|
||||
}, []);
|
||||
return arr.concat({
|
||||
name: key,
|
||||
type: baseName,
|
||||
operator,
|
||||
value,
|
||||
label,
|
||||
});
|
||||
}
|
||||
return arr;
|
||||
}, [])
|
||||
: [];
|
||||
|
||||
const getFilters = (type: string) => {
|
||||
return (
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useNavigation } from './useNavigation';
|
||||
|
||||
export function usePageParameters() {
|
||||
const {
|
||||
query: { page, pageSize, search },
|
||||
query: { page, pageSize, search, orderBy, sortDescending },
|
||||
} = useNavigation();
|
||||
|
||||
return useMemo(() => {
|
||||
@@ -11,6 +11,8 @@ export function usePageParameters() {
|
||||
page,
|
||||
pageSize,
|
||||
search,
|
||||
orderBy,
|
||||
sortDescending,
|
||||
};
|
||||
}, [page, pageSize, search]);
|
||||
}, [orderBy, page, pageSize, search, sortDescending]);
|
||||
}
|
||||
@@ -15,13 +15,13 @@ export function usePagedQuery<TData = any, TError = Error>({
|
||||
queryFn: (params?: object) => Promise<PageResult<TData>> | PageResult<TData>;
|
||||
}): UseQueryResult<PageResult<TData>, TError> {
|
||||
const {
|
||||
query: { page, search },
|
||||
query: { page, search, orderBy, sortDescending },
|
||||
} = useNavigation();
|
||||
const { useQuery } = useApi();
|
||||
|
||||
return useQuery<PageResult<TData>, TError>({
|
||||
queryKey: [...queryKey, page, search] as const,
|
||||
queryFn: () => queryFn({ page, search }),
|
||||
queryKey: [...queryKey, page, search, orderBy, sortDescending] as const,
|
||||
queryFn: () => queryFn({ page, search, orderBy, sortDescending }),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user