From 64a7e2ab26ebf88043b04ae0ac3f18aed5c2685f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Gerhard=20Lindesva=CC=88rd?= Date: Tue, 21 Jan 2025 15:21:24 +0000 Subject: [PATCH] improvements(dashboard): add headers to all overview tables to get a better understanding if its sessions or page views --- .../overview/overview-top-devices.tsx | 15 ++++++ .../overview-top-events.tsx | 2 +- .../components/overview/overview-top-geo.tsx | 3 ++ .../overview/overview-top-pages.tsx | 3 ++ .../overview/overview-top-sources.tsx | 25 ++++++++++ .../src/components/report-chart/bar/chart.tsx | 50 +++++++++++++++++-- .../src/components/report-chart/context.tsx | 1 + 7 files changed, 93 insertions(+), 6 deletions(-) diff --git a/apps/dashboard/src/components/overview/overview-top-devices.tsx b/apps/dashboard/src/components/overview/overview-top-devices.tsx index d05eef7a..7689b4f9 100644 --- a/apps/dashboard/src/components/overview/overview-top-devices.tsx +++ b/apps/dashboard/src/components/overview/overview-top-devices.tsx @@ -31,6 +31,9 @@ export default function OverviewTopDevices({ title: 'Top devices', btn: 'Devices', chart: { + options: { + columns: ['Device', isPageFilter ? 'Views' : 'Sessions'], + }, report: { limit: 10, projectId, @@ -64,6 +67,9 @@ export default function OverviewTopDevices({ title: 'Top browser', btn: 'Browser', chart: { + options: { + columns: ['Browser', isPageFilter ? 'Views' : 'Sessions'], + }, report: { limit: 10, projectId, @@ -98,6 +104,7 @@ export default function OverviewTopDevices({ btn: 'Browser Version', chart: { options: { + columns: ['Version', isPageFilter ? 'Views' : 'Sessions'], renderSerieName(name) { return name[1] || NOT_SET_VALUE; }, @@ -139,6 +146,9 @@ export default function OverviewTopDevices({ title: 'Top OS', btn: 'OS', chart: { + options: { + columns: ['OS', isPageFilter ? 'Views' : 'Sessions'], + }, report: { limit: 10, projectId, @@ -173,6 +183,7 @@ export default function OverviewTopDevices({ btn: 'OS Version', chart: { options: { + columns: ['Version', isPageFilter ? 'Views' : 'Sessions'], renderSerieName(name) { return name[1] || NOT_SET_VALUE; }, @@ -214,6 +225,9 @@ export default function OverviewTopDevices({ title: 'Top Brands', btn: 'Brands', chart: { + options: { + columns: ['Brand', isPageFilter ? 'Views' : 'Sessions'], + }, report: { limit: 10, projectId, @@ -248,6 +262,7 @@ export default function OverviewTopDevices({ btn: 'Models', chart: { options: { + columns: ['Model', isPageFilter ? 'Views' : 'Sessions'], renderSerieName(name) { return name[1] || NOT_SET_VALUE; }, diff --git a/apps/dashboard/src/components/overview/overview-top-events/overview-top-events.tsx b/apps/dashboard/src/components/overview/overview-top-events/overview-top-events.tsx index d291eb69..d44016ef 100644 --- a/apps/dashboard/src/components/overview/overview-top-events/overview-top-events.tsx +++ b/apps/dashboard/src/components/overview/overview-top-events/overview-top-events.tsx @@ -167,7 +167,7 @@ export default function OverviewTopEvents({ name[0] === NOT_SET_VALUE ? 'Direct / Not set' : name[0], onClick: (item) => { diff --git a/apps/dashboard/src/components/report-chart/bar/chart.tsx b/apps/dashboard/src/components/report-chart/bar/chart.tsx index 4a4f7392..7c020651 100644 --- a/apps/dashboard/src/components/report-chart/bar/chart.tsx +++ b/apps/dashboard/src/components/report-chart/bar/chart.tsx @@ -10,7 +10,7 @@ import { useNumber } from '@/hooks/useNumerFormatter'; import type { IChartData } from '@/trpc/client'; import { cn } from '@/utils/cn'; import { DropdownMenuPortal } from '@radix-ui/react-dropdown-menu'; -import { useMemo } from 'react'; +import { useMemo, useState } from 'react'; import { round } from '@openpanel/common'; import { NOT_SET_VALUE } from '@openpanel/constants'; @@ -25,10 +25,11 @@ interface Props { } export function Chart({ data }: Props) { + const [isOpen, setOpen] = useState(null); const { isEditMode, report: { metric, limit }, - options: { onClick, dropdownMenuContent }, + options: { onClick, dropdownMenuContent, columns }, } = useReportChartContext(); const number = useNumber(); const series = useMemo( @@ -44,6 +45,24 @@ export function Chart({ data }: Props) { isEditMode ? 'card gap-2 p-4 text-base' : '-m-3 gap-1', )} > + {columns && columns.length > 0 && ( +
+ {columns.map((column, index) => { + const isLast = columns.length - 1 <= index; + return ( +
+ {column} +
+ ); + })} +
+ )} {series.map((serie) => { const isClickable = !serie.names.includes(NOT_SET_VALUE) && onClick; const isDropDownEnabled = @@ -51,15 +70,36 @@ export function Chart({ data }: Props) { (dropdownMenuContent?.(serie) || []).length > 0; return ( - - + + setOpen((p) => (p === serie.id ? null : serie.id)) + } + open={isOpen === serie.id} + > + e.preventDefault(), + onClick: () => setOpen(serie.id), + } + : {})} + >
onClick?.(serie) } + ? { + onClick: () => onClick(serie), + } : {})} >