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, WorkflowParameterValueType, } from "./types/workflowTypes"; function defaultValue(type: WorkflowParameterValueType) { switch (type) { case "string": return ""; case "integer": return 0; case "float": return 0.0; case "boolean": return false; case "json": return null; case "file_url": return null; } } 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); }, }); const workflowParameters = workflow?.workflow_definition.parameters.filter( (parameter) => parameter.parameter_type === "workflow", ); 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) { acc[curr.key] = curr.default_value; return acc; } acc[curr.key] = defaultValue(curr.workflow_parameter_type); return acc; }, {} as Record, ); if (isFetching) { return
Getting workflow parameters...
; } if (!workflow || !workflowParameters || !initialValues) { return
Workflow not found
; } return (

Run Parameters

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

); } export { WorkflowRunParameters };