implement session replay filters

This commit is contained in:
Francis Cao committed 2026-06-17 11:38:57 -07:00
1 parent f3ce0e64ca
commit c61c01e3bb
62 files changed
+264 -372

No files matched your search

@@ -286,8 +286,9 @@ function ClickHeatmapView({
: '100%';
const overlayPageW = snapshot?.pageW ?? viewport?.pageW ?? baseWidth;
const overlayPageH = snapshot?.pageH ?? viewport?.pageH ?? baseHeight;
const showSnapshot = renderWidth > 0 && showPage && hasSnapshot;
const showOverlay = !showSnapshot || snapshotReady;
const shouldRenderSnapshot = renderWidth > 0 && hasSnapshot;
const showSnapshot = shouldRenderSnapshot && showPage;
const showOverlay = !showPage || !shouldRenderSnapshot || snapshotReady;
const totalClicks = visible.reduce((sum, point) => sum + point.count, 0);
const showLoading = isLoading;
@@ -345,12 +346,14 @@ function ClickHeatmapView({
<>
<div className={styles.snapshotClip}>
{showSnapshot && !snapshotReady && <CanvasLoading />}
{showSnapshot && snapshot && (
<SnapshotPreview
websiteId={websiteId}
snapshot={snapshot}
onReady={handleSnapshotReady}
/>
{shouldRenderSnapshot && snapshot && (
<div hidden={!showPage}>
<SnapshotPreview
websiteId={websiteId}
snapshot={snapshot}
onReady={handleSnapshotReady}
/>
</div>
)}
</div>
{showOverlay && (
@@ -445,8 +448,9 @@ function ScrollHeatmapView({
? `${renderWidth}px`
: `min(100%, ${renderWidth}px)`
: '100%';
const showSnapshot = renderWidth > 0 && showPage && hasSnapshot;
const showOverlay = !showSnapshot || snapshotReady;
const shouldRenderSnapshot = renderWidth > 0 && hasSnapshot;
const showSnapshot = shouldRenderSnapshot && showPage;
const showOverlay = !showPage || !shouldRenderSnapshot || snapshotReady;
const hasScrollData = Boolean(scroll && totalSessions > 0 && pageW && pageH && viewportW);
const showLoading = isLoading;
@@ -520,12 +524,14 @@ function ScrollHeatmapView({
) : (
<div className={styles.canvasClip}>
{showSnapshot && !snapshotReady && <CanvasLoading />}
{showSnapshot && snapshot && (
<SnapshotPreview
websiteId={websiteId}
snapshot={snapshot}
onReady={handleSnapshotReady}
/>
{shouldRenderSnapshot && snapshot && (
<div hidden={!showPage}>
<SnapshotPreview
websiteId={websiteId}
snapshot={snapshot}
onReady={handleSnapshotReady}
/>
</div>
)}
{showOverlay && (
<div className={styles.overlay}>
@@ -0,0 +1,96 @@
'use client';
import { Button, Column, Label, Row, Text, TextField } from '@umami/react-zen';
import { useState } from 'react';
import { useMessages, useNavigation } from '@/components/hooks';
import { ListFilter } from '@/components/icons';
import { DialogButton } from '@/components/input/DialogButton';
const DEFAULT_MIN_DURATION = '5';
function getMinDurationValue(value: unknown) {
if (value === '0') {
return '';
}
if (typeof value !== 'string' || !/^\d+$/.test(value)) {
return DEFAULT_MIN_DURATION;
}
return Number(value) > 0 ? value : DEFAULT_MIN_DURATION;
}
function ReplayFilterForm({
minDuration,
onClose,
}: {
minDuration: string;
onClose?: () => void;
}) {
const { t, labels, messages } = useMessages();
const { router, updateParams } = useNavigation();
const [value, setValue] = useState(minDuration);
const handleChange = (nextValue: string) => {
if (/^\d*$/.test(nextValue)) {
setValue(nextValue);
}
};
const handleReset = () => {
setValue(DEFAULT_MIN_DURATION);
};
const handleApply = () => {
const nextValue = value ? Number(value) : 0;
router.push(
updateParams({
minDuration: nextValue > 0 ? nextValue : 0,
page: 1,
}),
);
onClose?.();
};
return (
<Column width="320px" gap="4">
<Column gap="2">
<Label>{t(labels.minDurationSeconds)}</Label>
<Text color="muted">{t(messages.replayMinDurationDescription)}</Text>
<TextField
value={value}
onChange={handleChange}
autoFocus
autoComplete="off"
inputMode="numeric"
placeholder="10"
/>
</Column>
<Row alignItems="center" justifyContent="space-between" gap>
<Button onPress={handleReset}>{t(labels.reset)}</Button>
<Row alignItems="center" justifyContent="flex-end" gap>
<Button onPress={onClose}>{t(labels.cancel)}</Button>
<Button variant="primary" onPress={handleApply}>
{t(labels.apply)}
</Button>
</Row>
</Row>
</Column>
);
}
export function ReplayFilterButton() {
const { t, labels } = useMessages();
const { query } = useNavigation();
const minDuration = getMinDurationValue(query.minDuration);
const title = `${t(labels.replay)} ${t(labels.filter)}`;
const label = minDuration ? `${title} (${minDuration}s+)` : title;
return (
<DialogButton icon={<ListFilter />} label={label} title={title} variant="outline">
{({ close }) => <ReplayFilterForm minDuration={minDuration} onClose={close} />}
</DialogButton>
);
}
@@ -1,12 +1,25 @@
import { DataGrid } from '@/components/common/DataGrid';
import { useReplaysQuery } from '@/components/hooks';
import { useNavigation, useReplaysQuery } from '@/components/hooks';
import { ReplayFilterButton } from './ReplayFilterButton';
import { ReplaysTable } from './ReplaysTable';
const DEFAULT_MIN_DURATION = 5;
export function ReplaysDataTable({ websiteId }: { websiteId: string }) {
const queryResult = useReplaysQuery(websiteId);
const { query } = useNavigation();
const minDuration =
typeof query.minDuration === 'string' && /^\d+$/.test(query.minDuration)
? query.minDuration
: String(DEFAULT_MIN_DURATION);
const queryResult = useReplaysQuery(websiteId, { minDuration });
return (
<DataGrid query={queryResult} allowPaging allowSearch>
<DataGrid
query={queryResult}
allowPaging
allowSearch
renderActions={() => <ReplayFilterButton />}
>
{({ data }) => {
return <ReplaysTable data={data} />;
}}
@@ -1,6 +1,6 @@
import { getQueryFilters, parseRequest } from '@/lib/request';
import { json, unauthorized } from '@/lib/response';
import { filterParams, pagingParams, searchParams, withDateRange } from '@/lib/schema';
import { filterParams, pagingParams, replayParams, searchParams, withDateRange } from '@/lib/schema';
import { canViewAuthenticatedWebsite } from '@/permissions';
import { getSessionReplays } from '@/queries/sql';
@@ -10,6 +10,7 @@ export async function GET(
) {
const schema = withDateRange({
...filterParams,
...replayParams,
...pagingParams,
...searchParams,
});