mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-16 00:45:18 +00:00
feat(network-form): add DriverOptsEntries to network form schema and UI
- Introduced DriverOptsEntries to the network form schema, allowing users to specify driver options for networks. - Updated the form UI to support adding, editing, and removing driver options dynamically. - Adjusted the backend schema to accept driver options as a record of key-value pairs.
This commit is contained in:
+114
-7
@@ -16,12 +16,18 @@ import {
|
|||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { api } from "@/utils/api";
|
import { api } from "@/utils/api";
|
||||||
|
|
||||||
|
const driverOptEntrySchema = z.object({
|
||||||
|
key: z.string(),
|
||||||
|
value: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
export const networkFormSchema = z.object({
|
export const networkFormSchema = z.object({
|
||||||
networks: z
|
networks: z
|
||||||
.array(
|
.array(
|
||||||
z.object({
|
z.object({
|
||||||
Target: z.string().optional(),
|
Target: z.string().optional(),
|
||||||
Aliases: z.string().optional(),
|
Aliases: z.string().optional(),
|
||||||
|
DriverOptsEntries: z.array(driverOptEntrySchema).optional(),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.optional(),
|
.optional(),
|
||||||
@@ -80,6 +86,12 @@ export const NetworkForm = ({ id, type }: NetworkFormProps) => {
|
|||||||
const networkEntries = data.networkSwarm.map((network) => ({
|
const networkEntries = data.networkSwarm.map((network) => ({
|
||||||
Target: network.Target || "",
|
Target: network.Target || "",
|
||||||
Aliases: network.Aliases?.join(", ") || "",
|
Aliases: network.Aliases?.join(", ") || "",
|
||||||
|
DriverOptsEntries: network.DriverOpts
|
||||||
|
? Object.entries(network.DriverOpts).map(([key, value]) => ({
|
||||||
|
key,
|
||||||
|
value: value ?? "",
|
||||||
|
}))
|
||||||
|
: [],
|
||||||
}));
|
}));
|
||||||
form.reset({ networks: networkEntries });
|
form.reset({ networks: networkEntries });
|
||||||
}
|
}
|
||||||
@@ -91,12 +103,25 @@ export const NetworkForm = ({ id, type }: NetworkFormProps) => {
|
|||||||
const networksArray =
|
const networksArray =
|
||||||
formData.networks
|
formData.networks
|
||||||
?.filter((network) => network.Target)
|
?.filter((network) => network.Target)
|
||||||
.map((network) => ({
|
.map((network) => {
|
||||||
Target: network.Target,
|
const entries =
|
||||||
Aliases: network.Aliases
|
(network.DriverOptsEntries ?? []).filter(
|
||||||
? network.Aliases.split(",").map((alias) => alias.trim())
|
(e) => e.key.trim() !== "",
|
||||||
: undefined,
|
);
|
||||||
})) || [];
|
const driverOpts =
|
||||||
|
entries.length > 0
|
||||||
|
? Object.fromEntries(
|
||||||
|
entries.map((e) => [e.key.trim(), e.value]),
|
||||||
|
)
|
||||||
|
: undefined;
|
||||||
|
return {
|
||||||
|
Target: network.Target,
|
||||||
|
Aliases: network.Aliases
|
||||||
|
? network.Aliases.split(",").map((alias) => alias.trim())
|
||||||
|
: undefined,
|
||||||
|
DriverOpts: driverOpts,
|
||||||
|
};
|
||||||
|
}) || [];
|
||||||
|
|
||||||
// If no networks, send null to clear the database
|
// If no networks, send null to clear the database
|
||||||
const networksToSend = networksArray.length > 0 ? networksArray : null;
|
const networksToSend = networksArray.length > 0 ? networksArray : null;
|
||||||
@@ -166,6 +191,82 @@ export const NetworkForm = ({ id, type }: NetworkFormProps) => {
|
|||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<FormLabel>Driver options (optional)</FormLabel>
|
||||||
|
<FormDescription>
|
||||||
|
e.g. com.docker.network.driver.mtu, com.docker.network.driver.host_binding
|
||||||
|
</FormDescription>
|
||||||
|
{(form.watch(`networks.${index}.DriverOptsEntries`) ?? []).map(
|
||||||
|
(_, optIndex) => (
|
||||||
|
<div
|
||||||
|
key={optIndex}
|
||||||
|
className="flex gap-2 items-end flex-wrap"
|
||||||
|
>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name={`networks.${index}.DriverOptsEntries.${optIndex}.key`}
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem className="flex-1 min-w-[140px]">
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
placeholder="com.docker.network.driver.mtu"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name={`networks.${index}.DriverOptsEntries.${optIndex}.value`}
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem className="flex-1 min-w-[100px]">
|
||||||
|
<FormControl>
|
||||||
|
<Input {...field} placeholder="1500" />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
const entries =
|
||||||
|
form.getValues(
|
||||||
|
`networks.${index}.DriverOptsEntries`,
|
||||||
|
) ?? [];
|
||||||
|
form.setValue(
|
||||||
|
`networks.${index}.DriverOptsEntries`,
|
||||||
|
entries.filter((_, i) => i !== optIndex),
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Remove
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
)}
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
const entries =
|
||||||
|
form.getValues(
|
||||||
|
`networks.${index}.DriverOptsEntries`,
|
||||||
|
) ?? [];
|
||||||
|
form.setValue(
|
||||||
|
`networks.${index}.DriverOptsEntries`,
|
||||||
|
[...entries, { key: "", value: "" }],
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Add driver option
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="destructive"
|
variant="destructive"
|
||||||
@@ -180,7 +281,13 @@ export const NetworkForm = ({ id, type }: NetworkFormProps) => {
|
|||||||
type="button"
|
type="button"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => append({ Target: "", Aliases: "" })}
|
onClick={() =>
|
||||||
|
append({
|
||||||
|
Target: "",
|
||||||
|
Aliases: "",
|
||||||
|
DriverOptsEntries: [],
|
||||||
|
})
|
||||||
|
}
|
||||||
>
|
>
|
||||||
Add Network
|
Add Network
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ export const NetworkSwarmSchema = z.array(
|
|||||||
.object({
|
.object({
|
||||||
Target: z.string().optional(),
|
Target: z.string().optional(),
|
||||||
Aliases: z.array(z.string()).optional(),
|
Aliases: z.array(z.string()).optional(),
|
||||||
DriverOpts: z.object({}).optional(),
|
DriverOpts: z.record(z.string()).optional(),
|
||||||
})
|
})
|
||||||
.strict(),
|
.strict(),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user