Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dashboard): Add default values to workflow editor provider form #6932

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,24 @@ export const WorkflowEditorProvider = ({ children }: { children: ReactNode }) =>
const { currentEnvironment } = useEnvironment();
const { workflowSlug } = useParams<{ workflowSlug?: string }>();
const navigate = useNavigate();
const form = useForm<z.infer<typeof workflowSchema>>({ mode: 'onSubmit', resolver: zodResolver(workflowSchema) });

const { workflow, error } = useFetchWorkflow({
workflowSlug,
});
const defaultFormValues = useMemo(
() => ({ ...workflow, steps: workflow?.steps.map((step) => ({ ...step })) }),
[workflow]
);
const form = useForm<z.infer<typeof workflowSchema>>({
mode: 'onSubmit',
resolver: zodResolver(workflowSchema),
defaultValues: defaultFormValues,
});
const { reset, setError } = form;
const steps = useFieldArray({
control: form.control,
name: 'steps',
});

const { workflow, error } = useFetchWorkflow({
workflowSlug,
});
const isReadOnly = workflow?.origin === WorkflowOriginEnum.EXTERNAL;

useLayoutEffect(() => {
Expand All @@ -79,8 +87,8 @@ export const WorkflowEditorProvider = ({ children }: { children: ReactNode }) =>
return;
}

reset({ ...workflow, steps: workflow.steps.map((step) => ({ ...step })) });
}, [workflow, error, navigate, reset, currentEnvironment]);
reset(defaultFormValues);
}, [workflow, defaultFormValues, error, navigate, reset, currentEnvironment]);

const { updateWorkflow, isPending } = useUpdateWorkflow({
onSuccess: (data) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const WorkflowEditor = () => {

return (
<div className="flex h-full flex-1 flex-nowrap">
<Tabs defaultValue="workflow" className="-mt-[1px] flex h-full flex-1 flex-col" value="workflow">
<Tabs defaultValue="workflow" className="-mt-px flex h-full flex-1 flex-col" value="workflow">
<TabsList variant="regular">
<TabsTrigger value="workflow" asChild variant="regular">
<Link
Expand Down
Loading