fix: align table headers with row data using CSS grid

- Switch FrustrationTable from flex to grid columns so headers
  and row cells share the same column widths
- Replace bar chart with pie chart for frustration trend
- Remove Card wrapper borders, footer line, and total signals text
- Change dead clicks color from yellow to darker orange
This commit is contained in:
Usman Baig
2026-03-12 18:16:12 +01:00
parent 0889079372
commit d4dc45e82b
2 changed files with 53 additions and 64 deletions

View File

@@ -65,6 +65,9 @@ function SelectorCell({ selector }: { selector: string }) {
)
}
const GRID_WITH_AVG = 'grid grid-cols-[1fr_60px_50px_64px_64px_40px] items-center gap-2 h-9 px-2 -mx-2'
const GRID_NO_AVG = 'grid grid-cols-[1fr_60px_64px_64px_40px] items-center gap-2 h-9 px-2 -mx-2'
function Row({
item,
showAvgClicks,
@@ -73,32 +76,30 @@ function Row({
showAvgClicks?: boolean
}) {
return (
<div className="flex items-center justify-between h-9 group hover:bg-neutral-50 dark:hover:bg-neutral-800 rounded-lg px-2 -mx-2 transition-colors">
<div className="flex items-center gap-3 flex-1 min-w-0">
<div className={`${showAvgClicks ? GRID_WITH_AVG : GRID_NO_AVG} group hover:bg-neutral-50 dark:hover:bg-neutral-800 rounded-lg transition-colors`}>
<div className="flex items-center gap-2 min-w-0">
<SelectorCell selector={item.selector} />
<span
className="text-xs text-neutral-400 dark:text-neutral-500 truncate max-w-[120px]"
className="text-xs text-neutral-400 dark:text-neutral-500 truncate"
title={item.page_path}
>
{item.page_path}
</span>
</div>
<div className="flex items-center gap-4 ml-4 shrink-0">
{showAvgClicks && item.avg_click_count != null && (
<span className="text-xs text-neutral-400 dark:text-neutral-500 tabular-nums">
avg {item.avg_click_count.toFixed(1)}
</span>
)}
<span className="text-xs text-neutral-400 dark:text-neutral-500 tabular-nums">
{item.sessions} {item.sessions === 1 ? 'session' : 'sessions'}
{showAvgClicks && (
<span className="text-xs text-neutral-400 dark:text-neutral-500 tabular-nums text-right">
{item.avg_click_count != null ? item.avg_click_count.toFixed(1) : ''}
</span>
<span className="text-xs text-neutral-400 dark:text-neutral-500 tabular-nums" title={item.last_seen}>
{formatRelativeTime(item.last_seen)}
</span>
<span className="text-sm font-semibold text-neutral-600 dark:text-neutral-400 tabular-nums">
{formatNumber(item.count)}
</span>
</div>
)}
<span className="text-xs text-neutral-400 dark:text-neutral-500 tabular-nums text-right">
{item.sessions}
</span>
<span className="text-xs text-neutral-400 dark:text-neutral-500 tabular-nums text-right" title={item.last_seen}>
{formatRelativeTime(item.last_seen)}
</span>
<span className="text-sm font-semibold text-neutral-600 dark:text-neutral-400 tabular-nums text-right">
{formatNumber(item.count)}
</span>
</div>
)
}
@@ -166,17 +167,12 @@ export default function FrustrationTable({
) : hasData ? (
<div>
{/* Column headers */}
<div className="flex items-center justify-between px-2 -mx-2 mb-2 text-xs font-medium text-neutral-400 dark:text-neutral-500 uppercase tracking-wider">
<div className="flex items-center gap-3">
<span>Selector</span>
<span>Page</span>
</div>
<div className="flex items-center gap-4">
{showAvgClicks && <span>Avg</span>}
<span>Sessions</span>
<span>Last Seen</span>
<span>Count</span>
</div>
<div className={`${showAvgClicks ? GRID_WITH_AVG : GRID_NO_AVG} mb-2 text-xs font-medium text-neutral-400 dark:text-neutral-500 uppercase tracking-wider !h-auto`}>
<span>Selector / Page</span>
{showAvgClicks && <span className="text-right">Avg</span>}
<span className="text-right">Sessions</span>
<span className="text-right">Last Seen</span>
<span className="text-right">Count</span>
</div>
<div className="space-y-0.5">
{items.map((item, i) => (

View File

@@ -3,14 +3,6 @@
import { TrendUp } from '@phosphor-icons/react'
import { Pie, PieChart } from 'recharts'
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from '@/components/ui/card'
import {
ChartContainer,
ChartTooltip,
@@ -48,7 +40,7 @@ const chartConfig = {
},
dead_clicks: {
label: 'Dead Clicks',
color: '#F59E0B',
color: '#E04E0A',
},
prev_rage_clicks: {
label: 'Prev Rage Clicks',
@@ -106,12 +98,17 @@ export default function FrustrationTrend({ summary, loading }: FrustrationTrendP
}
return (
<Card className="flex flex-col h-full">
<CardHeader className="items-center pb-0">
<CardTitle>Frustration Trend</CardTitle>
<CardDescription>Current vs. previous period</CardDescription>
</CardHeader>
<CardContent className="flex-1 pb-0">
<div className="bg-white dark:bg-neutral-900 border border-neutral-200 dark:border-neutral-800 rounded-2xl p-6 h-full flex flex-col">
<div className="flex items-center justify-between mb-1">
<h3 className="text-lg font-semibold text-neutral-900 dark:text-white">
Frustration Trend
</h3>
</div>
<p className="text-sm text-neutral-500 dark:text-neutral-400 mb-4">
Rage and dead clicks split across current and previous period
</p>
<div className="flex-1">
<ChartContainer
config={chartConfig}
className="mx-auto aspect-square max-h-[250px]"
@@ -129,25 +126,21 @@ export default function FrustrationTrend({ summary, loading }: FrustrationTrendP
/>
</PieChart>
</ChartContainer>
</CardContent>
<CardFooter className="flex-col gap-2 text-sm">
<div className="flex items-center gap-2 leading-none font-medium">
{totalChange !== null ? (
<>
{totalChange > 0 ? 'Up' : totalChange < 0 ? 'Down' : 'No change'} by {Math.abs(totalChange)}% vs previous period <TrendUp className="h-4 w-4" />
</>
) : totalCurrent > 0 ? (
<>
{totalCurrent.toLocaleString()} new signals this period <TrendUp className="h-4 w-4" />
</>
) : (
'No frustration signals detected'
)}
</div>
<div className="leading-none text-muted-foreground">
{totalCurrent.toLocaleString()} total signals in current period
</div>
</CardFooter>
</Card>
</div>
<div className="flex items-center justify-center gap-2 text-sm font-medium pt-2">
{totalChange !== null ? (
<>
{totalChange > 0 ? 'Up' : totalChange < 0 ? 'Down' : 'No change'} by {Math.abs(totalChange)}% vs previous period <TrendUp className="h-4 w-4" />
</>
) : totalCurrent > 0 ? (
<>
{totalCurrent.toLocaleString()} new signals this period <TrendUp className="h-4 w-4" />
</>
) : (
'No frustration signals detected'
)}
</div>
</div>
)
}