mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-23 04:18:45 +00:00
feat(destinations): enhance additionalFlags handling in destination settings
- Refactored the `additionalFlags` field to use a structured object format, allowing for better validation and management of flag values. - Replaced the textarea input with a dynamic list of input fields, enabling users to add or remove flags easily. - Updated form handling to accommodate the new structure, ensuring proper data mapping during form submission.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { standardSchemaResolver as zodResolver } from "@hookform/resolvers/standard-schema";
|
import { standardSchemaResolver as zodResolver } from "@hookform/resolvers/standard-schema";
|
||||||
import { PenBoxIcon, PlusIcon } from "lucide-react";
|
import { PenBoxIcon, PlusIcon, Trash2 } from "lucide-react";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useFieldArray, useForm } from "react-hook-form";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { AlertBlock } from "@/components/shared/alert-block";
|
import { AlertBlock } from "@/components/shared/alert-block";
|
||||||
@@ -24,7 +24,6 @@ import {
|
|||||||
FormMessage,
|
FormMessage,
|
||||||
} from "@/components/ui/form";
|
} from "@/components/ui/form";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Textarea } from "@/components/ui/textarea";
|
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
@@ -47,7 +46,9 @@ const addDestination = z.object({
|
|||||||
region: z.string(),
|
region: z.string(),
|
||||||
endpoint: z.string().min(1, "Endpoint is required"),
|
endpoint: z.string().min(1, "Endpoint is required"),
|
||||||
serverId: z.string().optional(),
|
serverId: z.string().optional(),
|
||||||
additionalFlags: z.array(z.string()).optional(),
|
additionalFlags: z
|
||||||
|
.array(z.object({ value: z.string().min(1, "Flag cannot be empty") }))
|
||||||
|
.optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
type AddDestination = z.infer<typeof addDestination>;
|
type AddDestination = z.infer<typeof addDestination>;
|
||||||
@@ -95,6 +96,12 @@ export const HandleDestinations = ({ destinationId }: Props) => {
|
|||||||
},
|
},
|
||||||
resolver: zodResolver(addDestination),
|
resolver: zodResolver(addDestination),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { fields, append, remove } = useFieldArray({
|
||||||
|
control: form.control,
|
||||||
|
name: "additionalFlags",
|
||||||
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (destination) {
|
if (destination) {
|
||||||
form.reset({
|
form.reset({
|
||||||
@@ -105,7 +112,8 @@ export const HandleDestinations = ({ destinationId }: Props) => {
|
|||||||
bucket: destination.bucket,
|
bucket: destination.bucket,
|
||||||
region: destination.region,
|
region: destination.region,
|
||||||
endpoint: destination.endpoint,
|
endpoint: destination.endpoint,
|
||||||
additionalFlags: destination.additionalFlags ?? [],
|
additionalFlags:
|
||||||
|
destination.additionalFlags?.map((f) => ({ value: f })) ?? [],
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
form.reset();
|
form.reset();
|
||||||
@@ -122,7 +130,8 @@ export const HandleDestinations = ({ destinationId }: Props) => {
|
|||||||
region: data.region,
|
region: data.region,
|
||||||
secretAccessKey: data.secretAccessKey,
|
secretAccessKey: data.secretAccessKey,
|
||||||
destinationId: destinationId || "",
|
destinationId: destinationId || "",
|
||||||
additionalFlags: data.additionalFlags ?? [],
|
additionalFlags:
|
||||||
|
data.additionalFlags?.map((f) => f.value) ?? [],
|
||||||
})
|
})
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
toast.success(`Destination ${destinationId ? "Updated" : "Created"}`);
|
toast.success(`Destination ${destinationId ? "Updated" : "Created"}`);
|
||||||
@@ -184,7 +193,8 @@ export const HandleDestinations = ({ destinationId }: Props) => {
|
|||||||
region,
|
region,
|
||||||
secretAccessKey: secretKey,
|
secretAccessKey: secretKey,
|
||||||
serverId,
|
serverId,
|
||||||
additionalFlags: form.getValues("additionalFlags") ?? [],
|
additionalFlags:
|
||||||
|
form.getValues("additionalFlags")?.map((f) => f.value) ?? [],
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
toast.success("Connection Success");
|
toast.success("Connection Success");
|
||||||
@@ -364,33 +374,48 @@ export const HandleDestinations = ({ destinationId }: Props) => {
|
|||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<FormField
|
<div className="flex flex-col gap-2">
|
||||||
control={form.control}
|
<div className="flex items-center justify-between">
|
||||||
name="additionalFlags"
|
<FormLabel>Additional Flags (Optional)</FormLabel>
|
||||||
render={({ field }) => (
|
<Button
|
||||||
<FormItem>
|
type="button"
|
||||||
<FormLabel>Additional Flags (Optional)</FormLabel>
|
variant="ghost"
|
||||||
<FormControl>
|
size="sm"
|
||||||
<Textarea
|
onClick={() => append({ value: "" })}
|
||||||
placeholder={
|
>
|
||||||
"--s3-sign-accept-encoding=false\n--s3-chunk-size=50M"
|
<PlusIcon className="size-4" />
|
||||||
}
|
Add Flag
|
||||||
className="h-20"
|
</Button>
|
||||||
value={(field.value || []).join("\n")}
|
</div>
|
||||||
onChange={(e) =>
|
{fields.map((field, index) => (
|
||||||
field.onChange(
|
<FormField
|
||||||
e.target.value
|
key={field.id}
|
||||||
.split("\n")
|
control={form.control}
|
||||||
.map((f) => f.trim())
|
name={`additionalFlags.${index}.value`}
|
||||||
.filter((f) => f.length > 0),
|
render={({ field }) => (
|
||||||
)
|
<FormItem>
|
||||||
}
|
<div className="flex items-center gap-2">
|
||||||
/>
|
<FormControl>
|
||||||
</FormControl>
|
<Input
|
||||||
<FormMessage />
|
placeholder="--s3-sign-accept-encoding=false"
|
||||||
</FormItem>
|
{...field}
|
||||||
)}
|
/>
|
||||||
/>
|
</FormControl>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => remove(index)}
|
||||||
|
>
|
||||||
|
<Trash2 className="size-4 text-muted-foreground" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<DialogFooter
|
<DialogFooter
|
||||||
|
|||||||
Reference in New Issue
Block a user