refactor(network-form): clean up DriverOptsEntries rendering logic

- Simplified the rendering of DriverOptsEntries in the network form by consolidating the mapping logic.
- Improved formatting of example driver options in the form description for better readability.
- Ensured consistent handling of adding and removing driver options within the form.
This commit is contained in:
Mauricio Siu
2026-02-06 00:19:18 -06:00
parent 97f1105cf4
commit 4f13c25ca2
@@ -104,8 +104,7 @@ export const NetworkForm = ({ id, type }: NetworkFormProps) => {
formData.networks formData.networks
?.filter((network) => network.Target) ?.filter((network) => network.Target)
.map((network) => { .map((network) => {
const entries = const entries = (network.DriverOptsEntries ?? []).filter(
(network.DriverOptsEntries ?? []).filter(
(e) => e.key.trim() !== "", (e) => e.key.trim() !== "",
); );
const driverOpts = const driverOpts =
@@ -194,10 +193,12 @@ export const NetworkForm = ({ id, type }: NetworkFormProps) => {
<div className="space-y-2"> <div className="space-y-2">
<FormLabel>Driver options (optional)</FormLabel> <FormLabel>Driver options (optional)</FormLabel>
<FormDescription> <FormDescription>
e.g. com.docker.network.driver.mtu, com.docker.network.driver.host_binding e.g. com.docker.network.driver.mtu,
com.docker.network.driver.host_binding
</FormDescription> </FormDescription>
{(form.watch(`networks.${index}.DriverOptsEntries`) ?? []).map( {(
(_, optIndex) => ( form.watch(`networks.${index}.DriverOptsEntries`) ?? []
).map((_, optIndex) => (
<div <div
key={optIndex} key={optIndex}
className="flex gap-2 items-end flex-wrap" className="flex gap-2 items-end flex-wrap"
@@ -247,21 +248,19 @@ export const NetworkForm = ({ id, type }: NetworkFormProps) => {
Remove Remove
</Button> </Button>
</div> </div>
), ))}
)}
<Button <Button
type="button" type="button"
variant="outline" variant="outline"
size="sm" size="sm"
onClick={() => { onClick={() => {
const entries = const entries =
form.getValues( form.getValues(`networks.${index}.DriverOptsEntries`) ??
`networks.${index}.DriverOptsEntries`, [];
) ?? []; form.setValue(`networks.${index}.DriverOptsEntries`, [
form.setValue( ...entries,
`networks.${index}.DriverOptsEntries`, { key: "", value: "" },
[...entries, { key: "", value: "" }], ]);
);
}} }}
> >
Add driver option Add driver option