Skip to content

Commit

Permalink
enhance: workflow params form default to empty (#1123)
Browse files Browse the repository at this point in the history
- remove default value for workflow params form
- update style for name/description form

Signed-off-by: Ryan Hopper-Lowe <[email protected]>
  • Loading branch information
ryanhopperlowe authored Jan 6, 2025
1 parent e9744f4 commit 672d8c1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
44 changes: 27 additions & 17 deletions ui/admin/app/components/composed/NameDescriptionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import { useEffect } from "react";
import { useFieldArray, useForm } from "react-hook-form";
import { z } from "zod";

import { cn } from "~/lib/utils";

import { ControlledInput } from "~/components/form/controlledInputs";
import { Button } from "~/components/ui/button";
import { Card } from "~/components/ui/card";
import { Form } from "~/components/ui/form";
import { InputProps } from "~/components/ui/input";

Expand All @@ -31,12 +34,14 @@ export function NameDescriptionForm({
addLabel = "Add",
nameFieldProps,
descriptionFieldProps,
asCard = false,
}: {
defaultValues: Item[];
onChange: (values: Item[]) => void;
addLabel?: string;
nameFieldProps?: InputProps;
descriptionFieldProps?: InputProps;
asCard?: boolean;
}) {
const form = useForm<ParamFormValues>({
resolver: zodResolver(formSchema),
Expand All @@ -59,14 +64,19 @@ export function NameDescriptionForm({
return () => subscription.unsubscribe();
}, [form, onChange]);

const Comp = asCard ? Card : "div";
const isEmpty = paramFields.fields.length === 0;

return (
<Form {...form}>
<div className="flex flex-col gap-4">
<Comp
className={cn("flex flex-col gap-4 fade-in-50", {
"p-4": asCard,
hidden: isEmpty,
})}
>
{paramFields.fields.map((field, i) => (
<div
className="flex gap-2 p-2 bg-secondary rounded-md"
key={field.id}
>
<div className="flex gap-2" key={field.id}>
<ControlledInput
placeholder="Name"
{...nameFieldProps}
Expand All @@ -93,19 +103,19 @@ export function NameDescriptionForm({
</Button>
</div>
))}
</Comp>

<Button
variant="ghost"
className="self-end"
startContent={<PlusIcon />}
type="button"
onClick={() =>
paramFields.append({ name: "", description: "" })
}
>
{addLabel}
</Button>
</div>
<Button
variant="ghost"
className="self-end"
startContent={<PlusIcon />}
type="button"
onClick={() =>
paramFields.append({ name: "", description: "" })
}
>
{addLabel}
</Button>
</Form>
);
}
3 changes: 2 additions & 1 deletion ui/admin/app/components/workflow/ParamsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const convertFrom = (params: ParamValues) => {
})
);

return converted.length ? converted : [{ name: "", description: "" }];
return converted.length ? converted : [];
};

const convertTo = (
Expand Down Expand Up @@ -44,6 +44,7 @@ export function ParamsForm({

return (
<NameDescriptionForm
asCard
addLabel="Add Parameter"
defaultValues={defaultValues}
onChange={(values) => onChange?.({ params: convertTo(values) })}
Expand Down

0 comments on commit 672d8c1

Please sign in to comment.