mirror of
https://github.com/allankoechke/mantisbase-admin.git
synced 2026-11-30 10:19:37 +00:00
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:
@@ -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,32 +79,36 @@ export function EditItemDrawer({ table, item, apiClient, open, onClose, onItemUp
|
||||
<DrawerDescription>Edit record in {table.name} table</DrawerDescription>
|
||||
</DrawerHeader>
|
||||
|
||||
<ScrollArea className="flex-1">
|
||||
<div className="p-6 space-y-6">
|
||||
{table.fields?.map((field) => (
|
||||
<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>
|
||||
<Input
|
||||
id={field.name}
|
||||
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)}
|
||||
className={`w-full ${isSystemField(field.name) ? "bg-muted" : ""}`}
|
||||
placeholder={`Enter ${field.name}`}
|
||||
/>
|
||||
{isSystemField(field.name) && (
|
||||
<p className="text-xs text-muted-foreground">System field - cannot be modified</p>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
<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">
|
||||
<Label htmlFor={field.name} className="text-sm font-medium capitalize">
|
||||
{field.name}
|
||||
{!field.nullable && <span className="text-red-500 ml-1">*</span>}
|
||||
</Label>
|
||||
<Input
|
||||
id={field.name}
|
||||
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)}
|
||||
className={`w-full ${isSystemField(field.name) ? "bg-muted" : ""}`}
|
||||
placeholder={`Enter ${field.name}`}
|
||||
/>
|
||||
{isSystemField(field.name) && (
|
||||
<p className="text-xs text-muted-foreground">System field - cannot be modified</p>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</div>
|
||||
|
||||
<DrawerFooter className="border-t mt-6">
|
||||
<DrawerFooter>
|
||||
<div className="flex gap-3">
|
||||
<Button variant="outline" onClick={onClose} className="flex-1">
|
||||
Cancel
|
||||
|
||||
@@ -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,276 +129,327 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
|
||||
<DrawerDescription>Manage table schema and access control rules</DrawerDescription>
|
||||
</DrawerHeader>
|
||||
|
||||
<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>
|
||||
<div className="flex-1 overflow-hidden">
|
||||
<ScrollArea className="h-full">
|
||||
<div className="p-6">
|
||||
<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>
|
||||
</TabsList>
|
||||
|
||||
<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" ? (
|
||||
<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="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
<div className="flex items-center space-x-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
id={`primary-${index}`}
|
||||
checked={column.primaryKey}
|
||||
onChange={(e) => updateColumn(index, "primaryKey", e.target.checked)}
|
||||
disabled={isSystem}
|
||||
className="rounded"
|
||||
/>
|
||||
<Label htmlFor={`primary-${index}`} className="text-sm">
|
||||
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"
|
||||
id={`required-${index}`}
|
||||
checked={!column.nullable}
|
||||
onChange={(e) => updateColumn(index, "nullable", !e.target.checked)}
|
||||
disabled={isSystem}
|
||||
className="rounded"
|
||||
/>
|
||||
<Label htmlFor={`required-${index}`} className="text-sm">
|
||||
Required
|
||||
</Label>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
id={`files-${index}`}
|
||||
checked={column.isFile || false}
|
||||
onChange={(e) => updateColumn(index, "isFile", e.target.checked)}
|
||||
disabled={isSystem}
|
||||
className="rounded"
|
||||
/>
|
||||
<Label htmlFor={`files-${index}`} className="text-sm">
|
||||
File Field
|
||||
</Label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{table.type !== "view" && (
|
||||
<div className="text-sm text-muted-foreground p-3 bg-muted/50 rounded-lg">
|
||||
<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-6">
|
||||
<div>
|
||||
<h4 className="text-lg font-medium mb-4">Access Control Rules</h4>
|
||||
<div className="space-y-6">
|
||||
<TabsContent value="schema" className="space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<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>
|
||||
<h4 className="text-lg font-medium">Table Structure</h4>
|
||||
<p className="text-sm text-muted-foreground">Modify columns and their properties</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>
|
||||
</>
|
||||
<Button type="button" variant="outline" size="sm" onClick={addColumn}>
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
Add Column
|
||||
</Button>
|
||||
)}
|
||||
</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>
|
||||
{table.type === "view" ? (
|
||||
<div className="p-4 bg-muted rounded-lg">
|
||||
<h5 className="font-medium mb-3">SQL Query</h5>
|
||||
<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={`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
|
||||
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>
|
||||
<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>
|
||||
|
||||
{/* Basic Properties */}
|
||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
<div className="flex items-center space-x-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
id={`primary-${index}`}
|
||||
checked={column.primaryKey}
|
||||
onChange={(e) => updateColumn(index, "primaryKey", e.target.checked)}
|
||||
disabled={isSystem}
|
||||
className="rounded"
|
||||
/>
|
||||
<Label htmlFor={`primary-${index}`} className="text-sm">
|
||||
Primary Key
|
||||
</Label>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
id={`required-${index}`}
|
||||
checked={!column.nullable}
|
||||
onChange={(e) => updateColumn(index, "nullable", !e.target.checked)}
|
||||
disabled={isSystem}
|
||||
className="rounded"
|
||||
/>
|
||||
<Label htmlFor={`required-${index}`} className="text-sm">
|
||||
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"
|
||||
id={`files-${index}`}
|
||||
checked={column.isFile || false}
|
||||
onChange={(e) => updateColumn(index, "isFile", e.target.checked)}
|
||||
disabled={isSystem}
|
||||
className="rounded"
|
||||
/>
|
||||
<Label htmlFor={`files-${index}`} className="text-sm">
|
||||
File Field
|
||||
</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>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{table.type !== "view" && (
|
||||
<div className="text-sm text-muted-foreground p-3 bg-muted/50 rounded-lg">
|
||||
<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-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={3}
|
||||
/>
|
||||
<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={3}
|
||||
/>
|
||||
<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={3}
|
||||
/>
|
||||
<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={3}
|
||||
/>
|
||||
<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={3}
|
||||
/>
|
||||
<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 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 only
|
||||
</p>
|
||||
<p>
|
||||
<code className="bg-background px-2 py-1 rounded">"auth.id == record.user_id"</code> - Owner
|
||||
access only
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</TabsContent>
|
||||
</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
|
||||
|
||||
@@ -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,53 +33,55 @@ export function TableDocsDrawer({ table, open, onClose }: TableDocsDrawerProps)
|
||||
<DrawerDescription>Auto-generated API endpoints and examples</DrawerDescription>
|
||||
</DrawerHeader>
|
||||
|
||||
<ScrollArea className="flex-1">
|
||||
<div className="p-6 space-y-6">
|
||||
<ApiEndpointCard
|
||||
method="GET"
|
||||
endpoint={`/api/v1/tables/${table.name}`}
|
||||
description={`List all records in the ${table.name} table`}
|
||||
table={table}
|
||||
operation="list"
|
||||
/>
|
||||
<div className="flex-1 overflow-hidden">
|
||||
<ScrollArea className="h-full">
|
||||
<div className="p-6 space-y-6">
|
||||
<ApiEndpointCard
|
||||
method="GET"
|
||||
endpoint={`/api/v1/tables/${table.name}`}
|
||||
description={`List all records in the ${table.name} table`}
|
||||
table={table}
|
||||
operation="list"
|
||||
/>
|
||||
|
||||
<ApiEndpointCard
|
||||
method="GET"
|
||||
endpoint={`/api/v1/tables/${table.name}/{id}`}
|
||||
description="Get a specific record by ID"
|
||||
table={table}
|
||||
operation="get"
|
||||
/>
|
||||
<ApiEndpointCard
|
||||
method="GET"
|
||||
endpoint={`/api/v1/tables/${table.name}/{id}`}
|
||||
description="Get a specific record by ID"
|
||||
table={table}
|
||||
operation="get"
|
||||
/>
|
||||
|
||||
{table.type !== "view" && (
|
||||
<>
|
||||
<ApiEndpointCard
|
||||
method="POST"
|
||||
endpoint={`/api/v1/tables/${table.name}`}
|
||||
description="Create a new record"
|
||||
table={table}
|
||||
operation="create"
|
||||
/>
|
||||
{table.type !== "view" && (
|
||||
<>
|
||||
<ApiEndpointCard
|
||||
method="POST"
|
||||
endpoint={`/api/v1/tables/${table.name}`}
|
||||
description="Create a new record"
|
||||
table={table}
|
||||
operation="create"
|
||||
/>
|
||||
|
||||
<ApiEndpointCard
|
||||
method="PATCH"
|
||||
endpoint={`/api/v1/tables/${table.name}/{id}`}
|
||||
description="Update a specific record"
|
||||
table={table}
|
||||
operation="update"
|
||||
/>
|
||||
<ApiEndpointCard
|
||||
method="PATCH"
|
||||
endpoint={`/api/v1/tables/${table.name}/{id}`}
|
||||
description="Update a specific record"
|
||||
table={table}
|
||||
operation="update"
|
||||
/>
|
||||
|
||||
<ApiEndpointCard
|
||||
method="DELETE"
|
||||
endpoint={`/api/v1/tables/${table.name}/{id}`}
|
||||
description="Delete a specific record"
|
||||
table={table}
|
||||
operation="delete"
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
<ApiEndpointCard
|
||||
method="DELETE"
|
||||
endpoint={`/api/v1/tables/${table.name}/{id}`}
|
||||
description="Delete a specific record"
|
||||
table={table}
|
||||
operation="delete"
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</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">
|
||||
<code>{requestExample}</code>
|
||||
</pre>
|
||||
<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">
|
||||
<code>{responseExample}</code>
|
||||
</pre>
|
||||
<ScrollArea className="h-48">
|
||||
<pre className="bg-muted p-4 rounded text-sm border">
|
||||
<code>{responseExample}</code>
|
||||
</pre>
|
||||
</ScrollArea>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user