🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Enhance StandardSectionDialog and PerformanceTable for improved UI consistency
Bill Yang648200a1be4e
diff --git a/client/src/app/[site]/components/shared/StandardSection/StandardSectionDialog.tsx b/client/src/app/[site]/components/shared/StandardSection/StandardSectionDialog.tsxindex b4b0b5637..9f60fc2fa 100644--- a/client/src/app/[site]/components/shared/StandardSection/StandardSectionDialog.tsx+++ b/client/src/app/[site]/components/shared/StandardSection/StandardSectionDialog.tsx@@ -1,5 +1,14 @@import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";import { Input } from "@/components/ui/input";+import {+ Table,+ TableBody,+ TableCell,+ TableHead,+ TableHeader,+ TableRow,+ TableSortIndicator,+} from "@/components/ui/table";import {createColumnHelper,flexRender,@@ -9,7 +18,7 @@ import {useReactTable,} from "@tanstack/react-table";import { useDebounce, useIntersectionObserver } from "@uidotdev/usehooks";-import { ChevronDown, ChevronUp, Loader2, Search, SquareArrowOutUpRight } from "lucide-react";+import { Loader2, Search, SquareArrowOutUpRight } from "lucide-react";import { ReactNode, useEffect, useMemo, useState } from "react";import { useInfiniteMetric } from "../../../../../api/analytics/useGetMetric";import { MetricResponse } from "../../../../../api/analytics/useGetMetric";@@ -201,99 +210,93 @@ export function StandardSectionDialog({return (<Dialog open={expanded} onOpenChange={close}>- <DialogContent className="max-w-[1000px] w-[calc(100vw-2rem)] p-2 sm:p-4">+ <DialogContent className="max-w-[1000px] w-[100vw] max-h-[1000px] h-[calc(100vh-2rem)] p-2 sm:p-4 flex flex-col gap-2"><DialogHeader><DialogTitle>{title}</DialogTitle></DialogHeader>- <div className="relative">- <Search className="absolute left-2.5 top-2.5 h-4 w-4 text-neutral-600 dark:text-neutral-400" />- <Input- type="text"- placeholder={`Filter ${allItems.length} items...`}- className="pl-9 bg-white dark:bg-neutral-900 border-neutral-200 dark:border-neutral-700 text-xs"- value={searchTerm}- onChange={e => setSearchTerm(e.target.value)}- />- </div>- <div className="flex flex-col gap-2 overflow-x-auto">- <div className="max-h-[80vh] overflow-y-auto">- <table className="w-full text-xs text-left min-w-max">- <thead className="bg-neutral-100 dark:bg-neutral-900 text-neutral-600 dark:text-neutral-400 sticky top-0 z-10">- {table.getHeaderGroups().map(headerGroup => (- <tr key={headerGroup.id}>- {headerGroup.headers.map((header, index) => (- <th- key={header.id}- scope="col"+ <Input+ type="text"+ placeholder={`Filter ${allItems.length} items...`}+ className="bg-white dark:bg-neutral-900 border-neutral-200 dark:border-neutral-700 text-xs"+ value={searchTerm}+ inputSize="sm"+ onChange={e => setSearchTerm(e.target.value)}+ />+ <div className="max-h-[85vh] overflow-auto relative overflow-x-auto">+ <table className="w-full text-xs text-left min-w-max">+ <thead className="sticky top-0 z-10 bg-neutral-100 dark:bg-neutral-850 [&_tr]:border-b-0">+ {table.getHeaderGroups().map(headerGroup => (+ <tr key={headerGroup.id} className="border-b-0">+ {headerGroup.headers.map((header, index) => (+ <th+ key={header.id}+ className={cn(+ "h-8 px-2 text-left align-middle font-medium text-neutral-500 dark:text-neutral-400 first:rounded-l-lg last:rounded-r-lg",+ "font-medium whitespace-nowrap cursor-pointer select-none",+ index === 0 ? "text-left" : "text-right"+ )}+ style={{+ minWidth: header.id === "user_id" ? "100px" : "auto",+ }}+ onClick={header.column.getToggleSortingHandler()}+ >+ <div className={cn("flex items-center gap-1", index !== 0 && "justify-end")}>+ {header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}+ <TableSortIndicator sortDirection={header.column.getIsSorted()} />+ </div>+ </th>+ ))}+ </tr>+ ))}+ </thead>+ <tbody className="[&_tr:last-child]:border-0 bg-white dark:bg-neutral-900">+ {table.getRowModel().rows.map(row => {+ return (+ <tr+ key={row.id}+ className="border-b border-b-neutral-100 transition-colors hover:bg-neutral-100/50 dark:border-b-neutral-800 dark:hover:bg-neutral-800/20 cursor-pointer group"+ onClick={() =>+ addFilter({+ parameter: filterParameter,+ value: [getValue(row.original)],+ type: "equals",+ })+ }+ >+ {row.getVisibleCells().map((cell, cellIndex) => (+ <td+ key={cell.id}className={cn(- "px-2 py-1 font-medium whitespace-nowrap cursor-pointer select-none",- index === 0 ? "text-left" : "text-right"+ "p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",+ "relative",+ cellIndex !== 0 && "text-right")}- style={{- minWidth: header.id === "user_id" ? "100px" : "auto",- }}- onClick={header.column.getToggleSortingHandler()}>- <div className={cn("flex items-center gap-1", index !== 0 && "justify-end")}>- {header.isPlaceholder- ? null- : flexRender(header.column.columnDef.header, header.getContext())}- {{- asc: <ChevronUp className="h-3 w-3" />,- desc: <ChevronDown className="h-3 w-3" />,- }[header.column.getIsSorted() as string] ?? null}- </div>- </th>+ <span className="relative z-0">+ {flexRender(cell.column.columnDef.cell, cell.getContext())}+ </span>+ </td>))}</tr>- ))}- </thead>- <tbody>- {table.getRowModel().rows.map((row, rowIndex) => {- return (- <tr- key={row.id}- className={cn(- "border-b border-neutral-300 dark:border-neutral-800 hover:bg-neutral-150 dark:hover:bg-neutral-850 cursor-pointer group",- rowIndex % 2 === 0 ? "bg-white dark:bg-neutral-900" : "bg-neutral-50 dark:bg-neutral-950"- )}- onClick={() =>- addFilter({- parameter: filterParameter,- value: [getValue(row.original)],- type: "equals",- })- }- >- {row.getVisibleCells().map((cell, cellIndex) => (- <td key={cell.id} className={cn("px-2 py-2 relative", cellIndex !== 0 && "text-right")}>- {cellIndex === 0 && <div></div>}- <span className="relative z-0">- {flexRender(cell.column.columnDef.cell, cell.getContext())}- </span>- </td>- ))}- </tr>- );- })}- </tbody>- </table>+ );+ })}+ </tbody>+ </table>- {/* Infinite scroll loading indicator and observer anchor */}- {filteredData.length > 0 && (- <div ref={ref} className="py-4 flex justify-center">- {isFetchingNextPage && (- <div className="flex items-center gap-2 text-neutral-600 dark:text-neutral-400 text-xs">- <Loader2 className="h-4 w-4 animate-spin" />- Loading more...- </div>- )}- {!hasNextPage && !isFetchingNextPage && (- <div className="text-neutral-500 dark:text-neutral-500 text-xs">All items loaded</div>- )}- </div>- )}- </div>+ {/* Infinite scroll loading indicator and observer anchor */}+ {filteredData.length > 0 && (+ <div ref={ref} className="py-4 flex justify-center">+ {isFetchingNextPage && (+ <div className="flex items-center gap-2 text-neutral-600 dark:text-neutral-400 text-xs">+ <Loader2 className="h-4 w-4 animate-spin" />+ Loading more...+ </div>+ )}+ {!hasNextPage && !isFetchingNextPage && (+ <div className="text-neutral-500 dark:text-neutral-500 text-xs">All items loaded</div>+ )}+ </div>+ )}</div></DialogContent></Dialog>diff --git a/client/src/app/[site]/performance/components/PerformanceTable.tsx b/client/src/app/[site]/performance/components/PerformanceTable.tsxindex 275977ca9..15fe5a85a 100644--- a/client/src/app/[site]/performance/components/PerformanceTable.tsx+++ b/client/src/app/[site]/performance/components/PerformanceTable.tsx@@ -1,7 +1,7 @@"use client";import { Skeleton } from "@/components/ui/skeleton";-import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";+import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, TableSortIndicator } from "@/components/ui/table";import {createColumnHelper,flexRender,@@ -11,9 +11,6 @@ import {useReactTable,} from "@tanstack/react-table";import {- ChevronDown,- ChevronsUpDown,- ChevronUp,Monitor,Smartphone,Tablet,@@ -388,17 +385,10 @@ export function PerformanceTable({ dimension, title }: PerformanceTableProps) {><div className="flex items-center gap-1">{flexRender(header.column.columnDef.header, header.getContext())}- {header.column.getCanSort() && (- <div className="flex flex-col">- {header.column.getIsSorted() === "asc" ? (- <ChevronUp className="h-3 w-3 text-blue-400" />- ) : header.column.getIsSorted() === "desc" ? (- <ChevronDown className="h-3 w-3 text-blue-400" />- ) : (- <ChevronsUpDown className="h-3 w-3 text-neutral-400" />- )}- </div>- )}+ <TableSortIndicator+ sortDirection={header.column.getIsSorted()}+ canSort={header.column.getCanSort()}+ /></div></TableHead>))}diff --git a/client/src/components/ui/dialog.tsx b/client/src/components/ui/dialog.tsxindex fa7f74a63..6a19ffcd9 100644--- a/client/src/components/ui/dialog.tsx+++ b/client/src/components/ui/dialog.tsx@@ -38,7 +38,7 @@ const DialogContent = React.forwardRef<<DialogPrimitive.Contentref={ref}className={cn(- "fixed left-[50%] top-[50%] z-50 grid w-full translate-x-[-50%] translate-y-[-50%] gap-4 border border-neutral-150 bg-white p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg dark:border-neutral-800 dark:bg-neutral-950",+ "fixed left-[50%] top-[50%] z-50 grid w-full translate-x-[-50%] translate-y-[-50%] gap-4 border border-neutral-150 bg-white p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] rounded-lg dark:border-neutral-800 dark:bg-neutral-950",className)}{...props}diff --git a/client/src/components/ui/table.tsx b/client/src/components/ui/table.tsxindex 2677632c6..e8ed2099c 100644--- a/client/src/components/ui/table.tsx+++ b/client/src/components/ui/table.tsx@@ -1,4 +1,5 @@import * as React from "react";+import { ChevronDown, ChevronsUpDown, ChevronUp } from "lucide-react";import { cn } from "@/lib/utils";@@ -82,4 +83,29 @@ const TableCaption = React.forwardRef<HTMLTableCaptionElement, React.HTMLAttribu);TableCaption.displayName = "TableCaption";-export { Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption };+interface TableSortIndicatorProps {+ /** The current sort direction: 'asc', 'desc', or false/undefined for unsorted */+ sortDirection?: false | "asc" | "desc";+ /** Whether sorting is enabled for this column */+ canSort?: boolean;+ className?: string;+}++const TableSortIndicator = ({ sortDirection, canSort = true, className }: TableSortIndicatorProps) => {+ if (!canSort) return null;++ return (+ <div className={cn("flex flex-col", className)}>+ {sortDirection === "asc" ? (+ <ChevronUp className="h-3 w-3 text-blue-400" />+ ) : sortDirection === "desc" ? (+ <ChevronDown className="h-3 w-3 text-blue-400" />+ ) : (+ <ChevronsUpDown className="h-3 w-3 text-neutral-400" />+ )}+ </div>+ );+};+TableSortIndicator.displayName = "TableSortIndicator";++export { Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption, TableSortIndicator };