OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.
fix: improve project cards #330
Carl-Gerhard Lindesvärd60f126d09ac7
diff --git a/apps/start/src/components/projects/project-card.tsx b/apps/start/src/components/projects/project-card.tsxindex ca9df0f24..a8b026bd6 100644--- a/apps/start/src/components/projects/project-card.tsx+++ b/apps/start/src/components/projects/project-card.tsx@@ -92,11 +92,11 @@ function ProjectChartOuter({ id }: { id: string }) {);}-function Metric({ value, label }: { value: React.ReactNode; label: string }) {+function Metric({ value, label, className }: { value: React.ReactNode; label: string; className?: string }) {return (- <div className="flex flex-col gap-2 md:flex-row items-center">- <div className="text-muted-foreground text-xs">{label}</div>- <span className="font-semibold">{value}</span>+ <div className={cn("flex flex-col gap-1 md:flex-row items-center text-sm", className)}>+ <div className="text-muted-foreground">{label}</div>+ <span className="font-medium whitespace-nowrap">{value}</span></div>);}@@ -111,8 +111,7 @@ function ProjectMetrics({ id }: { id: string }) {);return (- <FadeIn className="flex gap-8 flex-1">- <div className="flex-1 items-center gap-2 row">+ <FadeIn className="row flex-wrap gap-3 flex-1">{typeof data?.trend?.percentage === 'number' && (<Metriclabel="3M DIFF"@@ -147,10 +146,9 @@ function ProjectMetrics({ id }: { id: string }) {})}/>)}- </div>- <Metric label="3M" value={number.short(data?.metrics?.months_3 ?? 0)} />- <Metric label="30D" value={number.short(data?.metrics?.month ?? 0)} />- <Metric label="24H" value={number.short(data?.metrics?.day ?? 0)} />+ <Metric label="3M" value={number.short(data?.metrics?.months_3 ?? 0)} className="ml-auto" />+ <Metric label="30D" value={number.short(data?.metrics?.month ?? 0)} />+ <Metric label="24H" value={number.short(data?.metrics?.day ?? 0)} /></FadeIn>);}diff --git a/apps/start/src/components/projects/project-chart.tsx b/apps/start/src/components/projects/project-chart.tsxindex 26985bb96..2925ceb64 100644--- a/apps/start/src/components/projects/project-chart.tsx+++ b/apps/start/src/components/projects/project-chart.tsx@@ -16,6 +16,7 @@ import {XAxis,YAxis,} from 'recharts';+import { useYAxisProps } from '../report-chart/common/axis';type ChartDataItem = {value: number;@@ -94,7 +95,10 @@ export function ProjectChart({data: { value: number; date: Date; revenue: number }[];}) {const [activeBar, setActiveBar] = useState(-1);-++ const yAxisProps = useYAxisProps({+ width: 30,+ });if (data.length === 0) {return null;}@@ -114,13 +118,39 @@ export function ProjectChart({return getChartColor(0);};+ if (maxValue === 0) {+ return (+ <div className="relative h-full w-full pl-3">++ <div className="pointer-events-none absolute inset-x-3 bottom-2 h-12">+ <div className="flex h-full items-end gap-1.5 opacity-35">+ {[28, 42, 35, 50, 40, 56, 45, 60, 49, 32,98,29,49,69,49,20, 28, 42, 35, 50, 40, 56, 45, 60, 49, 32,98,29,49,69,49,20].map((height, index) => (+ <div+ key={index}+ className="flex-1 rounded-full bg-foreground/20"+ style={{ height: `${height}%` }}+ />+ ))}+ </div>+ </div>++ <div className="absolute inset-0 flex flex-col items-center justify-center gap-1 px-4 text-center">+ <p className="text-sm font-medium text-foreground/85">No activity yet</p>+ <p className="text-xs text-muted-foreground">+ Sessions will show up here once tracking starts.+ </p>+ </div>+ </div>+ );+ }+return (- <div className="relative h-full w-full">+ <div className="relative h-full w-full pl-3"><TooltipProvider color={color}><ResponsiveContainer width="100%" height="100%"><ComposedChartdata={chartData}- margin={{ top: 10, right: 10, bottom: 10, left: 10 }}+ margin={{ top: 10, right: 10, bottom: 10, left: 0 }}onMouseMove={(e) => {setActiveBar(e.activeTooltipIndex ?? -1);}}@@ -132,7 +162,11 @@ export function ProjectChart({domain={['dataMin', 'dataMax']}hide/>- <YAxis domain={[0, maxValue || 'dataMax']} hide width={0} />+ <YAxis+ {...yAxisProps}+ domain={[0, maxValue || 'dataMax']}+ allowDecimals={false}+ /><YAxisyAxisId="right"orientation="right"@@ -212,4 +246,4 @@ export function ProjectChart({</TooltipProvider></div>);-}+}\ No newline at end of filediff --git a/apps/start/src/components/report-chart/common/axis.tsx b/apps/start/src/components/report-chart/common/axis.tsxindex 2d3ac4de3..2b25782b6 100644--- a/apps/start/src/components/report-chart/common/axis.tsx+++ b/apps/start/src/components/report-chart/common/axis.tsx@@ -24,8 +24,9 @@ export function getYAxisWidth(value: string | undefined | null) {export const useYAxisProps = (options?: {hide?: boolean;tickFormatter?: (value: number) => string;+ width?: number;}) => {- const [width, setWidth] = useState(24);+ const [width, setWidth] = useState(options?.width || 24);const setWidthDebounced = useDebounceFn(setWidth, 100);const number = useNumber();const ref = useRef<number[]>([]);@@ -40,9 +41,11 @@ export const useYAxisProps = (options?: {const tick = options?.tickFormatter? options.tickFormatter(value): number.short(value);- const newWidth = getYAxisWidth(tick);- ref.current.push(newWidth);- setWidthDebounced(Math.max(...ref.current));+ if(!options?.width) {+ const newWidth = getYAxisWidth(tick);+ ref.current.push(newWidth);+ setWidthDebounced(Math.max(...ref.current));+ }return tick;},};diff --git a/packages/trpc/src/routers/chart.ts b/packages/trpc/src/routers/chart.tsindex 6699c7ff0..8bad8e55f 100644--- a/packages/trpc/src/routers/chart.ts+++ b/packages/trpc/src/routers/chart.ts@@ -147,7 +147,7 @@ export const chartRouter = createTRPCRouter({created_at >= now() - interval '3 month'GROUP BY dateORDER BY date ASC- WITH FILL FROM toStartOfDay(now() - interval '1 month')+ WITH FILL FROM toStartOfDay(now() - interval '3 month')TO toStartOfDay(now())STEP INTERVAL 1 daySETTINGS session_timezone = '${timezone}'