From 877945e72146e76aedadb4f6564c29b76d674019 Mon Sep 17 00:00:00 2001 From: Francis Cao Date: Mon, 27 Apr 2026 12:09:13 -0700 Subject: [PATCH] Event data UI/UX polish --- .../event-data/EventDataDateChart.tsx | 89 ++++++++++++------- .../event-data/EventDataPivotTable.tsx | 55 ++++++++++-- .../[websiteId]/events/EventProperties.tsx | 13 +-- .../[websiteId]/events/EventsPage.tsx | 14 +-- 4 files changed, 124 insertions(+), 47 deletions(-) diff --git a/src/app/(main)/websites/[websiteId]/event-data/EventDataDateChart.tsx b/src/app/(main)/websites/[websiteId]/event-data/EventDataDateChart.tsx index 136d73aa0..c075a46d5 100644 --- a/src/app/(main)/websites/[websiteId]/event-data/EventDataDateChart.tsx +++ b/src/app/(main)/websites/[websiteId]/event-data/EventDataDateChart.tsx @@ -169,7 +169,20 @@ export function EventDataDateChart({ }, [exactDateRows, chartUnit, dateLocale]); const chartData: any = useMemo(() => { - if (!rows.length || !minPropertyDate || !maxPropertyDate) return null; + if (!minPropertyDate || !maxPropertyDate) { + return { + datasets: [ + { + label: t(labels.count), + data: [], + barPercentage: 0.9, + categoryPercentage: 0.9, + ...colors.chart.visitors, + borderWidth: 1, + }, + ], + }; + } return { datasets: [ @@ -231,6 +244,28 @@ export function EventDataDateChart({ }; }); }, [exactDateRows, total, dateLocale]); + const topDateByDay = useMemo(() => { + if (!exactDateRows.length || total === 0) return null; + + const dayTotals = exactDateRows.reduce( + (obj, { date, y }) => { + const dayDate = startOfDay(date); + const key = format(dayDate, 'yyyy-MM-dd'); + const existing = obj[key]; + + obj[key] = { + date: dayDate, + count: (existing?.count ?? 0) + y, + }; + + return obj; + }, + {} as Record, + ); + + return Object.values(dayTotals) + .sort((a, b) => b.count - a.count || b.date.getTime() - a.date.getTime())[0]; + }, [exactDateRows, total]); const topWeekday = useMemo( () => [...weekdayTableData].sort((a, b) => b.count - a.count)[0], @@ -264,18 +299,9 @@ export function EventDataDateChart({ ], }; }, [weekdayTableData, weekdayLabels, weekdayColorMap]); - const spanDays = useMemo( - () => - minPropertyDate && maxPropertyDate - ? differenceInCalendarDays(maxPropertyDate, minPropertyDate) + 1 - : 0, - [minPropertyDate, maxPropertyDate], - ); - return ( - {chartData && minPropertyDate && maxPropertyDate && ( - formatLongNumber(Number(value))} - height="400px" - /> - )} + + {chartData && ( + formatLongNumber(Number(value))} + height="400px" + /> + )} + (keys)]; }, [propertiesQuery.data, eventName]); + const tableMinWidth = useMemo(() => { + return `${72 + 220 + 180 + propertyKeys.length * 160}px`; + }, [propertyKeys.length]); + const tableData = useMemo(() => { if (!pivotQuery.data?.data) return []; return pivotQuery.data.data.map( @@ -76,16 +80,16 @@ export function EventDataPivotTable({ renderEmpty={() => } > - - - + {isMobile ? ( + + {(row: any) => ( )} - + {(row: any) => ( {row.urlPath} @@ -93,7 +97,7 @@ export function EventDataPivotTable({ )} {propertyKeys.map(key => ( - + {(row: any) => ( {row[key] ?? ''} @@ -101,11 +105,48 @@ export function EventDataPivotTable({ )} ))} - + {(row: any) => } - + ) : ( +
+
+ + + {(row: any) => ( + + + + )} + + + {(row: any) => ( + + {row.urlPath} + + )} + + {propertyKeys.map(key => ( + + {(row: any) => ( + + {row[key] ?? ''} + + )} + + ))} + + {(row: any) => } + + +
+
+ )} {showPager && tableQuery && ( )} {eventName && ( - + + + )}
diff --git a/src/app/(main)/websites/[websiteId]/events/EventsPage.tsx b/src/app/(main)/websites/[websiteId]/events/EventsPage.tsx index 5f5ab82a8..f359b9cb0 100644 --- a/src/app/(main)/websites/[websiteId]/events/EventsPage.tsx +++ b/src/app/(main)/websites/[websiteId]/events/EventsPage.tsx @@ -87,17 +87,21 @@ export function EventsPage({ websiteId }) { })} - - handleSelect(key)}> + + handleSelect(key)} + style={{ minWidth: 0, width: '100%' }} + > {t(labels.chart)} {t(labels.activity)} {t(labels.properties)} - + - + @@ -111,7 +115,7 @@ export function EventsPage({ websiteId }) { /> - +