Skip to content

Commit 827a45c

Browse files
committed
fix(run-job): navigate to new instance when re-run job button is used
Fixes #1255
1 parent b893a4a commit 827a45c

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

components/results/RerunJobButton.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useState } from "react";
33
import type { InstanceGetResponse, InstanceSummary } from "@squonk/data-manager-client";
44

55
import { Button } from "@mui/material";
6+
import { useRouter } from "next/router";
67

78
import { JobModal } from "../runCards/JobCard/JobModal";
89

@@ -23,6 +24,8 @@ export interface RerunJobButtonProps {
2324
export const RerunJobButton = ({ instance, disabled = false }: RerunJobButtonProps) => {
2425
const [open, setOpen] = useState(false);
2526

27+
const { push } = useRouter();
28+
2629
// If the job id is undefined, it's probably an application which we don't currently let be rerun.
2730
return instance.job_id !== undefined ? (
2831
<>
@@ -36,6 +39,9 @@ export const RerunJobButton = ({ instance, disabled = false }: RerunJobButtonPro
3639
open={open}
3740
projectId={instance.project_id}
3841
onClose={() => setOpen(false)}
42+
onLaunch={(instanceId) =>
43+
push({ pathname: "/results/instance/[instanceId]", query: { instanceId } })
44+
}
3945
/>
4046
)}
4147
</>

components/runCards/ApplicationCard/ApplicationModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const ApplicationModal = ({
5050
const handleCreateInstance = async () => {
5151
if (projectId) {
5252
try {
53-
await createInstance({
53+
const { instance_id: instanceId } = await createInstance({
5454
data: {
5555
debug,
5656
application_id: applicationId,
@@ -62,11 +62,11 @@ export const ApplicationModal = ({
6262
}),
6363
},
6464
});
65+
onLaunch && onLaunch(instanceId);
6566
await queryClient.invalidateQueries({ queryKey: getGetInstancesQueryKey() });
6667
} catch (error) {
6768
enqueueError(error);
6869
} finally {
69-
onLaunch && onLaunch();
7070
onClose();
7171
}
7272
} else {

components/runCards/JobCard/JobModal.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ const validateJobInputs = (required: string[], inputsData: InputData) => {
5353
const inputsDataIsValid = Object.values(inputsData)
5454
.map((inputValue) => {
5555
if (inputValue === undefined) {
56-
return false;
56+
return false; // when does this happen?
5757
}
5858
if (Array.isArray(inputValue)) {
5959
return inputValue.every((v) => v !== "");
6060
}
61+
6162
return inputValue.split("\n").every((v) => v !== "");
6263
})
6364
.every((v) => v);
@@ -118,9 +119,14 @@ export const JobModal = ({
118119

119120
const [inputsData, setInputsData] = useState<InputData>({});
120121

122+
const inputKeys = Object.keys(job?.variables?.inputs?.properties ?? {});
123+
const specInputs = Object.fromEntries(
124+
Object.entries(specVariables ?? {}).filter(([key, _]) => inputKeys.includes(key)),
125+
);
126+
121127
const inputsValid = validateJobInputs(
122128
(job?.variables?.inputs as InputSchema | undefined)?.required ?? [],
123-
Object.keys(inputsData).length > 0 ? inputsData : specVariables ?? {},
129+
Object.keys(inputsData).length > 0 ? inputsData : specInputs,
124130
);
125131

126132
const formRef = useRef<any>();
@@ -140,7 +146,7 @@ export const JobModal = ({
140146
variables: { ...optionsFormData, ...inputsData },
141147
};
142148
try {
143-
await createInstance({
149+
const { instance_id: instanceId } = await createInstance({
144150
data: {
145151
debug,
146152
application_id: job.application.application_id,
@@ -150,13 +156,13 @@ export const JobModal = ({
150156
specification: JSON.stringify(specification),
151157
},
152158
});
159+
onLaunch && onLaunch(instanceId);
153160
await queryClient.invalidateQueries({
154161
queryKey: getGetInstancesQueryKey({ project_id: projectId }),
155162
});
156163
} catch (error) {
157164
enqueueError(error);
158165
} finally {
159-
onLaunch && onLaunch();
160166
onClose();
161167
}
162168
} else {

components/runCards/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ export interface CommonModalProps {
1616
/**
1717
* Called after an instance is created. Optional, skipped if not provided.
1818
*/
19-
onLaunch?: () => void;
19+
onLaunch?: (instanceId: string) => void;
2020
}

0 commit comments

Comments
 (0)