From 344f37719e4dcb626218911c3ab4a2c537b2faa1 Mon Sep 17 00:00:00 2001 From: "santasri.pachhal" Date: Wed, 18 Mar 2026 01:03:58 +0530 Subject: [PATCH] refactor: redesign table module --- src/app/(modules)/dashboard/page.tsx | 79 ++--- src/app/(modules)/layout.tsx | 20 +- src/app/(modules)/location/page.tsx | 120 +++++-- src/app/(modules)/package/page.tsx | 104 +++--- src/app/(modules)/project/page.tsx | 113 +++--- src/app/favicon.ico | Bin 0 -> 25931 bytes src/app/globals.css | 23 ++ src/app/layout.tsx | 2 + src/components/app-breadcrumb.tsx | 57 +++ src/components/app-sidebar.tsx | 1 - .../dashboard/detection-donut-chart.tsx | 285 ++++++++------- .../dashboard/location-bar-chart.tsx | 254 +++++--------- src/components/dashboard/stats-card.tsx | 2 +- src/components/data-table/Footer/index.tsx | 113 +++--- .../data-table/Header/SearchBar.tsx | 18 +- src/components/data-table/Header/index.tsx | 68 ++-- src/components/data-table/TableHeader.tsx | 51 +-- src/components/data-table/index.tsx | 327 +++++++++--------- src/components/page-header.tsx | 34 +- src/components/ui/badge.tsx | 32 +- src/components/ui/breadcrumb.tsx | 10 +- src/components/ui/popover.tsx | 57 ++- src/components/ui/scroll-area.tsx | 28 +- src/components/ui/table.tsx | 8 +- 24 files changed, 991 insertions(+), 815 deletions(-) create mode 100644 src/app/favicon.ico create mode 100644 src/components/app-breadcrumb.tsx diff --git a/src/app/(modules)/dashboard/page.tsx b/src/app/(modules)/dashboard/page.tsx index 55513dc..8971f56 100644 --- a/src/app/(modules)/dashboard/page.tsx +++ b/src/app/(modules)/dashboard/page.tsx @@ -1,7 +1,7 @@ "use client"; import { useState, useEffect } from "react"; -import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; +import { Card, CardContent, CardHeader, CardTitle, CardDescription, CardFooter } from "@/components/ui/card"; import { AlertCircle, Activity, @@ -11,6 +11,7 @@ import { Zap, PencilLine, CheckCircle2, + Settings2, } from "lucide-react"; import { StatsCard } from "@/components/dashboard/stats-card"; import { CompactProjectSelector } from "@/components/dashboard/compact-project-selector"; @@ -26,9 +27,9 @@ import { PopoverTrigger, } from "@/components/ui/popover"; import { Button } from "@/components/ui/button"; -import { Filter } from "lucide-react"; import { DashboardSkeleton } from "@/components/dashboard/dashboard-skeleton" import { PoweredBy } from "@/components/powered-by"; +import { toast } from "sonner"; const API_URL = process.env.NEXT_PUBLIC_API_URL; @@ -207,14 +208,12 @@ export default function DashboardPage() { totalRoadDamage: 0, locationData: [], }); - const [error, setError] = useState(null); // Load projects on mount useEffect(() => { const loadProjects = async () => { try { setIsLoading(true); - setError(null); const projectsData = await fetchProjects(); setProjects(projectsData); @@ -223,9 +222,9 @@ export default function DashboardPage() { } } catch (err) { console.error("Failed to load projects:", err); - setError( - "Failed to load projects. Please check if the backend is running.", - ); + toast.error("Failed to load projects", { + description: "Please check if the backend is running." + }); } finally { setTimeout(() => { setIsLoading(false); @@ -274,7 +273,6 @@ export default function DashboardPage() { const loadProjectSummary = async () => { try { setIsLoading(true); - setError(null); const response = await fetch( `${API_URL}/summary/projects/${selectedProjectId}`, @@ -294,7 +292,7 @@ export default function DashboardPage() { setProjectSummary(summary); } catch (err) { console.error("Failed to load project summary:", err); - setError("Failed to load project summary."); + toast.error("Failed to load project summary"); setProjectSummary(null); } finally { setTimeout(() => { @@ -422,10 +420,10 @@ export default function DashboardPage() { }, [projectSummary, selectedPackageId, selectedLocationId]); return ( -
+ <> {/* Main Content */} -
-
+
+
{/* Header */}

- + Filter Analysis

Refine your view by project, package, or location

@@ -467,14 +465,6 @@ export default function DashboardPage() {
- {/* Error Display */} - {error && ( -
- -

{error}

-
- )} - {isLoading && !projectSummary ? ( ) : ( @@ -522,18 +512,12 @@ export default function DashboardPage() { {/* Charts Row - Side by Side */}
{/* Left Chart - Detection Distribution */} - - - -
- -
- - Detection Distribution - -
+ + + Detection Distribution + Breakdown of all detected road conditions - + + +
+ Total detections: {stats.totalRoadDamage + stats.totalGoodSignboard} +
+
- {/* Right Chart - Location Bar Chart */} - - - -
- -
- Detections by Location -
+ {/* Right Chart - Detections by Location */} + + + Detections by Location + Frequency of road issues across different map segments - + ({ name: loc.name, @@ -562,11 +547,15 @@ export default function DashboardPage() { pothole: loc.pothole, road_crack: loc.road_crack, damaged_road_marking: loc.damaged_road_marking, - good_sign_board: loc.good_sign_board, total: loc.total, }))} /> + +
+ Analysis based on latest processed sequence +
+
@@ -585,6 +574,6 @@ export default function DashboardPage() {
-
+ ); } diff --git a/src/app/(modules)/layout.tsx b/src/app/(modules)/layout.tsx index ffa8540..e2d13cd 100644 --- a/src/app/(modules)/layout.tsx +++ b/src/app/(modules)/layout.tsx @@ -1,6 +1,8 @@ +import { BreadcrumbBasic } from "@/components/app-breadcrumb"; import { AppSidebar } from "@/components/app-sidebar"; import { ModeToggle } from "@/components/mode-toogle"; import { SidebarProvider, SidebarTrigger } from "@/components/ui/sidebar"; +import { Separator } from "@/components/ui/separator"; import React from "react"; const ModulesLayout = ({ @@ -11,15 +13,23 @@ const ModulesLayout = ({ return ( -
-
- - +
+
+ {/* Centering container wrapper */} +
+
+ + + + +
+
{children}
+
-
{children}
); }; + export default ModulesLayout; diff --git a/src/app/(modules)/location/page.tsx b/src/app/(modules)/location/page.tsx index b4a57c8..3b0df0f 100644 --- a/src/app/(modules)/location/page.tsx +++ b/src/app/(modules)/location/page.tsx @@ -27,6 +27,8 @@ import { } from "@/lib/api" import { ColumnDef } from "@tanstack/react-table" import { toast } from "sonner" +import { Badge } from "@/components/ui/badge" +import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover" export default function LocationPage() { const [locations, setLocations] = useState([]) @@ -168,7 +170,9 @@ export default function LocationPage() { end_lng: parseFloat(endLng), } await updateLocation(currentLocation.id, data) - toast.success("Location updated successfully!") + toast.success("Location Updated", { + description: `${segmentName} has been updated successfully at ${new Date().toLocaleTimeString()}`, + }) } else { const data: LocationCreate = { package_id: selectedPackageId, @@ -181,7 +185,9 @@ export default function LocationPage() { end_lng: parseFloat(endLng), } await createLocation(data) - toast.success("Location created successfully!") + toast.success("Location Created", { + description: `${segmentName} has been established successfully at ${new Date().toLocaleTimeString()}`, + }) } // Refresh locations list @@ -191,7 +197,11 @@ export default function LocationPage() { setIsModalOpen(false) resetForm() } catch (err) { - setError(err instanceof Error ? err.message : `Failed to ${isEditing ? 'update' : 'create'} location`) + const message = err instanceof Error ? err.message : `Failed to ${isEditing ? 'update' : 'create'} location` + setError(message) + toast.error("Operation Failed", { + description: message, + }) } finally { setIsSubmitting(false) } @@ -224,10 +234,15 @@ export default function LocationPage() { try { setIsLoading(true) await deleteLocation(location.id) - toast.success("Location deleted successfully!") + toast.success("Location Deleted", { + description: `${location.segment_name} has been removed from the system.`, + }) await loadLocations() } catch (err) { setError("Failed to delete location") + toast.error("Deletion Failed", { + description: "The location could not be removed. Please try again.", + }) } finally { setIsLoading(false) } @@ -262,6 +277,50 @@ export default function LocationPage() { return project?.name || "—" } }, + { + id: "project_state", + header: "Project State", + cell: ({ row }) => { + const location = row.original + const pkg = allPackages.find(p => p.id === location.package_id) + const project = projects.find(p => p.id === pkg?.project_id) + if (!project?.state) return + + const states = project.state.split(',').map(s => s.trim()).filter(Boolean) + if (states.length === 0) return + + const firstState = states[0] + const remainingStates = states.slice(1) + + return ( +
+ + {firstState} + + + {remainingStates.length > 0 && ( + + + + + +
+

Other States

+ {remainingStates.map((item, idx) => ( + + {item} + + ))} +
+
+
+ )} +
+ ) + } + }, { accessorKey: "chainage", header: "Chainage (km)", @@ -269,9 +328,10 @@ export default function LocationPage() { const location = row.original if (location.chainage_start_km !== null && location.chainage_end_km !== null) { return ( - + + {location.chainage_start_km} - {location.chainage_end_km} - + ) } return "—" @@ -281,44 +341,44 @@ export default function LocationPage() { accessorKey: "start_gps", header: "Start GPS", cell: ({ row }) => ( - + + {row.original.start_lat.toFixed(4)}, {row.original.start_lng.toFixed(4)} - + ) }, { accessorKey: "end_gps", header: "End GPS", cell: ({ row }) => ( - + + {row.original.end_lat.toFixed(4)}, {row.original.end_lng.toFixed(4)} - + ) }, ] return ( -
-
-
+ <> +
{/* Refined Header */}
{ setIsEditing(false); setIsModalOpen(true); }} + > + + Add New Location + + } />
- {/* Error Message */} - {error && !isModalOpen && ( -
-
- ! -
-

{error}

-
- )} {/* Data Table */}
@@ -326,10 +386,8 @@ export default function LocationPage() { title="Locations" data={locations} columns={columns} - onAddNew={() => { setIsEditing(false); setIsModalOpen(true); }} onEdit={handleEdit} onDelete={handleDelete} - addButtonText="Add New Location" isLoading={isLoading} pagination={{ skip, @@ -344,8 +402,7 @@ export default function LocationPage() {
-
-
+
{/* Modal Dialog */} { if (!open) { setIsModalOpen(false); resetForm(); } else { setIsModalOpen(true); } }}> @@ -365,15 +422,6 @@ export default function LocationPage() { - {/* Error Message in Modal */} - {error && ( -
-
- ! -
-

{error}

-
- )}
{!isEditing && ( @@ -607,6 +655,6 @@ export default function LocationPage() {
-
+ ) } diff --git a/src/app/(modules)/package/page.tsx b/src/app/(modules)/package/page.tsx index 7093f7e..0730eec 100644 --- a/src/app/(modules)/package/page.tsx +++ b/src/app/(modules)/package/page.tsx @@ -23,6 +23,8 @@ import { } from "@/lib/api" import { ColumnDef } from "@tanstack/react-table" import { toast } from "sonner" +import { Badge } from "@/components/ui/badge" +import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover" import { PoweredBy } from "@/components/powered-by" export default function PackagePage() { @@ -108,7 +110,9 @@ export default function PackagePage() { region: region.trim() || null, } await updatePackage(currentPackage.id, data) - toast.success("Package updated successfully!") + toast.success("Package Updated", { + description: `${name} has been updated successfully at ${new Date().toLocaleTimeString()}`, + }) } else { const data: PackageCreate = { project_id: selectedProjectId, @@ -116,7 +120,9 @@ export default function PackagePage() { region: region.trim() || null, } await createPackage(data) - toast.success("Package created successfully!") + toast.success("Package Created", { + description: `${name} has been established successfully at ${new Date().toLocaleTimeString()}`, + }) } // Refresh packages list @@ -126,7 +132,11 @@ export default function PackagePage() { setIsModalOpen(false) resetForm() } catch (err) { - setError(err instanceof Error ? err.message : `Failed to ${isEditing ? 'update' : 'create'} package`) + const message = err instanceof Error ? err.message : `Failed to ${isEditing ? 'update' : 'create'} package` + setError(message) + toast.error("Operation Failed", { + description: message, + }) } finally { setIsSubmitting(false) } @@ -147,10 +157,15 @@ export default function PackagePage() { try { setIsLoading(true) await deletePackage(pkg.id) - toast.success("Package deleted successfully!") + toast.success("Package Deleted", { + description: `${pkg.name} has been removed from the system.`, + }) await loadPackages() } catch (err) { setError("Failed to delete package") + toast.error("Deletion Failed", { + description: "The package could not be removed. Please try again.", + }) } finally { setIsLoading(false) } @@ -180,16 +195,38 @@ export default function PackagePage() { const pkg = row.original const project = projects.find(p => p.id === pkg.project_id) if (!project?.state) return + + const states = project.state.split(',').map(s => s.trim()).filter(Boolean) + if (states.length === 0) return + + const firstState = states[0] + const remainingStates = states.slice(1) + return ( -
- {project.state.split(',').map((item, idx) => ( - - {item.trim()} - - ))} +
+ + {firstState} + + + {remainingStates.length > 0 && ( + + + + + +
+

Other States

+ {remainingStates.map((item, idx) => ( + + {item} + + ))} +
+
+
+ )}
) } @@ -201,27 +238,26 @@ export default function PackagePage() { ] return ( -
-
-
+ <> + +
{/* Refined Header */}
{ setIsEditing(false); setIsModalOpen(true); }} + > + + Add New Package + + } />
- {/* Error Message */} - {error && !isModalOpen && ( -
-
- ! -
-

{error}

-
- )} {/* Data Table */}
@@ -229,10 +265,8 @@ export default function PackagePage() { title="Packages" data={packages} columns={columns} - onAddNew={() => { setIsEditing(false); setIsModalOpen(true); }} onEdit={handleEdit} onDelete={handleDelete} - addButtonText="Add New Package" isLoading={isLoading} pagination={{ skip, @@ -247,8 +281,7 @@ export default function PackagePage() {
-
-
+ {/* Modal Dialog */} { if (!open) { setIsModalOpen(false); resetForm(); } else { setIsModalOpen(true); } }}> @@ -269,15 +302,6 @@ export default function PackagePage() { - {/* Error Message in Modal */} - {error && ( -
-
- ! -
-

{error}

-
- )}
{/* Step 1: Select Project */} @@ -371,7 +395,7 @@ export default function PackagePage() {
-
+ ) } diff --git a/src/app/(modules)/project/page.tsx b/src/app/(modules)/project/page.tsx index 9d880c6..69a591a 100644 --- a/src/app/(modules)/project/page.tsx +++ b/src/app/(modules)/project/page.tsx @@ -12,6 +12,8 @@ import { PageHeader } from "@/components/page-header" import { createProject, fetchProjects, updateProject, deleteProject, type ProjectCreate, type Project, type ProjectUpdate } from "@/lib/api" import { ColumnDef } from "@tanstack/react-table" import { toast } from "sonner" +import { Badge } from "@/components/ui/badge" +import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover" import { PoweredBy } from "@/components/powered-by" export default function ProjectPage() { @@ -91,7 +93,9 @@ export default function ProjectPage() { end_lng: endLng ? parseFloat(endLng) : null, } await updateProject(currentProject.id, data) - toast.success("Project updated successfully!") + toast.success("Project Updated", { + description: `${name} has been updated successfully at ${new Date().toLocaleTimeString()}`, + }) } else { const data: ProjectCreate = { name: name.trim(), @@ -103,7 +107,9 @@ export default function ProjectPage() { end_lng: endLng ? parseFloat(endLng) : null, } await createProject(data) - toast.success("Project created successfully!") + toast.success("Project Created", { + description: `${name} has been established successfully at ${new Date().toLocaleTimeString()}`, + }) } // Refresh projects list @@ -113,7 +119,11 @@ export default function ProjectPage() { setIsModalOpen(false) resetForm() } catch (err) { - setError(err instanceof Error ? err.message : `Failed to ${isEditing ? 'update' : 'create'} project`) + const message = err instanceof Error ? err.message : `Failed to ${isEditing ? 'update' : 'create'} project` + setError(message) + toast.error("Operation Failed", { + description: message, + }) } finally { setIsSubmitting(false) } @@ -138,10 +148,15 @@ export default function ProjectPage() { try { setIsLoading(true) await deleteProject(project.id) - toast.success("Project deleted successfully!") + toast.success("Project Deleted", { + description: `${project.name} has been removed from the system.`, + }) await loadProjects() } catch (err) { setError("Failed to delete project") + toast.error("Deletion Failed", { + description: "The project could not be removed. Please try again or check your permissions.", + }) } finally { setIsLoading(false) } @@ -152,7 +167,7 @@ export default function ProjectPage() { accessorKey: "name", header: "Project Name", cell: ({ row }) => ( -
{row.original.name}
+
{row.original.name}
) }, { @@ -160,17 +175,45 @@ export default function ProjectPage() { header: "State", cell: ({ row }) => { const project = row.original - if (!project.state) return + if (!project.state) return + + const states = project.state.split(',').map(s => s.trim()).filter(Boolean) + if (states.length === 0) return + + const firstState = states[0] + const remainingStates = states.slice(1) + return ( -
- {project.state.split(',').map((item, idx) => ( - - {item.trim()} - - ))} +
+ + {firstState} + + + {remainingStates.length > 0 && ( + + + + + +
+

Other States

+ {remainingStates.map((item, idx) => ( + + {item} + + ))} +
+
+
+ )}
) } @@ -182,27 +225,26 @@ export default function ProjectPage() { ] return ( -
-
-
+ <> + +
{/* Refined Header */}
{ setIsEditing(false); setIsModalOpen(true); }} + > + + Add New Project + + } />
- {/* Error Message */} - {error && !isModalOpen && ( -
-
- ! -
-

{error}

-
- )} {/* Data Table */}
@@ -210,10 +252,8 @@ export default function ProjectPage() { title="Projects" data={projects} columns={columns} - onAddNew={() => { setIsEditing(false); setIsModalOpen(true); }} onEdit={handleEdit} onDelete={handleDelete} - addButtonText="Add New Project" isLoading={isLoading} pagination={{ skip, @@ -228,8 +268,8 @@ export default function ProjectPage() {
-
-
+ + {/* Modal Dialog */} { if (!open) { setIsModalOpen(false); resetForm(); } else { setIsModalOpen(true); } }}> @@ -250,15 +290,6 @@ export default function ProjectPage() { - {/* Error Message in Modal */} - {error && ( -
-
- ! -
-

{error}

-
- )}
{/* Project Name */} @@ -409,6 +440,6 @@ export default function ProjectPage() {
-
+ ) } diff --git a/src/app/favicon.ico b/src/app/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..718d6fea4835ec2d246af9800eddb7ffb276240c GIT binary patch literal 25931 zcmeHv30#a{`}aL_*G&7qml|y<+KVaDM2m#dVr!KsA!#An?kSQM(q<_dDNCpjEux83 zLb9Z^XxbDl(w>%i@8hT6>)&Gu{h#Oeyszu?xtw#Zb1mO{pgX9699l+Qppw7jXaYf~-84xW z)w4x8?=youko|}Vr~(D$UXIbiXABHh`p1?nn8Po~fxRJv}|0e(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YxIVbISaoc z-nLZC*6Tgivd5V`K%GxhBsp@SUU60-rfc$=wb>zdJzXS&-5(NRRodFk;Kxk!S(O(a0e7oY=E( zAyS;Ow?6Q&XA+cnkCb{28_1N8H#?J!*$MmIwLq^*T_9-z^&UE@A(z9oGYtFy6EZef LrJugUA?W`A8`#=m literal 0 HcmV?d00001 diff --git a/src/app/globals.css b/src/app/globals.css index 6102594..eca3ba5 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -149,6 +149,29 @@ body { @apply bg-background text-foreground; } + + /* Modern Scrollbar Styles */ + ::-webkit-scrollbar { + width: 8px; /* Slightly wider for better accessibility */ + height: 8px; + } + + ::-webkit-scrollbar-track { + background: transparent; + } + + ::-webkit-scrollbar-thumb { + background-color: var(--muted-foreground); + border-radius: 20px; + border: 2px solid transparent; + background-clip: content-box; + opacity: 0.5; /* More visible default */ + } + /* Firefox Support */ + * { + /* scrollbar-width: ; */ + scrollbar-color: var(--muted-foreground) transparent; + } } diff --git a/src/app/layout.tsx b/src/app/layout.tsx index b08eb05..a6f1f17 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -2,6 +2,7 @@ import type { Metadata } from "next"; import { Geist, Geist_Mono } from "next/font/google"; import "./globals.css"; import { ThemeProvider } from "@/components/theme-provider"; +import { Toaster } from "@/components/ui/sonner" const geistSans = Geist({ variable: "--font-geist-sans", @@ -35,6 +36,7 @@ export default function RootLayout({ disableTransitionOnChange > {children} + diff --git a/src/components/app-breadcrumb.tsx b/src/components/app-breadcrumb.tsx new file mode 100644 index 0000000..bb6f54d --- /dev/null +++ b/src/components/app-breadcrumb.tsx @@ -0,0 +1,57 @@ +"use client"; + +import React from "react"; +import { usePathname } from "next/navigation"; +import { + Breadcrumb, + BreadcrumbItem, + BreadcrumbLink, + BreadcrumbList, + BreadcrumbPage, + BreadcrumbSeparator, +} from "@/components/ui/breadcrumb"; + +export function BreadcrumbBasic() { + const pathname = usePathname(); + const segments = pathname.split("/").filter((segment) => segment !== ""); + + // Helper to format segment (e.g., "new-analysis" -> "New Analysis") + const formatSegment = (segment: string) => { + return segment + .split("-") + .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) + .join(" "); + }; + + return ( + + + + Home + + {segments.length > 0 && } + + {segments.map((segment, index) => { + const href = `/${segments.slice(0, index + 1).join("/")}`; + const isLast = index === segments.length - 1; + + // Skip segments that represent module groups or generic IDs if needed + // For now, mapping all segments + + return ( + + + {isLast ? ( + {formatSegment(segment)} + ) : ( + {formatSegment(segment)} + )} + + {!isLast && } + + ); + })} + + + ); +} diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsx index 3b0d9d7..4844c1a 100644 --- a/src/components/app-sidebar.tsx +++ b/src/components/app-sidebar.tsx @@ -78,7 +78,6 @@ export function AppSidebar({ ...props }: React.ComponentProps) { - Application {data.navMain.map((item) => ( diff --git a/src/components/dashboard/detection-donut-chart.tsx b/src/components/dashboard/detection-donut-chart.tsx index 53d54a6..30ae4a6 100644 --- a/src/components/dashboard/detection-donut-chart.tsx +++ b/src/components/dashboard/detection-donut-chart.tsx @@ -1,159 +1,156 @@ "use client" -import { PieChart, Pie, Cell, ResponsiveContainer, Legend, Tooltip } from "recharts" +import * as React from "react" import { Loader2 } from "lucide-react" +import { Label, Pie, PieChart } from "recharts" + +import { + ChartContainer, + ChartTooltip, + ChartTooltipContent, + type ChartConfig, +} from "@/components/ui/chart" interface DetectionDonutChartProps { - defectedSignboard: number - pothole: number - roadCrack: number - damagedRoadMarking: number - goodSignboard: number - isLoading?: boolean + defectedSignboard: number + pothole: number + roadCrack: number + damagedRoadMarking: number + goodSignboard: number + isLoading?: boolean } -const COLORS = { - defectedSignboard: "#3b82f6", // Blue - pothole: "#ef4444", // Red - roadCrack: "#f59e0b", // Amber/Orange - damagedRoadMarking: "#6366f1", // Indigo - goodSignboard: "#10b981" // Emerald -} +const chartConfig = { + pothole: { + label: "Potholes", + color: "var(--chart-1)", + }, + defectedSignboard: { + label: "Defected Signboards", + color: "var(--chart-2)", + }, + roadCrack: { + label: "Road Cracks", + color: "var(--chart-3)", + }, + damagedRoadMarking: { + label: "Damaged Markings", + color: "var(--chart-4)", + }, + goodSignboard: { + label: "Good Signboards", + color: "var(--chart-5)", + }, +} satisfies ChartConfig export function DetectionDonutChart({ - defectedSignboard, - pothole, - roadCrack, - damagedRoadMarking, - goodSignboard, - isLoading = false + defectedSignboard, + pothole, + roadCrack, + damagedRoadMarking, + goodSignboard, + isLoading = false, }: DetectionDonutChartProps) { - if (isLoading) { - return ( -
- -
- ) - } + const chartData = React.useMemo( + () => + [ + { type: "pothole", count: pothole, fill: "var(--color-pothole)" }, + { + type: "defectedSignboard", + count: defectedSignboard, + fill: "var(--color-defectedSignboard)", + }, + { type: "roadCrack", count: roadCrack, fill: "var(--color-roadCrack)" }, + { + type: "damagedRoadMarking", + count: damagedRoadMarking, + fill: "var(--color-damagedRoadMarking)", + }, + { + type: "goodSignboard", + count: goodSignboard, + fill: "var(--color-goodSignboard)", + }, + ].filter((item) => item.count > 0), + [ + pothole, + defectedSignboard, + roadCrack, + damagedRoadMarking, + goodSignboard, + ] + ) - const total = defectedSignboard + pothole + roadCrack + damagedRoadMarking + goodSignboard - - if (total === 0) { - return ( -
-

No detections found

-

Process videos to see data

-
- ) - } - - const data = [ - { name: "Defected Signboards", value: defectedSignboard, color: COLORS.defectedSignboard }, - { name: "Potholes", value: pothole, color: COLORS.pothole }, - { name: "Road Cracks", value: roadCrack, color: COLORS.roadCrack }, - { name: "Damaged Markings", value: damagedRoadMarking, color: COLORS.damagedRoadMarking }, - { name: "Good Signboards", value: goodSignboard, color: COLORS.goodSignboard } - ].filter(item => item.value > 0) + const totalDetections = React.useMemo(() => { + return chartData.reduce((acc, curr) => acc + curr.count, 0) + }, [chartData]) + if (isLoading) { return ( -
- - - - - - - - - - - - - - - - - - - - - - - - - - {data.map((entry, index) => { - const gradId = entry.name === "Potholes" ? "gradPothole" : - entry.name === "Defected Signboards" ? "gradDefectedSign" : - entry.name === "Road Cracks" ? "gradCrack" : - entry.name === "Damaged Markings" ? "gradMarking" : "gradGoodSign" - return ( - - ) - })} - - { - if (active && payload && payload.length) { - const data = payload[0] - return ( -
-

{data.name}

-

- Count: {data.value} -

-

- {((Number(data.value) / total) * 100).toFixed(1)}% of total -

-
- ) - } - return null - }} - /> - ( -
- {payload?.map((entry, index) => ( -
-
- - {entry.value}: {data[index].value} - -
- ))} -
- )} - /> - - - {/* Center label */} -
-
-

{total}

-

Total

-
-
-
+
+ +
) + } + + if (totalDetections === 0) { + return ( +
+

No detections found

+

Process videos to see data

+
+ ) + } + + return ( + + + } + /> + + + + + ) } + diff --git a/src/components/dashboard/location-bar-chart.tsx b/src/components/dashboard/location-bar-chart.tsx index d60fe70..ac5cddf 100644 --- a/src/components/dashboard/location-bar-chart.tsx +++ b/src/components/dashboard/location-bar-chart.tsx @@ -1,179 +1,105 @@ "use client" -import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, Legend } from "recharts" +import * as React from "react" +import { Bar, BarChart, CartesianGrid, XAxis, YAxis } from "recharts" import { Loader2 } from "lucide-react" +import { + ChartContainer, + ChartTooltip, + ChartTooltipContent, + type ChartConfig, +} from "@/components/ui/chart" + interface LocationData { - name: string - defected_sign_board: number - pothole: number - road_crack: number - damaged_road_marking: number - good_sign_board: number - total: number + name: string + defected_sign_board: number + pothole: number + road_crack: number + damaged_road_marking: number + total: number } interface LocationBarChartProps { - data: LocationData[] - isLoading?: boolean + data: LocationData[] + isLoading?: boolean } -const COLORS = { - defected_sign_board: "#60a5fa", // Lighter Blue - pothole: "#ff8a8a", // Lighter Red - road_crack: "#fbbf24", // Lighter Orange - damaged_road_marking: "#818cf8", // Lighter Indigo - good_sign_board: "#34d399" // Lighter Emerald -} +const chartConfig = { + pothole: { + label: "Potholes", + color: "var(--chart-1)", + }, + defected_sign_board: { + label: "Defected Signboards", + color: "var(--chart-2)", + }, + road_crack: { + label: "Road Cracks", + color: "var(--chart-3)", + }, + damaged_road_marking: { + label: "Damaged Markings", + color: "var(--chart-4)", + }, +} satisfies ChartConfig export function LocationBarChart({ data, isLoading = false }: LocationBarChartProps) { - if (isLoading) { - return ( -
- -
- ) - } - - if (data.length === 0) { - return ( -
-

No location data available

-

Process videos to see detections by location

-
- ) - } - + if (isLoading) { return ( -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - { - if (active && payload && payload.length) { - return ( -
-

{label}

- {payload.map((entry, index) => ( -
-
- {(entry.name as string).replace(/_/g, ' ')}: - {entry.value} -
- ))} -
- ) - } - return null - }} - /> - ( -
- {payload?.map((entry, index) => ( -
-
- - {(entry.value as string).replace(/_/g, ' ')} - -
- ))} -
- )} - /> - - - - - - - -
+
+ +
) + } + + if (data.length === 0) { + return ( +
+

No location data available

+

Process videos to see detections by location

+
+ ) + } + + // Filter out good signboards for a more "damage-focused" standard chart as per multiple bar example + const chartData = data.map(item => ({ + name: item.name, + pothole: item.pothole, + defected_sign_board: item.defected_sign_board, + road_crack: item.road_crack, + damaged_road_marking: item.damaged_road_marking, + })) + + return ( +
+ + + + value.length > 8 ? `${value.slice(0, 8)}...` : value} + fontSize={12} + /> + + } + /> + + + + + + +
+ ) } diff --git a/src/components/dashboard/stats-card.tsx b/src/components/dashboard/stats-card.tsx index f53859b..511b232 100644 --- a/src/components/dashboard/stats-card.tsx +++ b/src/components/dashboard/stats-card.tsx @@ -19,7 +19,7 @@ export function StatsCard({ isLoading = false }: StatsCardProps) { return ( - +

diff --git a/src/components/data-table/Footer/index.tsx b/src/components/data-table/Footer/index.tsx index d899470..256eb92 100644 --- a/src/components/data-table/Footer/index.tsx +++ b/src/components/data-table/Footer/index.tsx @@ -1,64 +1,69 @@ "use client"; import { Table } from "@tanstack/react-table"; import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, } from "@/components/ui/select"; import { Button } from "@/components/ui/button"; import { ChevronLeft, ChevronRight } from "lucide-react"; export function TableFooter({ table }: { table: Table }) { - return ( -
-
-

Rows per page

- -
- -
- Page {table.getState().pagination.pageIndex + 1} of{" "} - {table.getPageCount() || 1} -
+ return ( +
+
+
+

Rows per page

+ +
+
-
- - -
-
- ); +
+
+ Page {table.getState().pagination.pageIndex + 1} + / + {table.getPageCount() || 1} +
+ +
+ + +
+
+
+ ); } diff --git a/src/components/data-table/Header/SearchBar.tsx b/src/components/data-table/Header/SearchBar.tsx index 6b5a6e2..fe96484 100644 --- a/src/components/data-table/Header/SearchBar.tsx +++ b/src/components/data-table/Header/SearchBar.tsx @@ -3,15 +3,15 @@ import { SearchIcon } from "lucide-react"; import { Input } from "@/components/ui/input"; const SearchBar = () => { - return ( -
- - -
- ); + return ( +
+ + +
+ ); }; export default SearchBar; diff --git a/src/components/data-table/Header/index.tsx b/src/components/data-table/Header/index.tsx index a235cad..46ab099 100644 --- a/src/components/data-table/Header/index.tsx +++ b/src/components/data-table/Header/index.tsx @@ -1,45 +1,47 @@ "use client"; +import React from "react"; import { Button } from "@/components/ui/button"; import SearchBar from "./SearchBar"; -import { PlusIcon } from "lucide-react"; +import { FolderPlus, Settings2, SlidersHorizontal } from "lucide-react"; +import { Badge } from "@/components/ui/badge"; interface TopHeaderProps { - title?: string; - itemCount?: number; - onAddNew?: () => void; - addButtonText?: string; + title?: string; + itemCount?: number; + onAddNew?: () => void; + addButtonText?: string; } const TopHeader = ({ title, itemCount, onAddNew, addButtonText = "Add New" }: TopHeaderProps) => { - return ( -
-
-
-

{title}

- {itemCount !== undefined && ( - - {itemCount} - - )} + return ( +
+ {/* Connected Summary Block */} +
+
+ Total {title || "Items"} : + {itemCount || 0} +
+
+ +
+ {/* Search Bar Hidden for now as per requirement */} + {/*
+ +
*/} + + {/* Add New Button moved to PageHeader */} + {/* {onAddNew && ( + + )} */} +
- - {onAddNew && ( - - )} -
- -
- -
-
- ); + ); }; export default TopHeader; diff --git a/src/components/data-table/TableHeader.tsx b/src/components/data-table/TableHeader.tsx index 51ba3ea..43b3d3b 100644 --- a/src/components/data-table/TableHeader.tsx +++ b/src/components/data-table/TableHeader.tsx @@ -1,33 +1,38 @@ "use client"; import { flexRender } from "@tanstack/react-table"; import { - TableHead, - TableHeader as ShadTableHeader, - TableRow, + TableHead, + TableHeader as ShadTableHeader, + TableRow, } from "@/components/ui/table"; import { Table } from "@tanstack/react-table"; +import { ChevronDown, ChevronsUpDown } from "lucide-react"; const TableHeader = ({ table }: { table: Table }) => { - return ( - - {table.getHeaderGroups().map((headerGroup) => ( - - {headerGroup.headers.map((header) => { - return ( - - {header.isPlaceholder - ? null - : flexRender( - header.column.columnDef.header, - header.getContext() - )} - - ); - })} - - ))} - - ); + return ( + + {table.getHeaderGroups().map((headerGroup) => ( + + {headerGroup.headers.map((header) => { + return ( + + {header.isPlaceholder + ? null + : ( +
+ {flexRender( + header.column.columnDef.header, + header.getContext() + )} +
+ )} +
+ ); + })} +
+ ))} +
+ ); }; export default TableHeader; diff --git a/src/components/data-table/index.tsx b/src/components/data-table/index.tsx index d86e67f..dbb0abf 100644 --- a/src/components/data-table/index.tsx +++ b/src/components/data-table/index.tsx @@ -1,20 +1,19 @@ "use client"; import React from "react"; import { - ColumnDef, - SortingState, - flexRender, - getCoreRowModel, - useReactTable, - getSortedRowModel, - getPaginationRowModel, + ColumnDef, + SortingState, + flexRender, + getCoreRowModel, + useReactTable, + getSortedRowModel, + getPaginationRowModel, } from "@tanstack/react-table"; import { Table, TableBody, TableCell, TableRow } from "@/components/ui/table"; import { Skeleton } from "@/components/ui/skeleton"; import { Button } from "@/components/ui/button"; -import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; -import { Edit2, Trash2 } from "lucide-react"; +import { Edit3, MoreHorizontal, Trash2 } from "lucide-react"; import TopHeader from "./Header"; import TableHeader from "./TableHeader"; @@ -22,165 +21,169 @@ import { TableFooter } from "./Footer"; import { cn } from "@/lib/utils"; export interface DataTableProps { - columns: ColumnDef[]; - data: TData[]; - title?: string; - onAddNew?: () => void; - addButtonText?: string; - isLoading?: boolean; - onEdit?: (item: TData) => void; - onDelete?: (item: TData) => void; - pagination?: { - skip: number; - limit: number; - totalItems?: number; - onPageChange: (newSkip: number) => void; - onLimitChange: (newLimit: number) => void; - }; + columns: ColumnDef[]; + data: TData[]; + title?: string; + onAddNew?: () => void; + addButtonText?: string; + isLoading?: boolean; + onEdit?: (item: TData) => void; + onDelete?: (item: TData) => void; + pagination?: { + skip: number; + limit: number; + totalItems?: number; + onPageChange: (newSkip: number) => void; + onLimitChange: (newLimit: number) => void; + }; } export function DataTable({ - columns: initialColumns, - data, - title, - onAddNew, - addButtonText, - isLoading = false, - onEdit, - onDelete, - pagination, -}: DataTableProps) { - const [rowSelection, setRowSelection] = React.useState({}); - const [sorting, setSorting] = React.useState([]); - - const columns = React.useMemo(() => { - const cols = [...initialColumns]; - if (onEdit || onDelete) { - cols.push({ - id: "actions", - header: () =>
Actions
, - cell: ({ row }) => { - const item = row.original; - return ( -
- {onEdit && ( - - )} - {onDelete && ( - - )} -
- ); - }, - }); - } - return cols; - }, [initialColumns, onEdit, onDelete]); - - const table = useReactTable({ + columns: initialColumns, data, - columns, - getCoreRowModel: getCoreRowModel(), - onRowSelectionChange: setRowSelection, - onSortingChange: setSorting, - getSortedRowModel: getSortedRowModel(), - getPaginationRowModel: getPaginationRowModel(), - manualPagination: !!pagination, - pageCount: pagination?.totalItems ? Math.ceil(pagination.totalItems / pagination.limit) : -1, - state: { - rowSelection, - sorting, - pagination: pagination ? { - pageIndex: Math.floor(pagination.skip / pagination.limit), - pageSize: pagination.limit, - } : undefined, - }, - onPaginationChange: (updater) => { - if (typeof updater === 'function' && pagination) { - const newState = updater({ + title, + onAddNew, + addButtonText, + isLoading = false, + onEdit, + onDelete, + pagination, +}: DataTableProps) { + const [rowSelection, setRowSelection] = React.useState({}); + const [sorting, setSorting] = React.useState([]); + + const columns = React.useMemo(() => { + const cols: ColumnDef[] = [ + ...initialColumns, + ]; + + if (onEdit || onDelete) { + cols.push({ + id: "actions", + header: () =>
Action
, + cell: ({ row }) => { + const item = row.original; + return ( +
+ {onEdit && ( + + )} + {onDelete && ( + + )} +
+ ); + }, + }); + } + return cols; + }, [initialColumns, onEdit, onDelete]); + + const table = useReactTable({ + data, + columns, + getCoreRowModel: getCoreRowModel(), + onRowSelectionChange: setRowSelection, + onSortingChange: setSorting, + getSortedRowModel: getSortedRowModel(), + getPaginationRowModel: getPaginationRowModel(), + manualPagination: !!pagination, + pageCount: pagination?.totalItems ? Math.ceil(pagination.totalItems / pagination.limit) : -1, + state: { + rowSelection, + sorting, + pagination: pagination ? { pageIndex: Math.floor(pagination.skip / pagination.limit), pageSize: pagination.limit, - }); - pagination.onLimitChange(newState.pageSize); - pagination.onPageChange(newState.pageIndex * newState.pageSize); - } - }, - initialState: { - pagination: { - pageSize: 10, - pageIndex: 0, - }, - }, - }); + } : undefined, + }, + onPaginationChange: (updater) => { + if (typeof updater === 'function' && pagination) { + const newState = updater({ + pageIndex: Math.floor(pagination.skip / pagination.limit), + pageSize: pagination.limit, + }); + pagination.onLimitChange(newState.pageSize); + pagination.onPageChange(newState.pageIndex * newState.pageSize); + } + }, + }); - return ( -
- + return ( +
+
+ -
- - - - {isLoading ? ( - Array.from({ length: 5 }).map((_, idx) => ( - - {columns.map((_, colIdx) => ( - - - - ))} - - )) - ) : table.getRowModel().rows?.length ? ( - table.getRowModel().rows.map((row) => ( - - {row.getVisibleCells().map((cell) => ( - - {flexRender( - cell.column.columnDef.cell, - cell.getContext() - )} - - ))} - - )) - ) : ( - - - No results found. - - - )} - -
-
- - -
- ); +
+ + + + {isLoading ? ( + Array.from({ length: 5 }).map((_, idx) => ( + + {columns.map((_, colIdx) => ( + + + + ))} + + )) + ) : table.getRowModel().rows?.length ? ( + table.getRowModel().rows.map((row) => ( + + {row.getVisibleCells().map((cell) => ( + + {flexRender( + cell.column.columnDef.cell, + cell.getContext() + )} + + ))} + + )) + ) : ( + + +
+

No results found.

+

Try adjusting your filters or search terms.

+
+
+
+ )} +
+
+
+ +
+
+ ); } diff --git a/src/components/page-header.tsx b/src/components/page-header.tsx index 7a82506..d9460c3 100644 --- a/src/components/page-header.tsx +++ b/src/components/page-header.tsx @@ -7,23 +7,31 @@ interface PageHeaderProps { description: string icon?: LucideIcon children?: React.ReactNode + actions?: React.ReactNode } -export function PageHeader({ title, description, icon: Icon, children }: PageHeaderProps) { +export function PageHeader({ title, description, icon: Icon, children, actions }: PageHeaderProps) { return ( -
-
- {Icon && } - {children} -
-
-

- {title} -

-

- {description} -

+
+
+ {/*
+ {Icon && } + {children} +
*/} +
+

+ {title} +

+

+ {description} +

+
+ {actions && ( +
+ {actions} +
+ )}
) } diff --git a/src/components/ui/badge.tsx b/src/components/ui/badge.tsx index fc4126b..6eb2a05 100644 --- a/src/components/ui/badge.tsx +++ b/src/components/ui/badge.tsx @@ -1,42 +1,44 @@ -import * as React from 'react' -import { Slot } from '@radix-ui/react-slot' -import { cva, type VariantProps } from 'class-variance-authority' +import * as React from "react" +import { cva, type VariantProps } from "class-variance-authority" +import { Slot } from "radix-ui" -import { cn } from '@/lib/utils' +import { cn } from "@/lib/utils" const badgeVariants = cva( - 'inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden', + "inline-flex w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-full border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3", { variants: { variant: { - default: - 'border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90', + default: "bg-primary text-primary-foreground [a&]:hover:bg-primary/90", secondary: - 'border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90', + "bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90", destructive: - 'border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60', + "bg-destructive text-white focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40 [a&]:hover:bg-destructive/90", outline: - 'text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground', + "border-border text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground", + ghost: "[a&]:hover:bg-accent [a&]:hover:text-accent-foreground", + link: "text-primary underline-offset-4 [a&]:hover:underline", }, }, defaultVariants: { - variant: 'default', + variant: "default", }, - }, + } ) function Badge({ className, - variant, + variant = "default", asChild = false, ...props -}: React.ComponentProps<'span'> & +}: React.ComponentProps<"span"> & VariantProps & { asChild?: boolean }) { - const Comp = asChild ? Slot : 'span' + const Comp = asChild ? Slot.Root : "span" return ( diff --git a/src/components/ui/breadcrumb.tsx b/src/components/ui/breadcrumb.tsx index eb88f32..f0fa16e 100644 --- a/src/components/ui/breadcrumb.tsx +++ b/src/components/ui/breadcrumb.tsx @@ -1,6 +1,6 @@ import * as React from "react" -import { Slot } from "@radix-ui/react-slot" import { ChevronRight, MoreHorizontal } from "lucide-react" +import { Slot } from "radix-ui" import { cn } from "@/lib/utils" @@ -13,7 +13,7 @@ function BreadcrumbList({ className, ...props }: React.ComponentProps<"ol">) {
    & { asChild?: boolean }) { - const Comp = asChild ? Slot : "a" + const Comp = asChild ? Slot.Root : "a" return ( ) @@ -56,7 +56,7 @@ function BreadcrumbPage({ className, ...props }: React.ComponentProps<"span">) { role="link" aria-disabled="true" aria-current="page" - className={cn("text-foreground font-normal", className)} + className={cn("font-normal text-foreground", className)} {...props} /> ) diff --git a/src/components/ui/popover.tsx b/src/components/ui/popover.tsx index 0a1a378..30058c4 100644 --- a/src/components/ui/popover.tsx +++ b/src/components/ui/popover.tsx @@ -1,9 +1,9 @@ -'use client' +"use client" -import * as React from 'react' -import * as PopoverPrimitive from '@radix-ui/react-popover' +import * as React from "react" +import { Popover as PopoverPrimitive } from "radix-ui" -import { cn } from '@/lib/utils' +import { cn } from "@/lib/utils" function Popover({ ...props @@ -19,7 +19,7 @@ function PopoverTrigger({ function PopoverContent({ className, - align = 'center', + align = "center", sideOffset = 4, ...props }: React.ComponentProps) { @@ -30,8 +30,8 @@ function PopoverContent({ align={align} sideOffset={sideOffset} className={cn( - 'bg-popover text-popover-foreground z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden', - className, + "z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95", + className )} {...props} /> @@ -45,4 +45,45 @@ function PopoverAnchor({ return } -export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor } +function PopoverHeader({ className, ...props }: React.ComponentProps<"div">) { + return ( +
    + ) +} + +function PopoverTitle({ className, ...props }: React.ComponentProps<"h2">) { + return ( +
    + ) +} + +function PopoverDescription({ + className, + ...props +}: React.ComponentProps<"p">) { + return ( +

    + ) +} + +export { + Popover, + PopoverTrigger, + PopoverContent, + PopoverAnchor, + PopoverHeader, + PopoverTitle, + PopoverDescription, +} diff --git a/src/components/ui/scroll-area.tsx b/src/components/ui/scroll-area.tsx index db7e9c5..73c4eb1 100644 --- a/src/components/ui/scroll-area.tsx +++ b/src/components/ui/scroll-area.tsx @@ -1,9 +1,9 @@ -'use client' +"use client" -import * as React from 'react' -import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area' +import * as React from "react" +import { ScrollArea as ScrollAreaPrimitive } from "radix-ui" -import { cn } from '@/lib/utils' +import { cn } from "@/lib/utils" function ScrollArea({ className, @@ -13,12 +13,12 @@ function ScrollArea({ return ( {children} @@ -30,7 +30,7 @@ function ScrollArea({ function ScrollBar({ className, - orientation = 'vertical', + orientation = "vertical", ...props }: React.ComponentProps) { return ( @@ -38,18 +38,18 @@ function ScrollBar({ data-slot="scroll-area-scrollbar" orientation={orientation} className={cn( - 'flex touch-none p-px select-none', - orientation === 'vertical' && - 'h-full w-2.5 border-l border-l-transparent', - orientation === 'horizontal' && - 'h-2.5 flex-col border-t border-t-transparent', - className, + "flex touch-none p-px transition-colors select-none", + orientation === "vertical" && + "h-full w-2.5 border-l border-l-transparent", + orientation === "horizontal" && + "h-2.5 flex-col border-t border-t-transparent", + className )} {...props} > ) diff --git a/src/components/ui/table.tsx b/src/components/ui/table.tsx index e27f183..be6f349 100644 --- a/src/components/ui/table.tsx +++ b/src/components/ui/table.tsx @@ -4,11 +4,15 @@ import * as React from "react" import { cn } from "@/lib/utils" -function Table({ className, ...props }: React.ComponentProps<"table">) { +function Table({ + className, + containerClassName, + ...props +}: React.ComponentProps<"table"> & { containerClassName?: string }) { return (