performance page polish
This commit is contained in:
1 parent
31caa0d62e
commit
383922ab17
9 files changed
+113
-54
No files matched your search
@@ -288,6 +288,7 @@
|
||||
"share": "Share",
|
||||
"share-url": "Share URL",
|
||||
"single-day": "Single day",
|
||||
"slug": "Slug",
|
||||
"sms": "SMS",
|
||||
"source": "Source",
|
||||
"sources": "Sources",
|
||||
|
||||
@@ -94,7 +94,7 @@ export function LinkEditForm({
|
||||
<Grid columns="1fr auto" alignItems="end" gap>
|
||||
<FormField
|
||||
name="slug"
|
||||
label={t({ id: 'label.slug', defaultMessage: 'Slug' })}
|
||||
label={t(labels.slug)}
|
||||
rules={{
|
||||
required: t(labels.required),
|
||||
}}
|
||||
|
||||
@@ -18,9 +18,9 @@ import { BarChart } from '@/components/charts/BarChart';
|
||||
import { GridRow } from '@/components/common/GridRow';
|
||||
import { LoadingPanel } from '@/components/common/LoadingPanel';
|
||||
import { Panel } from '@/components/common/Panel';
|
||||
import { TypeIcon } from '@/components/common/TypeIcon';
|
||||
import { useLocale, useMessages, useResultQuery } from '@/components/hooks';
|
||||
import { ListTable } from '@/components/metrics/ListTable';
|
||||
import { MetricLabel } from '@/components/metrics/MetricLabel';
|
||||
import { PerformanceCard } from '@/components/metrics/PerformanceCard';
|
||||
import { renderDateLabels } from '@/lib/charts';
|
||||
import { CHART_COLORS, WEB_VITALS_THRESHOLDS } from '@/lib/constants';
|
||||
@@ -46,9 +46,8 @@ const METRIC_LABELS: Record<string, string> = {
|
||||
};
|
||||
|
||||
function formatMetricValue(metric: string, value: number): string {
|
||||
if (metric === 'cls') {
|
||||
return value.toFixed(3);
|
||||
}
|
||||
if (metric === 'cls') return value.toFixed(3);
|
||||
if (value >= 1000) return `${(value / 1000).toFixed(2)} s`;
|
||||
return `${Math.round(value)} ms`;
|
||||
}
|
||||
|
||||
@@ -138,6 +137,11 @@ export function Performance({ websiteId, startDate, endDate, unit }: Performance
|
||||
const renderXLabel = useCallback(renderDateLabels(unit, locale), [unit, locale]);
|
||||
|
||||
const threshold = WEB_VITALS_THRESHOLDS[selectedMetric as keyof typeof WEB_VITALS_THRESHOLDS];
|
||||
const isCls = selectedMetric === 'cls';
|
||||
const metricLabel = t(labels[selectedMetric]) || selectedMetric.toUpperCase();
|
||||
const formatListCount = isCls
|
||||
? (n: number) => n.toFixed(3)
|
||||
: (n: number) => `${(n / 1000).toFixed(2)} s`;
|
||||
|
||||
return (
|
||||
<Column gap>
|
||||
@@ -189,6 +193,7 @@ export function Performance({ websiteId, startDate, endDate, unit }: Performance
|
||||
renderYLabel={(label: string) => {
|
||||
const val = Number(label);
|
||||
if (selectedMetric === 'cls') return val.toFixed(2);
|
||||
if (val >= 1000) return `${(val / 1000).toFixed(2)} s`;
|
||||
return `${Math.round(val)} ms`;
|
||||
}}
|
||||
height="400px"
|
||||
@@ -205,26 +210,40 @@ export function Performance({ websiteId, startDate, endDate, unit }: Performance
|
||||
</TabList>
|
||||
<TabPanel id="path">
|
||||
<ListTable
|
||||
metric={t(labels[selectedMetric]) || selectedMetric.toUpperCase()}
|
||||
metric={metricLabel}
|
||||
showPercentage={false}
|
||||
data={data.pages?.map(({ name, p50, p75, p95 }: any) => ({
|
||||
label: name,
|
||||
count: Number({ p50, p75, p95 }[selectedPercentile]),
|
||||
percent: 0,
|
||||
}))}
|
||||
formatCount={formatListCount}
|
||||
data={data.pages
|
||||
?.filter(
|
||||
({ p50, p75, p95 }: any) =>
|
||||
Number({ p50, p75, p95 }[selectedPercentile]) > 0,
|
||||
)
|
||||
.slice(0, 20)
|
||||
.map(({ name, p50, p75, p95 }: any) => ({
|
||||
label: name,
|
||||
count: Number({ p50, p75, p95 }[selectedPercentile]),
|
||||
percent: 0,
|
||||
}))}
|
||||
renderLabel={({ label }: { label: string }) => <Text>{label}</Text>}
|
||||
/>
|
||||
</TabPanel>
|
||||
<TabPanel id="title">
|
||||
<ListTable
|
||||
metric={t(labels[selectedMetric]) || selectedMetric.toUpperCase()}
|
||||
metric={metricLabel}
|
||||
showPercentage={false}
|
||||
data={data.pageTitles?.map(({ name, p50, p75, p95 }: any) => ({
|
||||
label: name,
|
||||
count: Number({ p50, p75, p95 }[selectedPercentile]),
|
||||
percent: 0,
|
||||
}))}
|
||||
renderLabel={({ label }: { label: string }) => <Text>{label}</Text>}
|
||||
formatCount={formatListCount}
|
||||
data={data.pageTitles
|
||||
?.filter(
|
||||
({ p50, p75, p95 }: any) =>
|
||||
Number({ p50, p75, p95 }[selectedPercentile]) > 0,
|
||||
)
|
||||
.slice(0, 20)
|
||||
.map(({ name, p50, p75, p95 }: any) => ({
|
||||
label: name,
|
||||
count: Number({ p50, p75, p95 }[selectedPercentile]),
|
||||
percent: 0,
|
||||
}))}
|
||||
renderLabel={(row: any) => <MetricLabel type="title" data={row} />}
|
||||
/>
|
||||
</TabPanel>
|
||||
</Tabs>
|
||||
@@ -238,36 +257,40 @@ export function Performance({ websiteId, startDate, endDate, unit }: Performance
|
||||
</TabList>
|
||||
<TabPanel id="device">
|
||||
<ListTable
|
||||
metric={t(labels[selectedMetric]) || selectedMetric.toUpperCase()}
|
||||
metric={metricLabel}
|
||||
showPercentage={false}
|
||||
data={data.devices?.map(({ name, p50, p75, p95 }: any) => ({
|
||||
label: name,
|
||||
count: Number({ p50, p75, p95 }[selectedPercentile]),
|
||||
percent: 0,
|
||||
}))}
|
||||
renderLabel={({ label }: { label: string }) => (
|
||||
<Row gap="2" alignItems="center">
|
||||
<TypeIcon type="device" value={label} />
|
||||
<Text>{label}</Text>
|
||||
</Row>
|
||||
)}
|
||||
formatCount={formatListCount}
|
||||
data={data.devices
|
||||
?.filter(
|
||||
({ p50, p75, p95 }: any) =>
|
||||
Number({ p50, p75, p95 }[selectedPercentile]) > 0,
|
||||
)
|
||||
.slice(0, 20)
|
||||
.map(({ name, p50, p75, p95 }: any) => ({
|
||||
label: name,
|
||||
count: Number({ p50, p75, p95 }[selectedPercentile]),
|
||||
percent: 0,
|
||||
}))}
|
||||
renderLabel={(row: any) => <MetricLabel type="device" data={row} />}
|
||||
/>
|
||||
</TabPanel>
|
||||
<TabPanel id="browser">
|
||||
<ListTable
|
||||
metric={t(labels[selectedMetric]) || selectedMetric.toUpperCase()}
|
||||
metric={metricLabel}
|
||||
showPercentage={false}
|
||||
data={data.browsers?.map(({ name, p50, p75, p95 }: any) => ({
|
||||
label: name,
|
||||
count: Number({ p50, p75, p95 }[selectedPercentile]),
|
||||
percent: 0,
|
||||
}))}
|
||||
renderLabel={({ label }: { label: string }) => (
|
||||
<Row gap="2" alignItems="center">
|
||||
<TypeIcon type="browser" value={label} />
|
||||
<Text>{label}</Text>
|
||||
</Row>
|
||||
)}
|
||||
formatCount={formatListCount}
|
||||
data={data.browsers
|
||||
?.filter(
|
||||
({ p50, p75, p95 }: any) =>
|
||||
Number({ p50, p75, p95 }[selectedPercentile]) > 0,
|
||||
)
|
||||
.slice(0, 20)
|
||||
.map(({ name, p50, p75, p95 }: any) => ({
|
||||
label: name,
|
||||
count: Number({ p50, p75, p95 }[selectedPercentile]),
|
||||
percent: 0,
|
||||
}))}
|
||||
renderLabel={(row: any) => <MetricLabel type="browser" data={row} />}
|
||||
/>
|
||||
</TabPanel>
|
||||
</Tabs>
|
||||
|
||||
@@ -95,6 +95,7 @@ export function FieldFilters({
|
||||
>
|
||||
{groupLabels.map(({ key: groupKey, label }) => {
|
||||
const groupFields = groupedFields[groupKey];
|
||||
if (!groupFields || groupFields.length === 0) return null;
|
||||
return (
|
||||
<MenuSection key={groupKey} title={label}>
|
||||
{groupFields.map(field => {
|
||||
|
||||
@@ -27,8 +27,28 @@ export function FilterEditForm({ websiteId, onChange, onClose }: FilterEditFormP
|
||||
const [currentCohort, setCurrentCohort] = useState(cohort);
|
||||
const [currentMatch, setCurrentMatch] = useState<string>(match || 'all');
|
||||
const { isMobile } = useMobile();
|
||||
const excludeFilters = !websiteId || pathname.includes('/pixels') || pathname.includes('/links');
|
||||
const isPixelLink = !websiteId || pathname.includes('/pixels') || pathname.includes('/links');
|
||||
const excludeEvent = !pathname.endsWith('/events') && !pathname.endsWith('/replays');
|
||||
const isPerformance = pathname.includes('/performance');
|
||||
|
||||
const excludedFields = isPixelLink
|
||||
? ['path', 'title', 'hostname', 'distinctId', 'tag', 'event']
|
||||
: isPerformance
|
||||
? [
|
||||
'referrer',
|
||||
'query',
|
||||
'event',
|
||||
'tag',
|
||||
'distinctId',
|
||||
'utmSource',
|
||||
'utmMedium',
|
||||
'utmCampaign',
|
||||
'utmContent',
|
||||
'utmTerm',
|
||||
]
|
||||
: excludeEvent
|
||||
? ['event']
|
||||
: [];
|
||||
|
||||
const handleReset = () => {
|
||||
setCurrentFilters([]);
|
||||
@@ -58,7 +78,7 @@ export function FilterEditForm({ websiteId, onChange, onClose }: FilterEditFormP
|
||||
<Tabs>
|
||||
<TabList>
|
||||
<Tab id="fields">{t(labels.fields)}</Tab>
|
||||
{!excludeFilters && (
|
||||
{!isPixelLink && (
|
||||
<>
|
||||
<Tab id="segments">{t(labels.segments)}</Tab>
|
||||
<Tab id="cohorts">{t(labels.cohorts)}</Tab>
|
||||
@@ -72,13 +92,7 @@ export function FilterEditForm({ websiteId, onChange, onClose }: FilterEditFormP
|
||||
match={currentMatch}
|
||||
onChange={setCurrentFilters}
|
||||
onMatchChange={setCurrentMatch}
|
||||
exclude={
|
||||
excludeFilters
|
||||
? ['path', 'title', 'hostname', 'distinctId', 'tag', 'event']
|
||||
: excludeEvent
|
||||
? ['event']
|
||||
: []
|
||||
}
|
||||
exclude={excludedFields}
|
||||
/>
|
||||
</TabPanel>
|
||||
<TabPanel id="segments">
|
||||
|
||||
@@ -339,6 +339,7 @@ export const labels: Record<string, string> = {
|
||||
saveCohort: 'label.save-cohort',
|
||||
analysis: 'label.analysis',
|
||||
destinationUrl: 'label.destination-url',
|
||||
slug: 'label.slug',
|
||||
audience: 'label.audience',
|
||||
invalidUrl: 'label.invalid-url',
|
||||
environment: 'label.environment',
|
||||
|
||||
@@ -27,6 +27,7 @@ export interface ListTableProps {
|
||||
showPercentage?: boolean;
|
||||
itemCount?: number;
|
||||
currency?: string;
|
||||
formatCount?: (n: number) => string;
|
||||
}
|
||||
|
||||
export function ListTable({
|
||||
@@ -40,6 +41,7 @@ export function ListTable({
|
||||
showPercentage = true,
|
||||
itemCount = 10,
|
||||
currency,
|
||||
formatCount,
|
||||
}: ListTableProps) {
|
||||
const { t, labels } = useMessages();
|
||||
const { isPhone } = useMobile();
|
||||
@@ -57,6 +59,7 @@ export function ListTable({
|
||||
showPercentage={showPercentage}
|
||||
change={renderChange ? renderChange(row, index) : null}
|
||||
currency={currency}
|
||||
formatCount={formatCount}
|
||||
isPhone={isPhone}
|
||||
/>
|
||||
);
|
||||
@@ -106,6 +109,7 @@ const AnimatedRow = ({
|
||||
animate,
|
||||
showPercentage = true,
|
||||
currency,
|
||||
formatCount,
|
||||
isPhone,
|
||||
}) => {
|
||||
const props = useSpring({
|
||||
@@ -135,7 +139,9 @@ const AnimatedRow = ({
|
||||
<AnimatedDiv title={props?.y as any}>
|
||||
{currency
|
||||
? props.y?.to(n => formatLongCurrency(n, currency))
|
||||
: props.y?.to(formatLongNumber)}
|
||||
: formatCount
|
||||
? props.y?.to(formatCount)
|
||||
: props.y?.to(formatLongNumber)}
|
||||
</AnimatedDiv>
|
||||
</Text>
|
||||
</Row>
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
}
|
||||
|
||||
.card:hover {
|
||||
box-shadow: 0 0 0 1px color-mix(in srgb, var(--primary) 15%, transparent);
|
||||
box-shadow:
|
||||
0 0 0 1px color-mix(in srgb, var(--primary) 40%, transparent),
|
||||
0 0 6px color-mix(in srgb, var(--primary) 15%, transparent);
|
||||
}
|
||||
|
||||
.card.selected {
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { config, useSpring } from '@react-spring/web';
|
||||
import { Column, Text } from '@umami/react-zen';
|
||||
import { useRef } from 'react';
|
||||
import { AnimatedDiv } from '@/components/common/AnimatedDiv';
|
||||
import { useMessages } from '@/components/hooks';
|
||||
import { WEB_VITALS_THRESHOLDS } from '@/lib/constants';
|
||||
import { formatNumber } from '@/lib/format';
|
||||
@@ -31,6 +34,14 @@ export const PerformanceCard = ({
|
||||
}: PerformanceCardProps) => {
|
||||
const { t, labels } = useMessages();
|
||||
const rating = getRating(metric, value);
|
||||
const prevMetricRef = useRef(metric);
|
||||
const metricChanged = prevMetricRef.current !== metric;
|
||||
if (metricChanged) prevMetricRef.current = metric;
|
||||
|
||||
const spring = useSpring({
|
||||
value: !Number.isNaN(value) ? value : 0,
|
||||
config: metricChanged ? { duration: 0 } : config.default,
|
||||
});
|
||||
|
||||
return (
|
||||
<Column
|
||||
@@ -49,7 +60,7 @@ export const PerformanceCard = ({
|
||||
{label}
|
||||
</Text>
|
||||
<Text size="4xl" weight="bold" wrap="nowrap">
|
||||
{formatValue(value)}
|
||||
<AnimatedDiv>{spring.value.to(n => formatValue(n))}</AnimatedDiv>
|
||||
</Text>
|
||||
<Text size="sm" className={styles.rating}>
|
||||
{t(labels[rating === 'needs-improvement' ? 'needsImprovement' : rating])}
|
||||
|
||||
Reference in new issue
Block a user