Skip to content

Commit 8d2b6b0

Browse files
committed
fix(run-job): show error message correctly when empty smiles entries are used
1 parent ad75496 commit 8d2b6b0

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

components/runCards/JobCard/JobInputFields.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ import { FileSelector } from "../../FileSelector";
99
import type { InputData } from "./JobModal";
1010
import { MultipleMoleculeInput } from "./MultipleMoleculeInput";
1111

12+
export const validateInputData = (inputValue: string | string[] | undefined) => {
13+
if (inputValue === undefined) {
14+
return false; // when does this happen?
15+
}
16+
if (Array.isArray(inputValue)) {
17+
return inputValue.every((v) => v !== "");
18+
}
19+
20+
return inputValue.split("\n").every((v) => v !== "");
21+
};
22+
1223
// Define types for the form schema as the Open API spec doesn't define these (just gives string)
1324
// These might be defined in the form generator types?
1425
export interface InputFieldSchema {
@@ -67,7 +78,9 @@ export const JobInputFields = ({
6778
const value = inputsData[key] || removeFileProtocolFromInputData(initialValues?.[key]);
6879
return (
6980
<InputSection
70-
error={required && !value ? "must have required input" : undefined}
81+
error={
82+
required && !validateInputData(value) ? "must have required input" : undefined
83+
}
7184
key={key}
7285
required={required}
7386
title={title}
@@ -93,7 +106,9 @@ export const JobInputFields = ({
93106

94107
return (
95108
<InputSection
96-
error={required && !value ? "must have required input" : undefined}
109+
error={
110+
required && !validateInputData(value) ? "must have required input" : undefined
111+
}
97112
key={key}
98113
required={required}
99114
title={title}

components/runCards/JobCard/JobModal.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { ModalWrapper } from "../../modals/ModalWrapper";
2121
import type { DebugValue } from "../DebugCheckbox";
2222
import { DebugCheckbox } from "../DebugCheckbox";
2323
import type { CommonModalProps } from "../types";
24-
import type { InputSchema, JobInputFieldsProps } from "./JobInputFields";
24+
import { type InputSchema, type JobInputFieldsProps, validateInputData } from "./JobInputFields";
2525

2626
const JobInputFields = dynamic<JobInputFieldsProps>(
2727
() => import("./JobInputFields").then((mod) => mod.JobInputFields),
@@ -51,16 +51,7 @@ export interface JobModalProps extends CommonModalProps {
5151

5252
const validateJobInputs = (required: string[], inputsData: InputData) => {
5353
const inputsDataIsValid = Object.values(inputsData)
54-
.map((inputValue) => {
55-
if (inputValue === undefined) {
56-
return false; // when does this happen?
57-
}
58-
if (Array.isArray(inputValue)) {
59-
return inputValue.every((v) => v !== "");
60-
}
61-
62-
return inputValue.split("\n").every((v) => v !== "");
63-
})
54+
.map(validateInputData)
6455
.every((v) => v);
6556

6657
const inputKeys = new Set(Object.keys(inputsData));

0 commit comments

Comments
 (0)