Merge branch 'dev' into fix/pagination
This commit is contained in:
545 files changed
+33236
-142546
No files matched your search
@@ -0,0 +1,6 @@
|
||||
import { useContext } from 'react';
|
||||
import { BoardContext, type BoardContextValue } from '@/app/(main)/boards/BoardProvider';
|
||||
|
||||
export function useBoard(): BoardContextValue {
|
||||
return useContext(BoardContext);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { useContext } from 'react';
|
||||
import { ShareContext } from '@/app/share/ShareProvider';
|
||||
|
||||
export function useShare() {
|
||||
return useContext(ShareContext);
|
||||
}
|
||||
@@ -1,14 +1,19 @@
|
||||
'use client';
|
||||
|
||||
// Context hooks
|
||||
export * from './context/useBoard';
|
||||
export * from './context/useLink';
|
||||
export * from './context/usePixel';
|
||||
export * from './context/useShare';
|
||||
export * from './context/useTeam';
|
||||
export * from './context/useUser';
|
||||
export * from './context/useWebsite';
|
||||
|
||||
// Query hooks
|
||||
export * from './queries/useActiveUsersQuery';
|
||||
export * from './queries/useBoardQuery';
|
||||
export * from './queries/useBoardsQuery';
|
||||
export * from './queries/useDashboardQuery';
|
||||
export * from './queries/useDateRangeQuery';
|
||||
export * from './queries/useDeleteQuery';
|
||||
export * from './queries/useEventDataEventsQuery';
|
||||
@@ -51,6 +56,7 @@ export * from './queries/useWebsiteSegmentsQuery';
|
||||
export * from './queries/useWebsiteSessionQuery';
|
||||
export * from './queries/useWebsiteSessionStatsQuery';
|
||||
export * from './queries/useWebsiteSessionsQuery';
|
||||
export * from './queries/useWebsiteSharesQuery';
|
||||
export * from './queries/useWebsiteStatsQuery';
|
||||
export * from './queries/useWebsitesQuery';
|
||||
export * from './queries/useWebsiteValuesQuery';
|
||||
@@ -82,3 +88,4 @@ export * from './useRegionNames';
|
||||
export * from './useSlug';
|
||||
export * from './useSticky';
|
||||
export * from './useTimezone';
|
||||
export * from './useWebsiteNavItems';
|
||||
@@ -0,0 +1,17 @@
|
||||
import { keepPreviousData } from '@tanstack/react-query';
|
||||
import type { ReactQueryOptions } from '@/lib/types';
|
||||
import { useApi } from '../useApi';
|
||||
import { useModified } from '../useModified';
|
||||
|
||||
export function useBoardQuery(boardId: string, options?: ReactQueryOptions) {
|
||||
const { get, useQuery } = useApi();
|
||||
const { modified } = useModified(`board:${boardId}`);
|
||||
|
||||
return useQuery({
|
||||
queryKey: ['boards', { boardId, modified }],
|
||||
queryFn: () => get(`/boards/${boardId}`),
|
||||
enabled: !!boardId && boardId !== 'create',
|
||||
placeholderData: keepPreviousData,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import type { ReactQueryOptions } from '@/lib/types';
|
||||
import { useApi } from '../useApi';
|
||||
import { useModified } from '../useModified';
|
||||
import { usePagedQuery } from '../usePagedQuery';
|
||||
|
||||
export function useBoardsQuery(
|
||||
{ teamId }: { teamId?: string },
|
||||
params?: Record<string, any>,
|
||||
options?: ReactQueryOptions,
|
||||
) {
|
||||
const { modified } = useModified('boards');
|
||||
const { get } = useApi();
|
||||
|
||||
return usePagedQuery({
|
||||
queryKey: ['boards', { teamId, modified, ...params }],
|
||||
queryFn: pageParams => {
|
||||
return get(teamId ? `/teams/${teamId}/boards` : '/boards', {
|
||||
...pageParams,
|
||||
...params,
|
||||
});
|
||||
},
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { keepPreviousData } from '@tanstack/react-query';
|
||||
import type { ReactQueryOptions } from '@/lib/types';
|
||||
import { useApi } from '../useApi';
|
||||
import { useModified } from '../useModified';
|
||||
|
||||
export function useDashboardQuery(options?: ReactQueryOptions) {
|
||||
const { get, useQuery } = useApi();
|
||||
const { modified } = useModified('dashboard');
|
||||
|
||||
return useQuery({
|
||||
queryKey: ['dashboard', { modified }],
|
||||
queryFn: () => get('/dashboard'),
|
||||
placeholderData: keepPreviousData,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -16,7 +16,7 @@ export function useEventDataValuesQuery(
|
||||
return useQuery<any>({
|
||||
queryKey: [
|
||||
'websites:event-data:values',
|
||||
{ websiteId, event, propertyName, startAt, endAt, unit, timezone, ...filters },
|
||||
{ websiteId, startAt, endAt, unit, timezone, ...filters, event, propertyName },
|
||||
],
|
||||
queryFn: () =>
|
||||
get(`/websites/${websiteId}/event-data/values`, {
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import type { UseQueryOptions } from '@tanstack/react-query';
|
||||
import { useDateParameters } from '@/components/hooks/useDateParameters';
|
||||
import { useApi } from '../useApi';
|
||||
import { useFilterParameters } from '../useFilterParameters';
|
||||
|
||||
export interface EventStatsData {
|
||||
events: number;
|
||||
visitors: number;
|
||||
visits: number;
|
||||
uniqueEvents: number;
|
||||
comparison: {
|
||||
events: number;
|
||||
visitors: number;
|
||||
visits: number;
|
||||
uniqueEvents: number;
|
||||
};
|
||||
}
|
||||
|
||||
type EventStatsApiResponse = {
|
||||
data: EventStatsData;
|
||||
};
|
||||
|
||||
export function useEventStatsQuery(
|
||||
{ websiteId }: { websiteId: string },
|
||||
options?: UseQueryOptions<EventStatsApiResponse, Error, EventStatsData>,
|
||||
) {
|
||||
const { get, useQuery } = useApi();
|
||||
const { startAt, endAt } = useDateParameters();
|
||||
const filters = useFilterParameters();
|
||||
|
||||
return useQuery<EventStatsApiResponse, Error, EventStatsData>({
|
||||
queryKey: ['websites:events:stats', { websiteId, startAt, endAt, ...filters }],
|
||||
queryFn: () =>
|
||||
get(`/websites/${websiteId}/events/stats`, {
|
||||
startAt,
|
||||
endAt,
|
||||
...filters,
|
||||
}),
|
||||
select: response => response.data,
|
||||
enabled: !!websiteId,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -3,14 +3,21 @@ import { useApi } from '../useApi';
|
||||
import { useModified } from '../useModified';
|
||||
import { usePagedQuery } from '../usePagedQuery';
|
||||
|
||||
export function useLinksQuery({ teamId }: { teamId?: string }, options?: ReactQueryOptions) {
|
||||
export function useLinksQuery(
|
||||
{ teamId }: { teamId?: string },
|
||||
params?: Record<string, any>,
|
||||
options?: ReactQueryOptions,
|
||||
) {
|
||||
const { modified } = useModified('links');
|
||||
const { get } = useApi();
|
||||
|
||||
return usePagedQuery({
|
||||
queryKey: ['links', { teamId, modified }],
|
||||
queryKey: ['links', { teamId, modified, ...params }],
|
||||
queryFn: pageParams => {
|
||||
return get(teamId ? `/teams/${teamId}/links` : '/links', pageParams);
|
||||
return get(teamId ? `/teams/${teamId}/links` : '/links', {
|
||||
...pageParams,
|
||||
...params,
|
||||
});
|
||||
},
|
||||
...options,
|
||||
});
|
||||
|
||||
@@ -3,14 +3,21 @@ import { useApi } from '../useApi';
|
||||
import { useModified } from '../useModified';
|
||||
import { usePagedQuery } from '../usePagedQuery';
|
||||
|
||||
export function usePixelsQuery({ teamId }: { teamId?: string }, options?: ReactQueryOptions) {
|
||||
export function usePixelsQuery(
|
||||
{ teamId }: { teamId?: string },
|
||||
params?: Record<string, any>,
|
||||
options?: ReactQueryOptions,
|
||||
) {
|
||||
const { modified } = useModified('pixels');
|
||||
const { get } = useApi();
|
||||
|
||||
return usePagedQuery({
|
||||
queryKey: ['pixels', { teamId, modified }],
|
||||
queryKey: ['pixels', { teamId, modified, ...params }],
|
||||
queryFn: pageParams => {
|
||||
return get(teamId ? `/teams/${teamId}/pixels` : '/pixels', pageParams);
|
||||
return get(teamId ? `/teams/${teamId}/pixels` : '/pixels', {
|
||||
...pageParams,
|
||||
...params,
|
||||
});
|
||||
},
|
||||
...options,
|
||||
});
|
||||
|
||||
@@ -10,7 +10,7 @@ export function useResultQuery<T = any>(
|
||||
) {
|
||||
const { websiteId, ...parameters } = params;
|
||||
const { post, useQuery } = useApi();
|
||||
const { startDate, endDate, timezone } = useDateParameters();
|
||||
const { startDate, endDate, timezone, unit } = useDateParameters();
|
||||
const filters = useFilterParameters();
|
||||
|
||||
return useQuery<T>({
|
||||
@@ -22,6 +22,7 @@ export function useResultQuery<T = any>(
|
||||
startDate,
|
||||
endDate,
|
||||
timezone,
|
||||
unit,
|
||||
...params,
|
||||
...filters,
|
||||
},
|
||||
@@ -35,6 +36,7 @@ export function useResultQuery<T = any>(
|
||||
startDate,
|
||||
endDate,
|
||||
timezone,
|
||||
unit,
|
||||
...parameters,
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -1,25 +1,22 @@
|
||||
import { setShareToken, useApp } from '@/store/app';
|
||||
import { setShare, setShareToken, useApp } from '@/store/app';
|
||||
import { useApi } from '../useApi';
|
||||
|
||||
const selector = (state: { shareToken: string }) => state.shareToken;
|
||||
const selector = state => state.share;
|
||||
|
||||
export function useShareTokenQuery(shareId: string): {
|
||||
shareToken: any;
|
||||
isLoading?: boolean;
|
||||
error?: Error;
|
||||
} {
|
||||
const shareToken = useApp(selector);
|
||||
export function useShareTokenQuery(slug: string) {
|
||||
const share = useApp(selector);
|
||||
const { get, useQuery } = useApi();
|
||||
const { isLoading, error } = useQuery({
|
||||
queryKey: ['share', shareId],
|
||||
const query = useQuery({
|
||||
queryKey: ['share', slug],
|
||||
queryFn: async () => {
|
||||
const data = await get(`/share/${shareId}`);
|
||||
const data = await get(`/share/${slug}`);
|
||||
|
||||
setShareToken(data);
|
||||
setShare(data);
|
||||
setShareToken({ token: data?.token });
|
||||
|
||||
return data;
|
||||
},
|
||||
});
|
||||
|
||||
return { shareToken, isLoading, error };
|
||||
return { share, ...query };
|
||||
}
|
||||
@@ -3,15 +3,29 @@ import { useApi } from '../useApi';
|
||||
import { useDateParameters } from '../useDateParameters';
|
||||
import { useFilterParameters } from '../useFilterParameters';
|
||||
|
||||
export function useWebsiteEventsSeriesQuery(websiteId: string, options?: ReactQueryOptions) {
|
||||
export function useWebsiteEventsSeriesQuery(
|
||||
websiteId: string,
|
||||
params?: { limit?: number },
|
||||
options?: ReactQueryOptions,
|
||||
) {
|
||||
const { get, useQuery } = useApi();
|
||||
const { startAt, endAt, unit, timezone } = useDateParameters();
|
||||
const filters = useFilterParameters();
|
||||
|
||||
return useQuery({
|
||||
queryKey: ['websites:events:series', { websiteId, startAt, endAt, unit, timezone, ...filters }],
|
||||
queryKey: [
|
||||
'websites:events:series',
|
||||
{ websiteId, startAt, endAt, unit, timezone, ...filters, ...params },
|
||||
],
|
||||
queryFn: () =>
|
||||
get(`/websites/${websiteId}/events/series`, { startAt, endAt, unit, timezone, ...filters }),
|
||||
get(`/websites/${websiteId}/events/series`, {
|
||||
startAt,
|
||||
endAt,
|
||||
unit,
|
||||
timezone,
|
||||
...filters,
|
||||
...params,
|
||||
}),
|
||||
enabled: !!websiteId,
|
||||
...options,
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@ export function useWebsiteExpandedMetricsQuery(
|
||||
options?: ReactQueryOptions<WebsiteExpandedMetricsData>,
|
||||
) {
|
||||
const { get, useQuery } = useApi();
|
||||
const { startAt, endAt, unit, timezone } = useDateParameters();
|
||||
const { startAt, endAt } = useDateParameters();
|
||||
const filters = useFilterParameters();
|
||||
|
||||
return useQuery<WebsiteExpandedMetricsData>({
|
||||
@@ -29,8 +29,6 @@ export function useWebsiteExpandedMetricsQuery(
|
||||
websiteId,
|
||||
startAt,
|
||||
endAt,
|
||||
unit,
|
||||
timezone,
|
||||
...filters,
|
||||
...params,
|
||||
},
|
||||
@@ -39,8 +37,6 @@ export function useWebsiteExpandedMetricsQuery(
|
||||
get(`/websites/${websiteId}/metrics/expanded`, {
|
||||
startAt,
|
||||
endAt,
|
||||
unit,
|
||||
timezone,
|
||||
...filters,
|
||||
...params,
|
||||
}),
|
||||
|
||||
@@ -15,7 +15,7 @@ export function useWebsiteMetricsQuery(
|
||||
options?: ReactQueryOptions<WebsiteMetricsData>,
|
||||
) {
|
||||
const { get, useQuery } = useApi();
|
||||
const { startAt, endAt, unit, timezone } = useDateParameters();
|
||||
const { startAt, endAt } = useDateParameters();
|
||||
const filters = useFilterParameters();
|
||||
|
||||
return useQuery<WebsiteMetricsData>({
|
||||
@@ -25,8 +25,6 @@ export function useWebsiteMetricsQuery(
|
||||
websiteId,
|
||||
startAt,
|
||||
endAt,
|
||||
unit,
|
||||
timezone,
|
||||
...filters,
|
||||
...params,
|
||||
},
|
||||
@@ -35,8 +33,6 @@ export function useWebsiteMetricsQuery(
|
||||
get(`/websites/${websiteId}/metrics`, {
|
||||
startAt,
|
||||
endAt,
|
||||
unit,
|
||||
timezone,
|
||||
...filters,
|
||||
...params,
|
||||
}),
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import type { ReactQueryOptions } from '@/lib/types';
|
||||
import { useApi } from '../useApi';
|
||||
import { useModified } from '../useModified';
|
||||
import { usePagedQuery } from '../usePagedQuery';
|
||||
|
||||
export function useWebsiteSharesQuery(
|
||||
{ websiteId }: { websiteId: string },
|
||||
options?: ReactQueryOptions,
|
||||
) {
|
||||
const { modified } = useModified('shares');
|
||||
const { get } = useApi();
|
||||
|
||||
return usePagedQuery({
|
||||
queryKey: ['websiteShares', { websiteId, modified }],
|
||||
queryFn: pageParams => {
|
||||
return get(`/websites/${websiteId}/shares`, pageParams);
|
||||
},
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -19,17 +19,16 @@ export interface WebsiteStatsData {
|
||||
}
|
||||
|
||||
export function useWebsiteStatsQuery(
|
||||
websiteId: string,
|
||||
{ websiteId, compare }: { websiteId: string; compare?: string },
|
||||
options?: UseQueryOptions<WebsiteStatsData, Error, WebsiteStatsData>,
|
||||
) {
|
||||
const { get, useQuery } = useApi();
|
||||
const { startAt, endAt, unit, timezone } = useDateParameters();
|
||||
const { startAt, endAt } = useDateParameters();
|
||||
const filters = useFilterParameters();
|
||||
|
||||
return useQuery<WebsiteStatsData>({
|
||||
queryKey: ['websites:stats', { websiteId, startAt, endAt, unit, timezone, ...filters }],
|
||||
queryFn: () =>
|
||||
get(`/websites/${websiteId}/stats`, { startAt, endAt, unit, timezone, ...filters }),
|
||||
queryKey: ['websites:stats', { websiteId, compare, startAt, endAt, ...filters }],
|
||||
queryFn: () => get(`/websites/${websiteId}/stats`, { compare, startAt, endAt, ...filters }),
|
||||
enabled: !!websiteId,
|
||||
...options,
|
||||
});
|
||||
|
||||
@@ -12,13 +12,12 @@ export function useWeeklyTrafficQuery(websiteId: string, params?: Record<string,
|
||||
return useQuery({
|
||||
queryKey: [
|
||||
'sessions',
|
||||
{ websiteId, modified, startAt, endAt, unit, timezone, ...params, ...filters },
|
||||
{ websiteId, modified, startAt, endAt, timezone, ...params, ...filters },
|
||||
],
|
||||
queryFn: () => {
|
||||
return get(`/websites/${websiteId}/sessions/weekly`, {
|
||||
startAt,
|
||||
endAt,
|
||||
unit,
|
||||
timezone,
|
||||
...params,
|
||||
...filters,
|
||||
|
||||
@@ -7,13 +7,13 @@ import { getItem } from '@/lib/storage';
|
||||
|
||||
export function useDateRange(options: { ignoreOffset?: boolean; timezone?: string } = {}) {
|
||||
const {
|
||||
query: { date = '', offset = 0, compare = 'prev' },
|
||||
query: { date = '', unit = '', offset = 0, compare = 'prev' },
|
||||
} = useNavigation();
|
||||
const { locale } = useLocale();
|
||||
|
||||
const dateRange = useMemo(() => {
|
||||
const dateRangeObject = parseDateRange(
|
||||
date || getItem(DATE_RANGE_CONFIG) || DEFAULT_DATE_RANGE_VALUE,
|
||||
unit,
|
||||
locale,
|
||||
options.timezone,
|
||||
);
|
||||
@@ -21,12 +21,13 @@ export function useDateRange(options: { ignoreOffset?: boolean; timezone?: strin
|
||||
return !options.ignoreOffset && offset
|
||||
? getOffsetDateRange(dateRangeObject, +offset)
|
||||
: dateRangeObject;
|
||||
}, [date, offset, options]);
|
||||
}, [date, unit, offset, options]);
|
||||
|
||||
const dateCompare = getCompareDate(compare, dateRange.startDate, dateRange.endDate);
|
||||
|
||||
return {
|
||||
date,
|
||||
unit,
|
||||
offset,
|
||||
compare,
|
||||
isAllTime: date.endsWith(`:all`),
|
||||
|
||||
@@ -1,23 +1,142 @@
|
||||
import { useMessages } from './useMessages';
|
||||
|
||||
export function useFields() {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
export type FieldGroup = 'url' | 'sources' | 'location' | 'environment' | 'utm' | 'other';
|
||||
|
||||
const fields = [
|
||||
{ name: 'path', type: 'string', label: formatMessage(labels.path) },
|
||||
{ name: 'query', type: 'string', label: formatMessage(labels.query) },
|
||||
{ name: 'title', type: 'string', label: formatMessage(labels.pageTitle) },
|
||||
{ name: 'referrer', type: 'string', label: formatMessage(labels.referrer) },
|
||||
{ name: 'browser', type: 'string', label: formatMessage(labels.browser) },
|
||||
{ name: 'os', type: 'string', label: formatMessage(labels.os) },
|
||||
{ name: 'device', type: 'string', label: formatMessage(labels.device) },
|
||||
{ name: 'country', type: 'string', label: formatMessage(labels.country) },
|
||||
{ name: 'region', type: 'string', label: formatMessage(labels.region) },
|
||||
{ name: 'city', type: 'string', label: formatMessage(labels.city) },
|
||||
{ name: 'hostname', type: 'string', label: formatMessage(labels.hostname) },
|
||||
{ name: 'tag', type: 'string', label: formatMessage(labels.tag) },
|
||||
{ name: 'event', type: 'string', label: formatMessage(labels.event) },
|
||||
export interface Field {
|
||||
name: string;
|
||||
filterLabel: string;
|
||||
label: string;
|
||||
group: FieldGroup;
|
||||
}
|
||||
|
||||
export function useFields() {
|
||||
const { t, labels } = useMessages();
|
||||
|
||||
const fields: Field[] = [
|
||||
{
|
||||
name: 'path',
|
||||
filterLabel: t(labels.path),
|
||||
label: t(labels.path),
|
||||
group: 'url',
|
||||
},
|
||||
{
|
||||
name: 'query',
|
||||
filterLabel: t(labels.query),
|
||||
label: t(labels.query),
|
||||
group: 'url',
|
||||
},
|
||||
{
|
||||
name: 'title',
|
||||
filterLabel: t(labels.pageTitle),
|
||||
label: t(labels.pageTitle),
|
||||
group: 'url',
|
||||
},
|
||||
{
|
||||
name: 'referrer',
|
||||
filterLabel: t(labels.referrer),
|
||||
label: t(labels.referrer),
|
||||
group: 'sources',
|
||||
},
|
||||
{
|
||||
name: 'country',
|
||||
filterLabel: t(labels.country),
|
||||
label: t(labels.country),
|
||||
group: 'location',
|
||||
},
|
||||
{
|
||||
name: 'region',
|
||||
filterLabel: t(labels.region),
|
||||
label: t(labels.region),
|
||||
group: 'location',
|
||||
},
|
||||
{
|
||||
name: 'city',
|
||||
filterLabel: t(labels.city),
|
||||
label: t(labels.city),
|
||||
group: 'location',
|
||||
},
|
||||
{
|
||||
name: 'browser',
|
||||
filterLabel: t(labels.browser),
|
||||
label: t(labels.browser),
|
||||
group: 'environment',
|
||||
},
|
||||
{
|
||||
name: 'os',
|
||||
filterLabel: t(labels.os),
|
||||
label: t(labels.os),
|
||||
group: 'environment',
|
||||
},
|
||||
{
|
||||
name: 'device',
|
||||
filterLabel: t(labels.device),
|
||||
label: t(labels.device),
|
||||
group: 'environment',
|
||||
},
|
||||
{
|
||||
name: 'utmSource',
|
||||
filterLabel: t(labels.source),
|
||||
label: t(labels.utmSource),
|
||||
group: 'utm',
|
||||
},
|
||||
{
|
||||
name: 'utmMedium',
|
||||
filterLabel: t(labels.medium),
|
||||
label: t(labels.utmMedium),
|
||||
group: 'utm',
|
||||
},
|
||||
{
|
||||
name: 'utmCampaign',
|
||||
filterLabel: t(labels.campaign),
|
||||
label: t(labels.utmCampaign),
|
||||
group: 'utm',
|
||||
},
|
||||
{
|
||||
name: 'utmContent',
|
||||
filterLabel: t(labels.content),
|
||||
label: t(labels.utmContent),
|
||||
group: 'utm',
|
||||
},
|
||||
{
|
||||
name: 'utmTerm',
|
||||
filterLabel: t(labels.term),
|
||||
label: t(labels.utmTerm),
|
||||
group: 'utm',
|
||||
},
|
||||
{
|
||||
name: 'hostname',
|
||||
filterLabel: t(labels.hostname),
|
||||
label: t(labels.hostname),
|
||||
group: 'other',
|
||||
},
|
||||
{
|
||||
name: 'distinctId',
|
||||
filterLabel: t(labels.distinctId),
|
||||
label: t(labels.distinctId),
|
||||
group: 'other',
|
||||
},
|
||||
{
|
||||
name: 'tag',
|
||||
filterLabel: t(labels.tag),
|
||||
label: t(labels.tag),
|
||||
group: 'other',
|
||||
},
|
||||
{
|
||||
name: 'event',
|
||||
filterLabel: t(labels.event),
|
||||
label: t(labels.event),
|
||||
group: 'other',
|
||||
},
|
||||
];
|
||||
|
||||
return { fields };
|
||||
const groupLabels: { key: FieldGroup; label: string }[] = [
|
||||
{ key: 'url', label: t(labels.url) },
|
||||
{ key: 'sources', label: t(labels.sources) },
|
||||
{ key: 'location', label: t(labels.location) },
|
||||
{ key: 'environment', label: t(labels.environment) },
|
||||
{ key: 'utm', label: t(labels.utm) },
|
||||
{ key: 'other', label: t(labels.other) },
|
||||
];
|
||||
|
||||
return { fields, groupLabels };
|
||||
}
|
||||
@@ -18,11 +18,18 @@ export function useFilterParameters() {
|
||||
event,
|
||||
tag,
|
||||
hostname,
|
||||
distinctId,
|
||||
utmSource,
|
||||
utmMedium,
|
||||
utmCampaign,
|
||||
utmContent,
|
||||
utmTerm,
|
||||
page,
|
||||
pageSize,
|
||||
search,
|
||||
segment,
|
||||
cohort,
|
||||
excludeBounce,
|
||||
},
|
||||
} = useNavigation();
|
||||
|
||||
@@ -42,9 +49,16 @@ export function useFilterParameters() {
|
||||
event,
|
||||
tag,
|
||||
hostname,
|
||||
distinctId,
|
||||
utmSource,
|
||||
utmMedium,
|
||||
utmCampaign,
|
||||
utmContent,
|
||||
utmTerm,
|
||||
search,
|
||||
segment,
|
||||
cohort,
|
||||
excludeBounce,
|
||||
};
|
||||
}, [
|
||||
path,
|
||||
@@ -61,10 +75,17 @@ export function useFilterParameters() {
|
||||
event,
|
||||
tag,
|
||||
hostname,
|
||||
distinctId,
|
||||
utmSource,
|
||||
utmMedium,
|
||||
utmCampaign,
|
||||
utmContent,
|
||||
utmTerm,
|
||||
page,
|
||||
pageSize,
|
||||
search,
|
||||
segment,
|
||||
cohort,
|
||||
excludeBounce,
|
||||
]);
|
||||
}
|
||||
@@ -5,49 +5,60 @@ import { useMessages } from './useMessages';
|
||||
import { useNavigation } from './useNavigation';
|
||||
|
||||
export function useFilters() {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
const { query } = useNavigation();
|
||||
const { fields } = useFields();
|
||||
|
||||
const operators = [
|
||||
{ name: 'eq', type: 'string', label: formatMessage(labels.is) },
|
||||
{ name: 'neq', type: 'string', label: formatMessage(labels.isNot) },
|
||||
{ name: 'c', type: 'string', label: formatMessage(labels.contains) },
|
||||
{ name: 'dnc', type: 'string', label: formatMessage(labels.doesNotContain) },
|
||||
{ name: 'i', type: 'array', label: formatMessage(labels.includes) },
|
||||
{ name: 'dni', type: 'array', label: formatMessage(labels.doesNotInclude) },
|
||||
{ name: 't', type: 'boolean', label: formatMessage(labels.isTrue) },
|
||||
{ name: 'f', type: 'boolean', label: formatMessage(labels.isFalse) },
|
||||
{ name: 'eq', type: 'number', label: formatMessage(labels.is) },
|
||||
{ name: 'neq', type: 'number', label: formatMessage(labels.isNot) },
|
||||
{ name: 'gt', type: 'number', label: formatMessage(labels.greaterThan) },
|
||||
{ name: 'lt', type: 'number', label: formatMessage(labels.lessThan) },
|
||||
{ name: 'gte', type: 'number', label: formatMessage(labels.greaterThanEquals) },
|
||||
{ name: 'lte', type: 'number', label: formatMessage(labels.lessThanEquals) },
|
||||
{ name: 'bf', type: 'date', label: formatMessage(labels.before) },
|
||||
{ name: 'af', type: 'date', label: formatMessage(labels.after) },
|
||||
{ name: 'eq', type: 'uuid', label: formatMessage(labels.is) },
|
||||
{ name: 'eq', type: 'string', label: t(labels.is) },
|
||||
{ name: 'neq', type: 'string', label: t(labels.isNot) },
|
||||
{ name: 'c', type: 'string', label: t(labels.contains) },
|
||||
{ name: 'dnc', type: 'string', label: t(labels.doesNotContain) },
|
||||
{ name: 're', type: 'string', label: t(labels.regexMatch) },
|
||||
{ name: 'nre', type: 'string', label: t(labels.regexNotMatch) },
|
||||
{ name: 'i', type: 'array', label: t(labels.includes) },
|
||||
{ name: 'dni', type: 'array', label: t(labels.doesNotInclude) },
|
||||
{ name: 't', type: 'boolean', label: t(labels.isTrue) },
|
||||
{ name: 'f', type: 'boolean', label: t(labels.isFalse) },
|
||||
{ name: 'eq', type: 'number', label: t(labels.is) },
|
||||
{ name: 'neq', type: 'number', label: t(labels.isNot) },
|
||||
{ name: 'gt', type: 'number', label: t(labels.greaterThan) },
|
||||
{ name: 'lt', type: 'number', label: t(labels.lessThan) },
|
||||
{ name: 'gte', type: 'number', label: t(labels.greaterThanEquals) },
|
||||
{ name: 'lte', type: 'number', label: t(labels.lessThanEquals) },
|
||||
{ name: 'bf', type: 'date', label: t(labels.before) },
|
||||
{ name: 'af', type: 'date', label: t(labels.after) },
|
||||
{ name: 'eq', type: 'uuid', label: t(labels.is) },
|
||||
];
|
||||
|
||||
const operatorLabels = {
|
||||
[OPERATORS.equals]: formatMessage(labels.is),
|
||||
[OPERATORS.notEquals]: formatMessage(labels.isNot),
|
||||
[OPERATORS.set]: formatMessage(labels.isSet),
|
||||
[OPERATORS.notSet]: formatMessage(labels.isNotSet),
|
||||
[OPERATORS.contains]: formatMessage(labels.contains),
|
||||
[OPERATORS.doesNotContain]: formatMessage(labels.doesNotContain),
|
||||
[OPERATORS.true]: formatMessage(labels.true),
|
||||
[OPERATORS.false]: formatMessage(labels.false),
|
||||
[OPERATORS.greaterThan]: formatMessage(labels.greaterThan),
|
||||
[OPERATORS.lessThan]: formatMessage(labels.lessThan),
|
||||
[OPERATORS.greaterThanEquals]: formatMessage(labels.greaterThanEquals),
|
||||
[OPERATORS.lessThanEquals]: formatMessage(labels.lessThanEquals),
|
||||
[OPERATORS.before]: formatMessage(labels.before),
|
||||
[OPERATORS.after]: formatMessage(labels.after),
|
||||
[OPERATORS.equals]: t(labels.is),
|
||||
[OPERATORS.notEquals]: t(labels.isNot),
|
||||
[OPERATORS.set]: t(labels.isSet),
|
||||
[OPERATORS.notSet]: t(labels.isNotSet),
|
||||
[OPERATORS.contains]: t(labels.contains),
|
||||
[OPERATORS.doesNotContain]: t(labels.doesNotContain),
|
||||
[OPERATORS.regex]: t(labels.regexMatch),
|
||||
[OPERATORS.notRegex]: t(labels.regexNotMatch),
|
||||
[OPERATORS.true]: t(labels.true),
|
||||
[OPERATORS.false]: t(labels.false),
|
||||
[OPERATORS.greaterThan]: t(labels.greaterThan),
|
||||
[OPERATORS.lessThan]: t(labels.lessThan),
|
||||
[OPERATORS.greaterThanEquals]: t(labels.greaterThanEquals),
|
||||
[OPERATORS.lessThanEquals]: t(labels.lessThanEquals),
|
||||
[OPERATORS.before]: t(labels.before),
|
||||
[OPERATORS.after]: t(labels.after),
|
||||
};
|
||||
|
||||
const typeFilters = {
|
||||
string: [OPERATORS.equals, OPERATORS.notEquals, OPERATORS.contains, OPERATORS.doesNotContain],
|
||||
string: [
|
||||
OPERATORS.equals,
|
||||
OPERATORS.notEquals,
|
||||
OPERATORS.contains,
|
||||
OPERATORS.doesNotContain,
|
||||
OPERATORS.regex,
|
||||
OPERATORS.notRegex,
|
||||
],
|
||||
array: [OPERATORS.contains, OPERATORS.doesNotContain],
|
||||
boolean: [OPERATORS.true, OPERATORS.false],
|
||||
number: [
|
||||
|
||||
@@ -6,7 +6,7 @@ import { useLocale } from './useLocale';
|
||||
import { useMessages } from './useMessages';
|
||||
|
||||
export function useFormat() {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
const { locale } = useLocale();
|
||||
const { countryNames } = useCountryNames(locale);
|
||||
const { languageNames } = useLanguageNames(locale);
|
||||
@@ -20,7 +20,7 @@ export function useFormat() {
|
||||
};
|
||||
|
||||
const formatDevice = (value: string): string => {
|
||||
return formatMessage(labels[value] || labels.unknown);
|
||||
return t(labels[value] || labels.unknown);
|
||||
};
|
||||
|
||||
const formatCountry = (value: string): string => {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { httpGet } from '@/lib/fetch';
|
||||
import { getDateLocale, getTextDirection } from '@/lib/lang';
|
||||
import { setItem } from '@/lib/storage';
|
||||
import { setLocale, useApp } from '@/store/app';
|
||||
import enUS from '../../../public/intl/country/en-US.json';
|
||||
import enUS from '../../../public/intl/messages/en-US.json';
|
||||
import { useForceUpdate } from './useForceUpdate';
|
||||
|
||||
const messages = {
|
||||
|
||||
@@ -1,48 +1,25 @@
|
||||
import { FormattedMessage, type MessageDescriptor, useIntl } from 'react-intl';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { labels, messages } from '@/components/messages';
|
||||
import type { ApiError } from '@/lib/types';
|
||||
|
||||
type FormatMessage = (
|
||||
descriptor: MessageDescriptor,
|
||||
values?: Record<string, string | number | boolean | null | undefined>,
|
||||
opts?: any,
|
||||
) => string | null;
|
||||
export function useMessages() {
|
||||
const t = useTranslations();
|
||||
|
||||
interface UseMessages {
|
||||
formatMessage: FormatMessage;
|
||||
messages: typeof messages;
|
||||
labels: typeof labels;
|
||||
getMessage: (id: string) => string;
|
||||
getErrorMessage: (error: ApiError) => string | undefined;
|
||||
FormattedMessage: typeof FormattedMessage;
|
||||
}
|
||||
const getMessage = (id: string) => t(`message.${id}`);
|
||||
|
||||
export function useMessages(): UseMessages {
|
||||
const intl = useIntl();
|
||||
|
||||
const getMessage = (id: string) => {
|
||||
const message = Object.values(messages).find(value => value.id === `message.${id}`);
|
||||
|
||||
return message ? formatMessage(message) : id;
|
||||
};
|
||||
|
||||
const getErrorMessage = (error: ApiError) => {
|
||||
const getErrorMessage = (error: string | Error | undefined) => {
|
||||
if (!error) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const code = error?.code;
|
||||
if (typeof error === 'string') {
|
||||
return error;
|
||||
}
|
||||
|
||||
const code = (error as ApiError)?.code;
|
||||
|
||||
return code ? getMessage(code) : error?.message || 'Unknown error';
|
||||
};
|
||||
|
||||
const formatMessage = (
|
||||
descriptor: MessageDescriptor,
|
||||
values?: Record<string, string | number | boolean | null | undefined>,
|
||||
opts?: any,
|
||||
) => {
|
||||
return descriptor ? intl.formatMessage(descriptor, values, opts) : null;
|
||||
};
|
||||
|
||||
return { formatMessage, messages, labels, getMessage, getErrorMessage, FormattedMessage };
|
||||
return { t, messages, labels, getMessage, getErrorMessage };
|
||||
}
|
||||
@@ -2,8 +2,8 @@ import { useBreakpoint } from '@umami/react-zen';
|
||||
|
||||
export function useMobile() {
|
||||
const breakpoint = useBreakpoint();
|
||||
const isMobile = ['xs', 'sm', 'md'].includes(breakpoint);
|
||||
const isPhone = ['xs', 'sm'].includes(breakpoint);
|
||||
const isMobile = ['base', 'sm', 'md'].includes(breakpoint);
|
||||
const isPhone = ['base', 'sm'].includes(breakpoint);
|
||||
|
||||
return { breakpoint, isMobile, isPhone };
|
||||
}
|
||||
@@ -8,6 +8,9 @@ export function useNavigation() {
|
||||
const searchParams = useSearchParams();
|
||||
const [, teamId] = pathname.match(/\/teams\/([a-f0-9-]+)/) || [];
|
||||
const [, websiteId] = pathname.match(/\/websites\/([a-f0-9-]+)/) || [];
|
||||
const [, linkId] = pathname.match(/\/links\/([a-f0-9-]+)/) || [];
|
||||
const [, pixelId] = pathname.match(/\/pixels\/([a-f0-9-]+)/) || [];
|
||||
const [, boardId] = pathname.match(/\/boards\/([a-f0-9-]+)/) || [];
|
||||
const [queryParams, setQueryParams] = useState(Object.fromEntries(searchParams));
|
||||
|
||||
const updateParams = useCallback(
|
||||
@@ -45,6 +48,9 @@ export function useNavigation() {
|
||||
query: queryParams,
|
||||
teamId,
|
||||
websiteId,
|
||||
linkId,
|
||||
pixelId,
|
||||
boardId,
|
||||
updateParams,
|
||||
replaceParams,
|
||||
renderUrl,
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
import {
|
||||
AlignEndHorizontal,
|
||||
ChartPie,
|
||||
Clock,
|
||||
Eye,
|
||||
Sheet,
|
||||
Tag,
|
||||
User,
|
||||
UserPlus,
|
||||
} from '@/components/icons';
|
||||
import { Funnel, Lightning, Magnet, Money, Network, Path, Target } from '@/components/svg';
|
||||
import { useMessages } from './useMessages';
|
||||
import { useNavigation } from './useNavigation';
|
||||
|
||||
export function useWebsiteNavItems(websiteId: string) {
|
||||
const { t, labels } = useMessages();
|
||||
const { pathname, renderUrl } = useNavigation();
|
||||
|
||||
const renderPath = (path: string) =>
|
||||
renderUrl(`/websites/${websiteId}${path}`, {
|
||||
event: undefined,
|
||||
compare: undefined,
|
||||
view: undefined,
|
||||
unit: undefined,
|
||||
excludeBounce: undefined,
|
||||
});
|
||||
|
||||
const items = [
|
||||
{
|
||||
label: t(labels.traffic),
|
||||
items: [
|
||||
{
|
||||
id: 'overview',
|
||||
label: t(labels.overview),
|
||||
icon: <Eye />,
|
||||
path: renderPath(''),
|
||||
},
|
||||
{
|
||||
id: 'events',
|
||||
label: t(labels.events),
|
||||
icon: <Lightning />,
|
||||
path: renderPath('/events'),
|
||||
},
|
||||
{
|
||||
id: 'sessions',
|
||||
label: t(labels.sessions),
|
||||
icon: <User />,
|
||||
path: renderPath('/sessions'),
|
||||
},
|
||||
{
|
||||
id: 'realtime',
|
||||
label: t(labels.realtime),
|
||||
icon: <Clock />,
|
||||
path: renderPath('/realtime'),
|
||||
},
|
||||
{
|
||||
id: 'compare',
|
||||
label: t(labels.compare),
|
||||
icon: <AlignEndHorizontal />,
|
||||
path: renderPath('/compare'),
|
||||
},
|
||||
{
|
||||
id: 'breakdown',
|
||||
label: t(labels.breakdown),
|
||||
icon: <Sheet />,
|
||||
path: renderPath('/breakdown'),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: t(labels.behavior),
|
||||
items: [
|
||||
{
|
||||
id: 'goals',
|
||||
label: t(labels.goals),
|
||||
icon: <Target />,
|
||||
path: renderPath('/goals'),
|
||||
},
|
||||
{
|
||||
id: 'funnel',
|
||||
label: t(labels.funnels),
|
||||
icon: <Funnel />,
|
||||
path: renderPath('/funnels'),
|
||||
},
|
||||
{
|
||||
id: 'journeys',
|
||||
label: t(labels.journeys),
|
||||
icon: <Path />,
|
||||
path: renderPath('/journeys'),
|
||||
},
|
||||
{
|
||||
id: 'retention',
|
||||
label: t(labels.retention),
|
||||
icon: <Magnet />,
|
||||
path: renderPath('/retention'),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: t(labels.audience),
|
||||
items: [
|
||||
{
|
||||
id: 'segments',
|
||||
label: t(labels.segments),
|
||||
icon: <ChartPie />,
|
||||
path: renderPath('/segments'),
|
||||
},
|
||||
{
|
||||
id: 'cohorts',
|
||||
label: t(labels.cohorts),
|
||||
icon: <UserPlus />,
|
||||
path: renderPath('/cohorts'),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: t(labels.growth),
|
||||
items: [
|
||||
{
|
||||
id: 'utm',
|
||||
label: t(labels.utm),
|
||||
icon: <Tag />,
|
||||
path: renderPath('/utm'),
|
||||
},
|
||||
{
|
||||
id: 'revenue',
|
||||
label: t(labels.revenue),
|
||||
icon: <Money />,
|
||||
path: renderPath('/revenue'),
|
||||
},
|
||||
{
|
||||
id: 'attribution',
|
||||
label: t(labels.attribution),
|
||||
icon: <Network />,
|
||||
path: renderPath('/attribution'),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const selectedKey = items
|
||||
.flatMap(e => e.items)
|
||||
.find(({ path }) => path && pathname.endsWith(path.split('?')[0]))?.id;
|
||||
|
||||
return { items, selectedKey, renderPath };
|
||||
}
|
||||
Reference in new issue
Block a user