11import type { Field , FieldType , SchemaEntity } from "@dafthunk/types" ;
2+ import Asterisk from "lucide-react/icons/asterisk" ;
3+ import Hash from "lucide-react/icons/hash" ;
24import KeyRound from "lucide-react/icons/key-round" ;
35import PlusCircle from "lucide-react/icons/plus-circle" ;
46import Trash2 from "lucide-react/icons/trash-2" ;
@@ -22,7 +24,6 @@ import {
2224 SelectValue ,
2325} from "@/components/ui/select" ;
2426import { Spinner } from "@/components/ui/spinner" ;
25- import { Switch } from "@/components/ui/switch" ;
2627import { Textarea } from "@/components/ui/textarea" ;
2728import {
2829 Tooltip ,
@@ -88,18 +89,43 @@ function FieldEditor({ fields, onChange }: FieldEditorProps) {
8889 return (
8990 < div key = { index } className = "flex items-center gap-2" >
9091 < Input
91- placeholder = "Field name "
92+ placeholder = "Name "
9293 value = { field . name }
93- onChange = { ( e ) => updateField ( index , { name : e . target . value } ) }
94- className = { cn ( "flex-1" , isDuplicate && "border-destructive" ) }
94+ onChange = { ( e ) =>
95+ updateField ( index , { name : e . target . value } )
96+ }
97+ className = { cn (
98+ "flex-1 min-w-0" ,
99+ isDuplicate && "border-destructive"
100+ ) }
101+ />
102+ < Input
103+ placeholder = "Label"
104+ value = { field . label ?? "" }
105+ onChange = { ( e ) =>
106+ updateField ( index , {
107+ label : e . target . value || undefined ,
108+ } )
109+ }
110+ className = "flex-1 min-w-0"
111+ />
112+ < Input
113+ placeholder = "Default value"
114+ value = { field . defaultValue ?? "" }
115+ onChange = { ( e ) =>
116+ updateField ( index , {
117+ defaultValue : e . target . value || undefined ,
118+ } )
119+ }
120+ className = "flex-1 min-w-0"
95121 />
96122 < Select
97123 value = { field . type }
98124 onValueChange = { ( val ) =>
99125 updateField ( index , { type : val as FieldType } )
100126 }
101127 >
102- < SelectTrigger className = "w-32 " >
128+ < SelectTrigger className = "w-28 " >
103129 < SelectValue />
104130 </ SelectTrigger >
105131 < SelectContent >
@@ -110,18 +136,6 @@ function FieldEditor({ fields, onChange }: FieldEditorProps) {
110136 ) ) }
111137 </ SelectContent >
112138 </ Select >
113- < div className = "flex items-center gap-1" >
114- < Switch
115- checked = { field . required ?? false }
116- onCheckedChange = { ( checked ) =>
117- updateField ( index , {
118- required : checked ? true : undefined ,
119- } )
120- }
121- className = "scale-75"
122- />
123- < span className = "text-xs text-muted-foreground" > Req</ span >
124- </ div >
125139 < TooltipProvider >
126140 < Tooltip >
127141 < TooltipTrigger asChild >
@@ -137,7 +151,8 @@ function FieldEditor({ fields, onChange }: FieldEditorProps) {
137151 onChange (
138152 fields . map ( ( f , i ) => ( {
139153 ...f ,
140- primaryKey : i === index ? true : undefined ,
154+ primaryKey :
155+ i === index ? true : undefined ,
141156 } ) )
142157 ) ;
143158 }
@@ -160,6 +175,69 @@ function FieldEditor({ fields, onChange }: FieldEditorProps) {
160175 </ TooltipContent >
161176 </ Tooltip >
162177 </ TooltipProvider >
178+ < TooltipProvider >
179+ < Tooltip >
180+ < TooltipTrigger asChild >
181+ < Button
182+ type = "button"
183+ variant = { field . unique ? "secondary" : "ghost" }
184+ size = "icon"
185+ className = "h-8 w-8 shrink-0"
186+ disabled = { field . primaryKey }
187+ onClick = { ( ) =>
188+ updateField ( index , {
189+ unique : field . unique ? undefined : true ,
190+ } )
191+ }
192+ >
193+ < Hash
194+ className = { cn (
195+ "h-4 w-4" ,
196+ field . unique
197+ ? "text-foreground"
198+ : "text-muted-foreground"
199+ ) }
200+ />
201+ </ Button >
202+ </ TooltipTrigger >
203+ < TooltipContent >
204+ { field . unique
205+ ? "Remove unique constraint"
206+ : "Set as unique" }
207+ </ TooltipContent >
208+ </ Tooltip >
209+ </ TooltipProvider >
210+ < TooltipProvider >
211+ < Tooltip >
212+ < TooltipTrigger asChild >
213+ < Button
214+ type = "button"
215+ variant = { field . required ? "secondary" : "ghost" }
216+ size = "icon"
217+ className = "h-8 w-8 shrink-0"
218+ onClick = { ( ) =>
219+ updateField ( index , {
220+ required : field . required ? undefined : true ,
221+ } )
222+ }
223+ >
224+ < Asterisk
225+ className = { cn (
226+ "h-4 w-4" ,
227+ field . required
228+ ? "text-foreground"
229+ : "text-muted-foreground"
230+ ) }
231+ />
232+ </ Button >
233+ </ TooltipTrigger >
234+ < TooltipContent >
235+ { field . required
236+ ? "Set as optional"
237+ : "Set as required" }
238+ </ TooltipContent >
239+ </ Tooltip >
240+ </ TooltipProvider >
163241 < Button
164242 type = "button"
165243 variant = "ghost"
@@ -232,7 +310,7 @@ export function SchemaDialog({
232310
233311 return (
234312 < Dialog open = { open } onOpenChange = { onOpenChange } >
235- < DialogContent className = "sm:max-w-lg " >
313+ < DialogContent className = "sm:max-w-5xl max-h-[85vh] overflow-y-auto " >
236314 < DialogHeader >
237315 < DialogTitle > { title } </ DialogTitle >
238316 </ DialogHeader >
0 commit comments