Skip to content

Commit 54ce29a

Browse files
committed
fix: fix workflows with options
1 parent 39e35ac commit 54ce29a

File tree

4 files changed

+41
-21
lines changed

4 files changed

+41
-21
lines changed

src/components/runCards/JobCard/JobModal.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,17 @@ export const JobModal = ({
6969
const queryClient = useQueryClient();
7070
const { enqueueError, enqueueSnackbar } = useEnqueueError<DmError>();
7171

72-
const [nameState, setNameState] = useState(instance?.name ?? "");
7372
const [debug, setDebug] = useState<DebugValue>("0");
7473

7574
const { mutateAsync: createInstance } = useCreateInstance();
7675
// Get extra details about the job
7776
const { data: job } = useGetJob(jobId, undefined, {
7877
query: { retry: jobId === TEST_JOB_ID ? 1 : 3 },
7978
});
80-
const name = nameState || (job?.job ?? "");
79+
const [nameState, setNameState] = useState(instance?.name ?? "");
80+
useEffect(() => {
81+
job?.name && setNameState(job.name);
82+
}, [job?.name]);
8183

8284
const spec = instance?.application_specification;
8385
const specVariables = useMemo(
@@ -136,7 +138,7 @@ export const JobModal = ({
136138
debug,
137139
application_id: job.application.application_id,
138140
// application_version: job.application.latest_version,
139-
as_name: name,
141+
as_name: nameState,
140142
project_id: projectId,
141143
specification: JSON.stringify(specification),
142144
},
@@ -174,7 +176,7 @@ export const JobModal = ({
174176
<TextField
175177
fullWidth
176178
label="Job name"
177-
value={name} // Give a default instance name of job.job
179+
value={nameState} // Give a default instance name of job.job
178180
onChange={(event) => setNameState(event.target.value)}
179181
/>
180182
</Box>

src/components/runCards/WorkflowCard/RunWorkflowButton.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import dynamic from "next/dynamic";
77

88
export interface RunWorkflowButtonProps {
99
workflowId: WorkflowSummary["id"];
10+
name: WorkflowSummary["name"];
1011
projectId: string;
1112
onLaunch?: (instanceId: string) => void;
1213
disabled?: boolean;
@@ -22,6 +23,7 @@ const WorkflowModal = dynamic<any>(
2223
*/
2324
export const RunWorkflowButton = ({
2425
workflowId,
26+
name,
2527
projectId,
2628
onLaunch,
2729
disabled,
@@ -47,6 +49,7 @@ export const RunWorkflowButton = ({
4749
</Tooltip>
4850
{!!hasOpened && (
4951
<WorkflowModal
52+
name={name}
5053
open={open}
5154
projectId={projectId}
5255
workflowId={workflowId}

src/components/runCards/WorkflowCard/WorkflowCard.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const WorkflowCard = ({ workflow }: WorkflowCardProps) => {
2020
actions={() => (
2121
<RunWorkflowButton
2222
disabled={!projectId}
23+
name={workflow.workflow_name ?? workflow.name}
2324
projectId={projectId ?? ""}
2425
workflowId={workflow.id}
2526
/>

src/components/runCards/WorkflowCard/WorkflowModal.tsx

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { useRef, useState } from "react";
1+
import { useEffect, useRef, useState } from "react";
22

3+
import { type DmError } from "@squonk/data-manager-client";
34
import { useGetWorkflow, useRunWorkflow } from "@squonk/data-manager-client/workflow";
45

56
import { Box, TextField } from "@mui/material";
67

8+
import { useEnqueueError } from "../../../hooks/useEnqueueStackError";
79
import { ModalWrapper } from "../../modals/ModalWrapper";
810
import { DebugCheckbox, type DebugValue } from "../DebugCheckbox";
911
import { JobInputsAndOptionsForm } from "../JobCard/JobInputsAndOptionsForm";
@@ -21,10 +23,17 @@ export interface WorkflowModalProps {
2123
* Modal for running a workflow instance. Fetches workflow details and displays the correct form.
2224
*/
2325
export const WorkflowModal = ({ workflowId, projectId, open, onClose }: WorkflowModalProps) => {
26+
const { enqueueError } = useEnqueueError<DmError>();
27+
2428
const { data: workflow } = useGetWorkflow(workflowId);
2529
const specVariables = workflow?.variables;
2630

2731
const [nameState, setNameState] = useState("");
32+
33+
useEffect(() => {
34+
workflow?.workflow_name && setNameState(workflow.workflow_name);
35+
}, [workflow?.workflow_name]);
36+
2837
const [debug, setDebug] = useState<DebugValue>("0");
2938

3039
const [inputsData, setInputsData] = useState<InputData>({});
@@ -34,21 +43,23 @@ export const WorkflowModal = ({ workflowId, projectId, open, onClose }: Workflow
3443

3544
const { mutateAsync: runWorkflow } = useRunWorkflow();
3645

37-
console.log(specVariables);
38-
console.log(inputsData);
39-
4046
const handleSubmit = async () => {
41-
workflow?.id &&
42-
(await runWorkflow({
43-
workflowId: workflow.id,
44-
data: {
45-
as_name: nameState,
46-
debug,
47-
project_id: projectId,
48-
variables: JSON.stringify({ ...optionsFormData, ...inputsData }),
49-
},
50-
}));
51-
onClose();
47+
try {
48+
workflow?.id &&
49+
(await runWorkflow({
50+
workflowId: workflow.id,
51+
data: {
52+
as_name: nameState,
53+
debug,
54+
project_id: projectId,
55+
variables: JSON.stringify({ ...optionsFormData, ...inputsData }),
56+
},
57+
}));
58+
} catch (error) {
59+
enqueueError(error);
60+
} finally {
61+
onClose();
62+
}
5263
};
5364

5465
return (
@@ -67,7 +78,10 @@ export const WorkflowModal = ({ workflowId, projectId, open, onClose }: Workflow
6778
fullWidth
6879
label="Workflow name"
6980
value={nameState}
70-
onChange={(event) => setNameState(event.target.value)}
81+
onChange={(event) => {
82+
console.log(event.target.value);
83+
return setNameState(event.target.value);
84+
}}
7185
/>
7286
</Box>
7387

@@ -79,7 +93,7 @@ export const WorkflowModal = ({ workflowId, projectId, open, onClose }: Workflow
7993
inputsData={inputsData}
8094
options={specVariables?.options}
8195
optionsFormData={optionsFormData}
82-
order={[]}
96+
order={(specVariables?.options as any).properties}
8397
projectId={projectId}
8498
setInputsData={setInputsData}
8599
setOptionsFormData={setOptionsFormData}

0 commit comments

Comments
 (0)