Session/Event Property CSS fixes. Session Activity performance changes
This commit is contained in:
1 parent
92fd4b71c3
commit
d4e864e4d9
8 files changed
+161
-90
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { Box, Column, Label, Row, Text } from '@umami/react-zen';
|
||||
import { Column, Label, Row, Text } from '@umami/react-zen';
|
||||
import { Badge } from '@/components/common/Badge';
|
||||
import { Empty } from '@/components/common/Empty';
|
||||
import { LoadingPanel } from '@/components/common/LoadingPanel';
|
||||
import { useSessionDataQuery } from '@/components/hooks';
|
||||
@@ -17,11 +18,9 @@ export function SessionData({ websiteId, sessionId }: { websiteId: string; sessi
|
||||
<Label>{dataKey}</Label>
|
||||
<Row alignItems="center" gap>
|
||||
<Text>{stringValue}</Text>
|
||||
<Box paddingY="1" paddingX="2" border borderRadius borderColor="muted">
|
||||
<Text color="muted" size="xs">
|
||||
{DATA_TYPES[dataType]}
|
||||
</Text>
|
||||
</Box>
|
||||
<Badge variant="gray" dot={false}>
|
||||
{DATA_TYPES[dataType]}
|
||||
</Badge>
|
||||
</Row>
|
||||
</Column>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import { endOfMonth, startOfMonth } from 'date-fns';
|
||||
import { beforeEach, expect, test, vi } from 'vitest';
|
||||
import { getQueryFilters, parseRequest } from '@/lib/request';
|
||||
import { canViewWebsiteSection } from '@/permissions';
|
||||
import { getLinkedSessionIds, getSessionActivity } from '@/queries/sql';
|
||||
import { GET } from './route';
|
||||
|
||||
vi.mock('@/lib/request', () => ({
|
||||
getQueryFilters: vi.fn(),
|
||||
parseRequest: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('@/permissions', () => ({
|
||||
canViewWebsiteSection: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('@/queries/sql', () => ({
|
||||
getLinkedDistinctIds: vi.fn(),
|
||||
getLinkedSessionIds: vi.fn(),
|
||||
getSessionActivity: vi.fn(),
|
||||
}));
|
||||
|
||||
const parseRequestMock = vi.mocked(parseRequest);
|
||||
const getQueryFiltersMock = vi.mocked(getQueryFilters);
|
||||
const canViewWebsiteSectionMock = vi.mocked(canViewWebsiteSection);
|
||||
const getLinkedSessionIdsMock = vi.mocked(getLinkedSessionIds);
|
||||
const getSessionActivityMock = vi.mocked(getSessionActivity);
|
||||
|
||||
beforeEach(() => {
|
||||
parseRequestMock.mockReset();
|
||||
getQueryFiltersMock.mockReset();
|
||||
canViewWebsiteSectionMock.mockReset();
|
||||
getLinkedSessionIdsMock.mockReset();
|
||||
getSessionActivityMock.mockReset();
|
||||
});
|
||||
|
||||
test('uses linked session months to widen stitched activity without scanning event bounds', async () => {
|
||||
const query = {
|
||||
startAt: +new Date('2026-07-20T23:38:54.000Z'),
|
||||
endAt: +new Date('2026-07-21T00:08:01.000Z'),
|
||||
distinctId: 'bob@aol.com',
|
||||
};
|
||||
const linkedStart = new Date('2026-05-15T12:00:00.000Z');
|
||||
const linkedEnd = new Date('2026-08-02T12:00:00.000Z');
|
||||
const filters = {
|
||||
startDate: startOfMonth(linkedStart),
|
||||
endDate: endOfMonth(linkedEnd),
|
||||
};
|
||||
|
||||
parseRequestMock.mockResolvedValue({ auth: {}, query, error: undefined });
|
||||
canViewWebsiteSectionMock.mockResolvedValue(true);
|
||||
getLinkedSessionIdsMock.mockResolvedValue([
|
||||
{ sessionId: 'session-2', createdAt: linkedStart.toISOString() },
|
||||
{ sessionId: 'session-3', createdAt: linkedEnd.toISOString() },
|
||||
]);
|
||||
getQueryFiltersMock.mockResolvedValue(filters);
|
||||
getSessionActivityMock.mockResolvedValue([{ eventId: 'event-1' }]);
|
||||
|
||||
const response = await GET(
|
||||
new Request(
|
||||
'http://localhost/api/websites/website-1/sessions/session-1/activity?startAt=1784590734000&endAt=1784592481000&distinctId=bob%40aol.com',
|
||||
),
|
||||
{
|
||||
params: Promise.resolve({ websiteId: 'website-1', sessionId: 'session-1' }),
|
||||
},
|
||||
);
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
expect(getLinkedSessionIdsMock).toHaveBeenCalledWith('website-1', 'bob@aol.com');
|
||||
expect(getQueryFiltersMock).toHaveBeenCalledWith(
|
||||
{
|
||||
...query,
|
||||
startAt: +startOfMonth(linkedStart),
|
||||
endAt: +endOfMonth(linkedEnd),
|
||||
},
|
||||
'website-1',
|
||||
);
|
||||
expect(getSessionActivityMock).toHaveBeenCalledWith(
|
||||
'website-1',
|
||||
['session-1', 'session-2', 'session-3'],
|
||||
filters,
|
||||
);
|
||||
await expect(response.json()).resolves.toEqual([{ eventId: 'event-1' }]);
|
||||
});
|
||||
@@ -1,3 +1,4 @@
|
||||
import { endOfMonth, startOfMonth } from 'date-fns';
|
||||
import { z } from 'zod';
|
||||
import { FIELD_LENGTH } from '@/lib/constants';
|
||||
import { getQueryFilters, parseRequest } from '@/lib/request';
|
||||
@@ -7,7 +8,6 @@ import {
|
||||
getLinkedDistinctIds,
|
||||
getLinkedSessionIds,
|
||||
getSessionActivity,
|
||||
getSessionActivityBounds,
|
||||
} from '@/queries/sql';
|
||||
|
||||
export async function GET(
|
||||
@@ -42,18 +42,19 @@ export async function GET(
|
||||
: await getLinkedDistinctIds(websiteId, sessionId);
|
||||
|
||||
if (distinctIds.length) {
|
||||
const links = await Promise.all(distinctIds.map(distinctId => getLinkedSessionIds(websiteId, distinctId)));
|
||||
const links = await Promise.all(
|
||||
distinctIds.map(distinctId => getLinkedSessionIds(websiteId, distinctId)),
|
||||
);
|
||||
const linkedIds = links.flatMap(group => group.map(link => link.sessionId));
|
||||
const linkedDates = links
|
||||
.flatMap(group => group.map(link => +new Date(link.createdAt)))
|
||||
.filter(timestamp => !Number.isNaN(timestamp));
|
||||
|
||||
sessionIds = Array.from(new Set([sessionId, ...linkedIds]));
|
||||
|
||||
if (sessionIds.length > 1) {
|
||||
const bounds = await getSessionActivityBounds(websiteId, sessionIds);
|
||||
|
||||
if (bounds?.firstAt && bounds?.lastAt) {
|
||||
startAt = Math.min(startAt, +new Date(bounds.firstAt));
|
||||
endAt = Math.max(endAt, +new Date(bounds.lastAt));
|
||||
}
|
||||
if (sessionIds.length > 1 && linkedDates.length) {
|
||||
startAt = Math.min(startAt, +startOfMonth(new Date(Math.min(...linkedDates))));
|
||||
endAt = Math.max(endAt, +endOfMonth(new Date(Math.max(...linkedDates))));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user