More work on editing

This commit is contained in:
brian 2023-11-18 03:10:00 -05:00
parent 38a66ae2b5
commit 491de3481d
2 changed files with 51 additions and 12 deletions

View file

@ -69,31 +69,69 @@ export default function RouteCards({ routes }: { routes: Route[] }) {
} }
export function EditRouteDialog({ route }: { route?: Route }) { export function EditRouteDialog({ route }: { route?: Route }) {
const form = useForm(); const form = useForm({
defaultValues: {
handler: route?.handle[0].handler,
upstreams: route?.handle[0].upstreams,
//hosts: route?.match[0].host,
}
});
let test: RouteHandle = {
handle: [
{
handler: 'subroutes',
routes: [
{
handle: [
{
handler: 'reverse_proxy',
upstreams: [
{
dial: 'localhost:8080'
}
]
}
]
}
]
}
],
match: [
{
host: [
'example.com'
]
}
]
}
let onSubmit = ((data: any) => { let onSubmit = ((data: any) => {
console.log(JSON.stringify(data)) console.log('Original Route', JSON.stringify(route))
console.log(data)
}) })
let targetRoute: Route = route as Route;
return ( return (
<Dialog open={targetRoute != null}> <Dialog open={route as Route != null}>
<DialogContent className='sm:max-w-[425px]'> <DialogContent className='sm:max-w-[425px]'>
<Form {...form}> <Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)}> <form onSubmit={form.handleSubmit(onSubmit)}>
<FormField <FormField
control={form.control} control={form.control}
name="Handler" name="handler"
render={({ field }) => ( render={({ field }) => (
<FormItem> <FormItem>
<FormLabel>Handler</FormLabel> <FormLabel>Handler</FormLabel>
<FormControl> <FormControl>
<Input {...field} defaultValue={route?.handle[0].handler} /> <Input {...field} value={route?.handle[0].handler} />
</FormControl> </FormControl>
</FormItem> </FormItem>
)} )}
></FormField> ></FormField>
{route ? getRouteUpstreams(targetRoute)?.map((upstream, index) => (
{route ? getRouteUpstreams(route)?.map((upstream, index) => (
<FormField <FormField
key={index} key={index}
control={form.control} control={form.control}
@ -102,7 +140,7 @@ export function EditRouteDialog({ route }: { route?: Route }) {
<FormItem> <FormItem>
<FormLabel>Upstream {index + 1}</FormLabel> <FormLabel>Upstream {index + 1}</FormLabel>
<FormControl> <FormControl>
<Input {...field} defaultValue={upstream.dial} /> <Input {...field} value={upstream.dial} />
</FormControl> </FormControl>
</FormItem> </FormItem>
)} )}
@ -110,14 +148,14 @@ export function EditRouteDialog({ route }: { route?: Route }) {
</FormField> </FormField>
)) : <></>} )) : <></>}
{route ? getHosts(targetRoute)?.map((host, index) => ( {route ? getHosts(route)?.map((host, index) => (
<FormField <FormField
key={index} key={index}
control={form.control} control={form.control}
name="upstreams" name="hosts"
render={({ field }) => ( render={({ field }) => (
<FormItem> <FormItem>
<FormLabel>Upstream {index + 1}</FormLabel> <FormLabel>Host {index + 1}</FormLabel>
<FormControl> <FormControl>
<Input {...field} defaultValue={host} /> <Input {...field} defaultValue={host} />
</FormControl> </FormControl>

View file

@ -4,8 +4,9 @@ interface Server {
} }
interface Route { interface Route {
match: Match[];
handle: Handle[]; handle: Handle[];
match: Match[];
terminal?: boolean;
} }
interface Match { interface Match {