import { getClient } from "@/api/AxiosClient"; import { useCredentialGetter } from "@/hooks/useCredentialGetter"; import { useQuery } from "@tanstack/react-query"; import { useLocation, useParams } from "react-router-dom"; import { RunWorkflowForm } from "./RunWorkflowForm"; import { WorkflowApiResponse } from "./types/workflowTypes"; import { Skeleton } from "@/components/ui/skeleton"; import { ProxyLocation } from "@/api/types"; function WorkflowRunParameters() { const credentialGetter = useCredentialGetter(); const { workflowPermanentId } = useParams(); const location = useLocation(); const { data: workflow, isFetching } = useQuery({ queryKey: ["workflow", workflowPermanentId], queryFn: async () => { const client = await getClient(credentialGetter); return client .get(`/workflows/${workflowPermanentId}`) .then((response) => response.data); }, refetchOnWindowFocus: false, }); const workflowParameters = workflow?.workflow_definition.parameters.filter( (parameter) => parameter.parameter_type === "workflow", ); const proxyLocation = location.state ? (location.state.proxyLocation as ProxyLocation) : null; const initialValues = location.state?.data ? location.state.data : workflowParameters?.reduce( (acc, curr) => { if (curr.workflow_parameter_type === "json") { if (typeof curr.default_value === "string") { acc[curr.key] = curr.default_value; return acc; } if (curr.default_value) { acc[curr.key] = JSON.stringify(curr.default_value, null, 2); return acc; } } if ( curr.default_value && curr.workflow_parameter_type === "boolean" ) { acc[curr.key] = Boolean(curr.default_value); return acc; } if ( curr.default_value === null && curr.workflow_parameter_type === "string" ) { acc[curr.key] = ""; return acc; } if (curr.default_value) { acc[curr.key] = curr.default_value; return acc; } acc[curr.key] = null; return acc; }, {} as Record, ); const header = (

Parameters

Fill the placeholder values that you have linked throughout your workflow.

); if (isFetching) { return (
{header}
); } if (!workflow || !workflowParameters || !initialValues) { return
Workflow not found
; } return (
{header}
); } export { WorkflowRunParameters };