fix: enhance UI components and user experience

Improve error notifications, drawer sizing, and form layout
for better UX and responsive design.

#VERCEL_SKIP

Co-authored-by: Allan K. Koech <44490960+allankoechke@users.noreply.github.com>
This commit is contained in:
v0
2025-06-23 11:46:29 +00:00
parent 0a541fc379
commit b9869a1bca
5 changed files with 306 additions and 227 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-[500px] max-w-[90vw]">
<DrawerHeader>
<DrawerContent side="right" className="w-[700px] max-w-[90vw]">
<DrawerHeader className="border-b">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<Edit className="h-5 w-5" />
@@ -79,11 +79,11 @@ export function EditItemDrawer({ table, item, apiClient, open, onClose, onItemUp
<DrawerDescription>Edit record in {table.name} table</DrawerDescription>
</DrawerHeader>
<ScrollArea className="flex-1 px-6">
<div className="space-y-4">
<ScrollArea className="flex-1">
<div className="p-6 space-y-6">
{table.fields?.map((field) => (
<div key={field.name}>
<Label htmlFor={field.name} className="capitalize">
<div key={field.name} className="space-y-2">
<Label htmlFor={field.name} className="text-sm font-medium capitalize">
{field.name}
{!field.nullable && <span className="text-red-500 ml-1">*</span>}
</Label>
@@ -93,19 +93,19 @@ export function EditItemDrawer({ table, item, apiClient, open, onClose, onItemUp
value={formData[field.name] || ""}
onChange={(e) => handleFieldChange(field.name, e.target.value)}
disabled={isSystemField(field.name)}
className={isSystemField(field.name) ? "bg-muted" : ""}
className={`w-full ${isSystemField(field.name) ? "bg-muted" : ""}`}
placeholder={`Enter ${field.name}`}
/>
{isSystemField(field.name) && (
<p className="text-xs text-muted-foreground mt-1">System field - cannot be modified</p>
<p className="text-xs text-muted-foreground">System field - cannot be modified</p>
)}
</div>
))}
</div>
</ScrollArea>
<DrawerFooter>
<div className="flex gap-2">
<DrawerFooter className="border-t mt-6">
<div className="flex gap-3">
<Button variant="outline" onClick={onClose} className="flex-1">
Cancel
</Button>

View File

@@ -18,6 +18,7 @@ import {
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
import { ScrollArea } from "@/components/ui/scroll-area"
import { Textarea } from "@/components/ui/textarea"
import type { ApiClient, TableMetadata } from "@/lib/api"
interface TableConfigDrawerProps {
@@ -113,8 +114,8 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
return (
<Drawer open={open} onOpenChange={onClose}>
<DrawerContent side="right" className="w-[600px] max-w-[90vw]">
<DrawerHeader>
<DrawerContent side="right" className="w-[800px] max-w-[90vw]">
<DrawerHeader className="border-b">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<Cog className="h-5 w-5" />
@@ -127,87 +128,93 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
<DrawerDescription>Manage table schema and access control rules</DrawerDescription>
</DrawerHeader>
<ScrollArea className="flex-1 px-6">
<Tabs value={activeTab} onValueChange={setActiveTab}>
<TabsList className="grid w-full grid-cols-2">
<TabsTrigger value="schema">Schema</TabsTrigger>
<TabsTrigger value="rules">Access Rules</TabsTrigger>
</TabsList>
<ScrollArea className="flex-1">
<div className="p-6">
<Tabs value={activeTab} onValueChange={setActiveTab}>
<TabsList className="grid w-full grid-cols-2 mb-6">
<TabsTrigger value="schema">Schema</TabsTrigger>
<TabsTrigger value="rules">Access Rules</TabsTrigger>
</TabsList>
<TabsContent value="schema" className="space-y-4 mt-4">
<div className="flex items-center justify-between">
<div>
<h4 className="font-medium">Table Structure</h4>
<p className="text-sm text-muted-foreground">Modify columns and their properties</p>
<TabsContent value="schema" className="space-y-6">
<div className="flex items-center justify-between">
<div>
<h4 className="text-lg font-medium">Table Structure</h4>
<p className="text-sm text-muted-foreground">Modify columns and their properties</p>
</div>
{table.type !== "view" && (
<Button type="button" variant="outline" size="sm" onClick={addColumn}>
<Plus className="h-4 w-4 mr-2" />
Add Column
</Button>
)}
</div>
{table.type !== "view" && (
<Button type="button" variant="outline" size="sm" onClick={addColumn}>
<Plus className="h-4 w-4 mr-2" />
Add Column
</Button>
)}
</div>
{table.type === "view" ? (
<div className="p-4 bg-muted rounded-lg">
<h5 className="font-medium mb-2">SQL Query</h5>
<pre className="text-sm overflow-x-auto">
<code>{table.sql}</code>
</pre>
</div>
) : (
<div className="space-y-3">
{columns.map((column, index) => {
const isSystem = isSystemColumn(column.name)
return (
<div
key={index}
className={`flex flex-col gap-3 p-3 border rounded-lg ${isSystem ? "bg-muted/50" : ""}`}
>
<div className="flex items-center gap-2">
<Input
placeholder="Column name"
value={column.name}
onChange={(e) => updateColumn(index, "name", e.target.value)}
disabled={isSystem}
className={`flex-1 ${isSystem ? "bg-muted" : ""}`}
/>
{isSystem && (
<Badge variant="outline" className="text-xs">
System
</Badge>
)}
<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>
{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">
<code>{table.sql}</code>
</pre>
</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">
<Label className="text-sm font-medium mb-2 block">Column Name</Label>
<div className="flex items-center gap-2">
<Input
placeholder="Column name"
value={column.name}
onChange={(e) => updateColumn(index, "name", e.target.value)}
disabled={isSystem}
className={`flex-1 ${isSystem ? "bg-muted" : ""}`}
/>
{isSystem && (
<Badge variant="outline" className="text-xs">
System
</Badge>
)}
</div>
</div>
<div className="w-40">
<Label className="text-sm font-medium mb-2 block">Data Type</Label>
<Select
value={column.type}
onValueChange={(value) => updateColumn(index, "type", value)}
disabled={isSystem}
>
<SelectTrigger className={isSystem ? "bg-muted" : ""}>
<SelectValue />
</SelectTrigger>
<SelectContent>
{dataTypes.map((type) => (
<SelectItem key={type} value={type}>
{type.toUpperCase()}
</SelectItem>
))}
</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>
<div className="flex items-center gap-2">
<Select
value={column.type}
onValueChange={(value) => updateColumn(index, "type", value)}
disabled={isSystem}
>
<SelectTrigger className={`w-32 ${isSystem ? "bg-muted" : ""}`}>
<SelectValue />
</SelectTrigger>
<SelectContent>
{dataTypes.map((type) => (
<SelectItem key={type} value={type}>
{type.toUpperCase()}
</SelectItem>
))}
</SelectContent>
</Select>
<div className="flex items-center space-x-4">
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
<div className="flex items-center space-x-2">
<input
type="checkbox"
@@ -217,8 +224,8 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
disabled={isSystem}
className="rounded"
/>
<Label htmlFor={`primary-${index}`} className="text-xs">
PK
<Label htmlFor={`primary-${index}`} className="text-sm">
Primary Key
</Label>
</div>
<div className="flex items-center space-x-2">
@@ -230,7 +237,7 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
disabled={isSystem}
className="rounded"
/>
<Label htmlFor={`unique-${index}`} className="text-xs">
<Label htmlFor={`unique-${index}`} className="text-sm">
Unique
</Label>
</div>
@@ -243,7 +250,7 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
disabled={isSystem}
className="rounded"
/>
<Label htmlFor={`required-${index}`} className="text-xs">
<Label htmlFor={`required-${index}`} className="text-sm">
Required
</Label>
</div>
@@ -256,121 +263,142 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
disabled={isSystem}
className="rounded"
/>
<Label htmlFor={`files-${index}`} className="text-xs">
Files
<Label htmlFor={`files-${index}`} className="text-sm">
File Field
</Label>
</div>
</div>
</div>
</div>
)
})}
</div>
)}
{table.type !== "view" && (
<div className="text-sm text-muted-foreground">
<p>
<Badge variant="outline" className="text-xs mr-2">
System
</Badge>
System columns are automatically managed and cannot be modified.
</p>
</div>
)}
</TabsContent>
<TabsContent value="rules" className="space-y-4 mt-4">
<div>
<h4 className="font-medium mb-4">Access Control Rules</h4>
<div className="space-y-4">
<div>
<Label htmlFor="list-rule">List Rule</Label>
<Input
id="list-rule"
placeholder='e.g., "True", "auth.id != None", ""'
value={rules.list}
onChange={(e) => setRules({ ...rules, list: e.target.value })}
/>
<p className="text-xs text-muted-foreground mt-1">Controls who can list records</p>
)
})}
</div>
)}
<div>
<Label htmlFor="get-rule">Get Rule</Label>
<Input
id="get-rule"
placeholder='e.g., "True", "auth.id == record.user_id"'
value={rules.get}
onChange={(e) => setRules({ ...rules, get: e.target.value })}
/>
<p className="text-xs text-muted-foreground mt-1">Controls who can view individual records</p>
</div>
{table.type !== "view" && (
<>
<div>
<Label htmlFor="add-rule">Add Rule</Label>
<Input
id="add-rule"
placeholder='e.g., "auth.id != None", "auth.role == "admin""'
value={rules.add}
onChange={(e) => setRules({ ...rules, add: e.target.value })}
/>
<p className="text-xs text-muted-foreground mt-1">Controls who can create new records</p>
</div>
<div>
<Label htmlFor="update-rule">Update Rule</Label>
<Input
id="update-rule"
placeholder='e.g., "auth.id == record.user_id", ""'
value={rules.update}
onChange={(e) => setRules({ ...rules, update: e.target.value })}
/>
<p className="text-xs text-muted-foreground mt-1">Controls who can update records</p>
</div>
<div>
<Label htmlFor="delete-rule">Delete Rule</Label>
<Input
id="delete-rule"
placeholder='e.g., "auth.role == "admin"", ""'
value={rules.delete}
onChange={(e) => setRules({ ...rules, delete: e.target.value })}
/>
<p className="text-xs text-muted-foreground mt-1">Controls who can delete records</p>
</div>
</>
)}
</div>
<div className="mt-4 p-3 bg-muted rounded-lg">
<h5 className="font-medium mb-2">Rule Examples</h5>
<div className="space-y-1 text-sm text-muted-foreground">
{table.type !== "view" && (
<div className="text-sm text-muted-foreground p-3 bg-muted/50 rounded-lg">
<p>
<code>""</code> - Admin access only
</p>
<p>
<code>"True"</code> - Public access
</p>
<p>
<code>"auth.id != None"</code> - Authenticated users only
</p>
<p>
<code>"auth.id == record.user_id"</code> - Owner access only
</p>
<p>
<code>"auth.role == \"admin\""</code> - Admin role required
<Badge variant="outline" className="text-xs mr-2">
System
</Badge>
System columns are automatically managed and cannot be modified.
</p>
</div>
)}
</TabsContent>
<TabsContent value="rules" className="space-y-6">
<div>
<h4 className="text-lg font-medium mb-4">Access Control Rules</h4>
<div className="space-y-6">
<div>
<Label htmlFor="list-rule" className="text-sm font-medium">
List Rule
</Label>
<Textarea
id="list-rule"
placeholder='e.g., "True", "auth.id != None", ""'
value={rules.list}
onChange={(e) => setRules({ ...rules, list: e.target.value })}
className="mt-2"
rows={2}
/>
<p className="text-xs text-muted-foreground mt-1">Controls who can list records</p>
</div>
<div>
<Label htmlFor="get-rule" className="text-sm font-medium">
Get Rule
</Label>
<Textarea
id="get-rule"
placeholder='e.g., "True", "auth.id == record.user_id"'
value={rules.get}
onChange={(e) => setRules({ ...rules, get: e.target.value })}
className="mt-2"
rows={2}
/>
<p className="text-xs text-muted-foreground mt-1">Controls who can view individual records</p>
</div>
{table.type !== "view" && (
<>
<div>
<Label htmlFor="add-rule" className="text-sm font-medium">
Add Rule
</Label>
<Textarea
id="add-rule"
placeholder='e.g., "auth.id != None", "auth.role == "admin""'
value={rules.add}
onChange={(e) => setRules({ ...rules, add: e.target.value })}
className="mt-2"
rows={2}
/>
<p className="text-xs text-muted-foreground mt-1">Controls who can create new records</p>
</div>
<div>
<Label htmlFor="update-rule" className="text-sm font-medium">
Update Rule
</Label>
<Textarea
id="update-rule"
placeholder='e.g., "auth.id == record.user_id", ""'
value={rules.update}
onChange={(e) => setRules({ ...rules, update: e.target.value })}
className="mt-2"
rows={2}
/>
<p className="text-xs text-muted-foreground mt-1">Controls who can update records</p>
</div>
<div>
<Label htmlFor="delete-rule" className="text-sm font-medium">
Delete Rule
</Label>
<Textarea
id="delete-rule"
placeholder='e.g., "auth.role == "admin"", ""'
value={rules.delete}
onChange={(e) => setRules({ ...rules, delete: e.target.value })}
className="mt-2"
rows={2}
/>
<p className="text-xs text-muted-foreground mt-1">Controls who can delete records</p>
</div>
</>
)}
</div>
<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">
<p>
<code className="bg-background px-2 py-1 rounded">""</code> - Admin access only
</p>
<p>
<code className="bg-background px-2 py-1 rounded">"True"</code> - Public access
</p>
<p>
<code className="bg-background px-2 py-1 rounded">"auth.id != None"</code> - Authenticated
users
</p>
<p>
<code className="bg-background px-2 py-1 rounded">"auth.id == record.user_id"</code> - Owner
only
</p>
</div>
</div>
</div>
</div>
</div>
</TabsContent>
</Tabs>
</TabsContent>
</Tabs>
</div>
</ScrollArea>
<DrawerFooter>
<div className="flex gap-2">
<DrawerFooter className="border-t mt-6">
<div className="flex gap-3">
<Button variant="outline" onClick={onClose} className="flex-1">
Cancel
</Button>

View File

@@ -1,7 +1,7 @@
"use client"
import * as React from "react"
import { FileText, ChevronDown, ChevronRight, X } from "lucide-react"
import { FileText, ChevronDown, ChevronRight, X, Copy } from "lucide-react"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
@@ -19,8 +19,8 @@ interface TableDocsDrawerProps {
export function TableDocsDrawer({ table, open, onClose }: TableDocsDrawerProps) {
return (
<Drawer open={open} onOpenChange={onClose}>
<DrawerContent side="right" className="w-[600px] max-w-[90vw]">
<DrawerHeader>
<DrawerContent side="right" className="w-[900px] max-w-[90vw]">
<DrawerHeader className="border-b">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<FileText className="h-5 w-5" />
@@ -33,8 +33,8 @@ export function TableDocsDrawer({ table, open, onClose }: TableDocsDrawerProps)
<DrawerDescription>Auto-generated API endpoints and examples</DrawerDescription>
</DrawerHeader>
<ScrollArea className="flex-1 px-6 pb-6">
<div className="space-y-4">
<ScrollArea className="flex-1">
<div className="p-6 space-y-6">
<ApiEndpointCard
method="GET"
endpoint={`/api/v1/tables/${table.name}`}
@@ -103,18 +103,22 @@ function ApiEndpointCard({
const getMethodColor = (method: string) => {
switch (method) {
case "GET":
return "bg-green-100 text-green-800"
return "bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200"
case "POST":
return "bg-blue-100 text-blue-800"
return "bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200"
case "PATCH":
return "bg-yellow-100 text-yellow-800"
return "bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200"
case "DELETE":
return "bg-red-100 text-red-800"
return "bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200"
default:
return "bg-gray-100 text-gray-800"
return "bg-gray-100 text-gray-800 dark:bg-gray-900 dark:text-gray-200"
}
}
const copyToClipboard = (text: string) => {
navigator.clipboard.writeText(text)
}
const generateRequestExample = () => {
const baseUrl = "https://your-api.com"
let example = `curl -X ${method} "${baseUrl}${endpoint}"`
@@ -199,59 +203,86 @@ function ApiEndpointCard({
return JSON.stringify(sampleRecord, null, 2)
}
const requestExample = generateRequestExample()
const responseExample = generateResponseExample()
return (
<Collapsible open={isOpen} onOpenChange={setIsOpen}>
<CollapsibleTrigger asChild>
<div className="p-4 border rounded-lg cursor-pointer hover:bg-muted/50 transition-colors">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<Badge className={getMethodColor(method)}>{method}</Badge>
<code className="text-sm">{endpoint}</code>
<div className="flex items-center gap-3">
<Badge className={getMethodColor(method)} variant="secondary">
{method}
</Badge>
<code className="text-sm font-mono bg-muted px-2 py-1 rounded">{endpoint}</code>
{isOpen ? <ChevronDown className="h-4 w-4" /> : <ChevronRight className="h-4 w-4" />}
</div>
</div>
<p className="text-sm text-muted-foreground mt-1">{description}</p>
<p className="text-sm text-muted-foreground mt-2">{description}</p>
</div>
</CollapsibleTrigger>
<CollapsibleContent>
<div className="border-l-2 border-muted ml-4 pl-4 space-y-4">
<div className="border-l-2 border-muted ml-4 pl-6 space-y-6 mt-4">
<div>
<h5 className="font-medium mb-2">Request Example</h5>
<pre className="bg-muted p-3 rounded text-sm overflow-x-auto">
<code>{generateRequestExample()}</code>
<div className="flex items-center justify-between mb-3">
<h5 className="font-medium">Request Example</h5>
<Button variant="outline" size="sm" onClick={() => copyToClipboard(requestExample)} className="h-8">
<Copy className="h-3 w-3 mr-1" />
Copy
</Button>
</div>
<pre className="bg-muted p-4 rounded text-sm overflow-x-auto border">
<code>{requestExample}</code>
</pre>
</div>
<div>
<h5 className="font-medium mb-2">Response Example</h5>
<pre className="bg-muted p-3 rounded text-sm overflow-x-auto">
<code>{generateResponseExample()}</code>
<div className="flex items-center justify-between mb-3">
<h5 className="font-medium">Response Example</h5>
<Button variant="outline" size="sm" onClick={() => copyToClipboard(responseExample)} className="h-8">
<Copy className="h-3 w-3 mr-1" />
Copy
</Button>
</div>
<pre className="bg-muted p-4 rounded text-sm overflow-x-auto border">
<code>{responseExample}</code>
</pre>
</div>
<div>
<h5 className="font-medium mb-2">Possible Errors</h5>
<div className="space-y-2 text-sm">
<h5 className="font-medium mb-3">Possible Errors</h5>
<div className="grid grid-cols-1 md:grid-cols-2 gap-3 text-sm">
<div className="flex items-center gap-2">
<Badge variant="destructive">400</Badge>
<Badge variant="destructive" className="text-xs">
400
</Badge>
<span>Bad Request - Invalid input data</span>
</div>
<div className="flex items-center gap-2">
<Badge variant="destructive">401</Badge>
<Badge variant="destructive" className="text-xs">
401
</Badge>
<span>Unauthorized - Invalid or missing token</span>
</div>
<div className="flex items-center gap-2">
<Badge variant="destructive">403</Badge>
<Badge variant="destructive" className="text-xs">
403
</Badge>
<span>Forbidden - Access denied by rules</span>
</div>
{(operation === "get" || operation === "update" || operation === "delete") && (
<div className="flex items-center gap-2">
<Badge variant="destructive">404</Badge>
<Badge variant="destructive" className="text-xs">
404
</Badge>
<span>Not Found - Record does not exist</span>
</div>
)}
<div className="flex items-center gap-2">
<Badge variant="destructive">500</Badge>
<Badge variant="destructive" className="text-xs">
500
</Badge>
<span>Internal Server Error - Server error</span>
</div>
</div>

View File

@@ -1,7 +1,26 @@
"use client"
import { Toast, ToastClose, ToastDescription, ToastProvider, ToastTitle, ToastViewport } from "@/components/ui/toast"
import { Toast, ToastClose, ToastDescription, ToastProvider, ToastTitle } from "@/components/ui/toast"
import { useToast } from "@/hooks/use-toast"
import * as React from "react"
import * as ToastPrimitives from "@radix-ui/react-toast"
import { cn } from "@/lib/utils"
// Update the ToastViewport positioning for slide-in effect
const CustomToastViewport = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Viewport>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>
>(({ className, ...props }, ref) => (
<ToastPrimitives.Viewport
ref={ref}
className={cn(
"fixed top-4 right-4 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:max-w-[420px]",
className,
)}
{...props}
/>
))
CustomToastViewport.displayName = ToastPrimitives.Viewport.displayName
export function Toaster() {
const { toasts } = useToast()
@@ -18,7 +37,7 @@ export function Toaster() {
<ToastClose />
</Toast>
))}
<ToastViewport />
<CustomToastViewport />
</ToastProvider>
)
}

View File

@@ -5,7 +5,8 @@ import * as React from "react"
import type { ToastActionElement, ToastProps } from "@/components/ui/toast"
const TOAST_LIMIT = 1
const TOAST_REMOVE_DELAY = 1000000
// Update the TOAST_REMOVE_DELAY to show toasts longer
const TOAST_REMOVE_DELAY = 5000
type ToasterToast = ToastProps & {
id: string