fix: enhance admin dashboard drawer UX

Fix scrolling, layout, and collapsible sections; improve animations and sizing.

#VERCEL_SKIP

Co-authored-by: Allan K. Koech <44490960+allankoechke@users.noreply.github.com>
This commit is contained in:
v0
2025-06-23 11:54:58 +00:00
parent b9869a1bca
commit 8d83b194d7
4 changed files with 415 additions and 350 deletions

View File

@@ -65,8 +65,8 @@ export function EditItemDrawer({ table, item, apiClient, open, onClose, onItemUp
return (
<Drawer open={open} onOpenChange={onClose}>
<DrawerContent side="right" className="w-[700px] max-w-[90vw]">
<DrawerHeader className="border-b">
<DrawerContent side="right" className="w-[700px] max-w-[95vw]">
<DrawerHeader>
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<Edit className="h-5 w-5" />
@@ -79,7 +79,8 @@ export function EditItemDrawer({ table, item, apiClient, open, onClose, onItemUp
<DrawerDescription>Edit record in {table.name} table</DrawerDescription>
</DrawerHeader>
<ScrollArea className="flex-1">
<div className="flex-1 overflow-hidden">
<ScrollArea className="h-full">
<div className="p-6 space-y-6">
{table.fields?.map((field) => (
<div key={field.name} className="space-y-2">
@@ -89,7 +90,9 @@ export function EditItemDrawer({ table, item, apiClient, open, onClose, onItemUp
</Label>
<Input
id={field.name}
type={field.name === "password" ? "password" : field.type === "datetime" ? "datetime-local" : "text"}
type={
field.name === "password" ? "password" : field.type === "datetime" ? "datetime-local" : "text"
}
value={formData[field.name] || ""}
onChange={(e) => handleFieldChange(field.name, e.target.value)}
disabled={isSystemField(field.name)}
@@ -103,8 +106,9 @@ export function EditItemDrawer({ table, item, apiClient, open, onClose, onItemUp
))}
</div>
</ScrollArea>
</div>
<DrawerFooter className="border-t mt-6">
<DrawerFooter>
<div className="flex gap-3">
<Button variant="outline" onClick={onClose} className="flex-1">
Cancel

View File

@@ -1,7 +1,7 @@
"use client"
import * as React from "react"
import { Plus, Trash2, Cog, X } from "lucide-react"
import { Plus, Trash2, Cog, X, ChevronDown } from "lucide-react"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
@@ -19,6 +19,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
import { ScrollArea } from "@/components/ui/scroll-area"
import { Textarea } from "@/components/ui/textarea"
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible"
import type { ApiClient, TableMetadata } from "@/lib/api"
interface TableConfigDrawerProps {
@@ -114,8 +115,8 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
return (
<Drawer open={open} onOpenChange={onClose}>
<DrawerContent side="right" className="w-[800px] max-w-[90vw]">
<DrawerHeader className="border-b">
<DrawerContent side="right" className="w-[900px] max-w-[95vw]">
<DrawerHeader>
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<Cog className="h-5 w-5" />
@@ -128,9 +129,10 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
<DrawerDescription>Manage table schema and access control rules</DrawerDescription>
</DrawerHeader>
<ScrollArea className="flex-1">
<div className="flex-1 overflow-hidden">
<ScrollArea className="h-full">
<div className="p-6">
<Tabs value={activeTab} onValueChange={setActiveTab}>
<Tabs value={activeTab} onValueChange={setActiveTab} className="w-full">
<TabsList className="grid w-full grid-cols-2 mb-6">
<TabsTrigger value="schema">Schema</TabsTrigger>
<TabsTrigger value="rules">Access Rules</TabsTrigger>
@@ -153,18 +155,22 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
{table.type === "view" ? (
<div className="p-4 bg-muted rounded-lg">
<h5 className="font-medium mb-3">SQL Query</h5>
<pre className="text-sm overflow-x-auto whitespace-pre-wrap">
<ScrollArea className="h-32">
<pre className="text-sm whitespace-pre-wrap">
<code>{table.sql}</code>
</pre>
</ScrollArea>
</div>
) : (
<div className="space-y-4">
{columns.map((column, index) => {
const isSystem = isSystemColumn(column.name)
return (
<div key={index} className={`p-4 border rounded-lg space-y-4 ${isSystem ? "bg-muted/50" : ""}`}>
<div className="flex items-center gap-3">
<div className="flex-1">
<div key={index} className={`border rounded-lg ${isSystem ? "bg-muted/50" : ""}`}>
<div className="p-4 space-y-4">
{/* Basic Info */}
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
<div className="md:col-span-2">
<Label className="text-sm font-medium mb-2 block">Column Name</Label>
<div className="flex items-center gap-2">
<Input
@@ -181,7 +187,7 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
)}
</div>
</div>
<div className="w-40">
<div>
<Label className="text-sm font-medium mb-2 block">Data Type</Label>
<Select
value={column.type}
@@ -200,20 +206,9 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
</SelectContent>
</Select>
</div>
<div className="pt-6">
<Button
type="button"
variant="ghost"
size="sm"
onClick={() => removeColumn(index)}
disabled={columns.length === 1 || isSystem}
className={isSystem ? "opacity-30" : ""}
>
<Trash2 className="h-4 w-4" />
</Button>
</div>
</div>
{/* Basic Properties */}
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
<div className="flex items-center space-x-2">
<input
@@ -228,19 +223,6 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
Primary Key
</Label>
</div>
<div className="flex items-center space-x-2">
<input
type="checkbox"
id={`unique-${index}`}
checked={column.unique || false}
onChange={(e) => updateColumn(index, "unique", e.target.checked)}
disabled={isSystem}
className="rounded"
/>
<Label htmlFor={`unique-${index}`} className="text-sm">
Unique
</Label>
</div>
<div className="flex items-center space-x-2">
<input
type="checkbox"
@@ -254,6 +236,19 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
Required
</Label>
</div>
<div className="flex items-center space-x-2">
<input
type="checkbox"
id={`unique-${index}`}
checked={column.unique || false}
onChange={(e) => updateColumn(index, "unique", e.target.checked)}
disabled={isSystem}
className="rounded"
/>
<Label htmlFor={`unique-${index}`} className="text-sm">
Unique
</Label>
</div>
<div className="flex items-center space-x-2">
<input
type="checkbox"
@@ -268,6 +263,62 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
</Label>
</div>
</div>
{/* Advanced Options - Collapsible */}
<Collapsible>
<CollapsibleTrigger asChild>
<Button variant="ghost" size="sm" className="w-full justify-between p-2">
<span className="text-sm">Advanced Options</span>
<ChevronDown className="h-4 w-4" />
</Button>
</CollapsibleTrigger>
<CollapsibleContent className="space-y-4 pt-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<Label className="text-sm font-medium mb-2 block">Default Value</Label>
<Input
placeholder="Default value"
disabled={isSystem}
className={isSystem ? "bg-muted" : ""}
/>
</div>
<div>
<Label className="text-sm font-medium mb-2 block">Max Length</Label>
<Input
type="number"
placeholder="Max length"
disabled={isSystem}
className={isSystem ? "bg-muted" : ""}
/>
</div>
</div>
<div>
<Label className="text-sm font-medium mb-2 block">Description</Label>
<Textarea
placeholder="Column description"
disabled={isSystem}
className={isSystem ? "bg-muted" : ""}
rows={2}
/>
</div>
</CollapsibleContent>
</Collapsible>
{/* Delete Button */}
<div className="flex justify-end pt-2 border-t">
<Button
type="button"
variant="ghost"
size="sm"
onClick={() => removeColumn(index)}
disabled={columns.length === 1 || isSystem}
className={`text-destructive hover:text-destructive ${isSystem ? "opacity-30" : ""}`}
>
<Trash2 className="h-4 w-4 mr-2" />
Remove Column
</Button>
</div>
</div>
</div>
)
})}
@@ -300,7 +351,7 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
value={rules.list}
onChange={(e) => setRules({ ...rules, list: e.target.value })}
className="mt-2"
rows={2}
rows={3}
/>
<p className="text-xs text-muted-foreground mt-1">Controls who can list records</p>
</div>
@@ -315,7 +366,7 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
value={rules.get}
onChange={(e) => setRules({ ...rules, get: e.target.value })}
className="mt-2"
rows={2}
rows={3}
/>
<p className="text-xs text-muted-foreground mt-1">Controls who can view individual records</p>
</div>
@@ -332,7 +383,7 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
value={rules.add}
onChange={(e) => setRules({ ...rules, add: e.target.value })}
className="mt-2"
rows={2}
rows={3}
/>
<p className="text-xs text-muted-foreground mt-1">Controls who can create new records</p>
</div>
@@ -347,7 +398,7 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
value={rules.update}
onChange={(e) => setRules({ ...rules, update: e.target.value })}
className="mt-2"
rows={2}
rows={3}
/>
<p className="text-xs text-muted-foreground mt-1">Controls who can update records</p>
</div>
@@ -362,7 +413,7 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
value={rules.delete}
onChange={(e) => setRules({ ...rules, delete: e.target.value })}
className="mt-2"
rows={2}
rows={3}
/>
<p className="text-xs text-muted-foreground mt-1">Controls who can delete records</p>
</div>
@@ -373,7 +424,7 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
<div className="mt-6 p-4 bg-muted rounded-lg">
<h5 className="font-medium mb-3">Rule Examples</h5>
<div className="space-y-2 text-sm text-muted-foreground">
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<div className="grid grid-cols-1 gap-2">
<p>
<code className="bg-background px-2 py-1 rounded">""</code> - Admin access only
</p>
@@ -382,11 +433,11 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
</p>
<p>
<code className="bg-background px-2 py-1 rounded">"auth.id != None"</code> - Authenticated
users
users only
</p>
<p>
<code className="bg-background px-2 py-1 rounded">"auth.id == record.user_id"</code> - Owner
only
access only
</p>
</div>
</div>
@@ -396,8 +447,9 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
</Tabs>
</div>
</ScrollArea>
</div>
<DrawerFooter className="border-t mt-6">
<DrawerFooter>
<div className="flex gap-3">
<Button variant="outline" onClick={onClose} className="flex-1">
Cancel

View File

@@ -19,8 +19,8 @@ interface TableDocsDrawerProps {
export function TableDocsDrawer({ table, open, onClose }: TableDocsDrawerProps) {
return (
<Drawer open={open} onOpenChange={onClose}>
<DrawerContent side="right" className="w-[900px] max-w-[90vw]">
<DrawerHeader className="border-b">
<DrawerContent side="right" className="w-[1000px] max-w-[95vw]">
<DrawerHeader>
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<FileText className="h-5 w-5" />
@@ -33,7 +33,8 @@ export function TableDocsDrawer({ table, open, onClose }: TableDocsDrawerProps)
<DrawerDescription>Auto-generated API endpoints and examples</DrawerDescription>
</DrawerHeader>
<ScrollArea className="flex-1">
<div className="flex-1 overflow-hidden">
<ScrollArea className="h-full">
<div className="p-6 space-y-6">
<ApiEndpointCard
method="GET"
@@ -80,6 +81,7 @@ export function TableDocsDrawer({ table, open, onClose }: TableDocsDrawerProps)
)}
</div>
</ScrollArea>
</div>
</DrawerContent>
</Drawer>
)
@@ -232,9 +234,11 @@ function ApiEndpointCard({
Copy
</Button>
</div>
<pre className="bg-muted p-4 rounded text-sm overflow-x-auto border">
<ScrollArea className="h-48">
<pre className="bg-muted p-4 rounded text-sm border">
<code>{requestExample}</code>
</pre>
</ScrollArea>
</div>
<div>
@@ -245,9 +249,11 @@ function ApiEndpointCard({
Copy
</Button>
</div>
<pre className="bg-muted p-4 rounded text-sm overflow-x-auto border">
<ScrollArea className="h-48">
<pre className="bg-muted p-4 rounded text-sm border">
<code>{responseExample}</code>
</pre>
</ScrollArea>
</div>
<div>

View File

@@ -26,16 +26,16 @@ const DrawerOverlay = React.forwardRef<
DrawerOverlay.displayName = DrawerPrimitive.Overlay.displayName
const drawerVariants = cva(
"fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",
"fixed z-50 gap-4 bg-background shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",
{
variants: {
side: {
top: "inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",
bottom:
"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",
left: "inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",
left: "inset-y-0 left-0 h-full border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left",
right:
"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",
"inset-y-0 right-0 h-full border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right",
},
},
defaultVariants: {
@@ -52,11 +52,11 @@ const DrawerContent = React.forwardRef<React.ElementRef<typeof DrawerPrimitive.C
({ side = "right", className, children, ...props }, ref) => (
<DrawerPortal>
<DrawerOverlay />
<DrawerPrimitive.Content ref={ref} className={cn(drawerVariants({ side }), className)} {...props}>
{side === "right" && <div className="absolute left-0 top-1/2 h-4 w-1 -translate-y-1/2 rounded-r bg-muted" />}
{side === "left" && <div className="absolute right-0 top-1/2 h-4 w-1 -translate-y-1/2 rounded-l bg-muted" />}
{side === "bottom" && <div className="mx-auto mt-4 h-2 w-[100px] rounded-full bg-muted" />}
{side === "top" && <div className="mx-auto mb-4 h-2 w-[100px] rounded-full bg-muted" />}
<DrawerPrimitive.Content
ref={ref}
className={cn(drawerVariants({ side }), "flex flex-col", className)}
{...props}
>
{children}
</DrawerPrimitive.Content>
</DrawerPortal>
@@ -65,12 +65,15 @@ const DrawerContent = React.forwardRef<React.ElementRef<typeof DrawerPrimitive.C
DrawerContent.displayName = "DrawerContent"
const DrawerHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
<div className={cn("flex flex-col space-y-1.5 text-center sm:text-left", className)} {...props} />
<div className={cn("flex flex-col space-y-1.5 text-center sm:text-left p-6 border-b", className)} {...props} />
)
DrawerHeader.displayName = "DrawerHeader"
const DrawerFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
<div className={cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2", className)} {...props} />
<div
className={cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2 p-6 border-t mt-auto", className)}
{...props}
/>
)
DrawerFooter.displayName = "DrawerFooter"