🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Refactor EventsPage layout and improve EventList and OutboundLinksList components
Bill Yange9780e25a8bc
diff --git a/client/src/app/[site]/events/components/EventList.tsx b/client/src/app/[site]/events/components/EventList.tsxindex 6fbf47fb6..0dc8c44ff 100644--- a/client/src/app/[site]/events/components/EventList.tsx+++ b/client/src/app/[site]/events/components/EventList.tsx@@ -114,11 +114,14 @@ export function EventList({ events, isLoading, size = "small" }: EventListProps)// Find the total count to calculate percentagesconst totalCount = events.reduce((sum, event) => sum + event.count, 0);+ const maxCount = Math.max(...events.map(event => event.count));return (<div className="flex flex-col gap-2">{events.map(event => {+ const percentageOfMax = (event.count / maxCount) * 100;const percentage = (event.count / totalCount) * 100;+const isExpanded = expandedEvent === event.eventName;return (@@ -133,7 +136,7 @@ export function EventList({ events, isLoading, size = "small" }: EventListProps)><divclassName="absolute inset-0 bg-dataviz py-2 opacity-25 rounded-md"- style={{ width: `${percentage}%` }}+ style={{ width: `${percentageOfMax}%` }}></div><divclassName={cn(diff --git a/client/src/app/[site]/events/components/OutboundLinksList.tsx b/client/src/app/[site]/events/components/OutboundLinksList.tsxindex e1f26a997..e73599feb 100644--- a/client/src/app/[site]/events/components/OutboundLinksList.tsx+++ b/client/src/app/[site]/events/components/OutboundLinksList.tsx@@ -111,10 +111,12 @@ export function OutboundLinksList({ outboundLinks, isLoading, size = "small" }:// Find the total count to calculate percentagesconst totalCount = outboundLinks.reduce((sum, link) => sum + link.count, 0);+ const maxCount = Math.max(...outboundLinks.map(link => link.count));return (<div className="flex flex-col gap-2 overflow-y-auto max-h-[60vh] h-auto lg:h-full lg:min-h-0 lg:max-h-full">{outboundLinks.map((link, index) => {+ const percentageOfMax = (link.count / maxCount) * 100;const percentage = (link.count / totalCount) * 100;const lastClicked = DateTime.fromSQL(link.lastClicked, {zone: "utc",@@ -130,7 +132,7 @@ export function OutboundLinksList({ outboundLinks, isLoading, size = "small" }:><divclassName="absolute inset-0 bg-dataviz py-2 opacity-25 rounded-md"- style={{ width: `${percentage}%` }}+ style={{ width: `${percentageOfMax}%` }}></div><divclassName={cn("z-10 flex justify-between items-center w-full", size === "small" ? "text-xs" : "text-sm")}diff --git a/client/src/app/[site]/events/page.tsx b/client/src/app/[site]/events/page.tsxindex 0f10fb4aa..d71d90608 100644--- a/client/src/app/[site]/events/page.tsx+++ b/client/src/app/[site]/events/page.tsx@@ -3,50 +3,30 @@import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";import { EVENT_FILTERS } from "@/lib/store";import { useGetEventNames } from "../../../api/analytics/events/useGetEventNames";-import { useGetOutboundLinks } from "../../../api/analytics/events/useGetOutboundLinks";import { DisabledOverlay } from "../../../components/DisabledOverlay";import { useSetPageTitle } from "../../../hooks/useSetPageTitle";import { SubHeader } from "../components/SubHeader/SubHeader";import { EventList } from "./components/EventList";import { EventLog } from "./components/EventLog";-import { OutboundLinksList } from "./components/OutboundLinksList";export default function EventsPage() {useSetPageTitle("Rybbit · Events");const { data: eventNamesData, isLoading: isLoadingEventNames } = useGetEventNames();- const { data: outboundLinksData, isLoading: isLoadingOutboundLinks } = useGetOutboundLinks();return (<DisabledOverlay message="Events" featurePath="events"><div className="p-2 md:p-4 max-w-[1300px] mx-auto space-y-3"><SubHeader availableFilters={EVENT_FILTERS} />- <div className="grid grid-cols-1 lg:grid-cols-2 gap-3 items-stretch">- <Card className="h-auto lg:h-full">- <CardHeader>- <CardTitle>Custom Events</CardTitle>- </CardHeader>- <CardContent>- <EventList events={eventNamesData || []} isLoading={isLoadingEventNames} size="large" />- </CardContent>- </Card>-- <Card className="h-auto lg:h-full lg:min-h-0 flex flex-col overflow-hidden lg:[contain:size]">- <CardHeader>- <CardTitle>Outbound Clicks</CardTitle>- </CardHeader>- <CardContent className="lg:flex-1 lg:min-h-0 overflow-hidden p-0">- <div className="h-auto lg:h-full lg:min-h-0 p-4 pt-0">- <OutboundLinksList- outboundLinks={outboundLinksData || []}- isLoading={isLoadingOutboundLinks}- size="large"- />- </div>- </CardContent>- </Card>- </div>+ <Card className="h-auto lg:h-full">+ <CardHeader>+ <CardTitle>Custom Events</CardTitle>+ </CardHeader>+ <CardContent>+ <EventList events={eventNamesData || []} isLoading={isLoadingEventNames} size="large" />+ </CardContent>+ </Card><Card><CardHeader>