Skip to content

Commit 0430748

Browse files
committed
fix(results-page): fix rerun job functionality when job uses a smiles input
1 parent ff16e12 commit 0430748

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

components/SMILESInput.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ export const SMILESInput = ({
146146
const ketcher = global.ketcher;
147147
try {
148148
const smi = await ketcher?.getSmiles();
149-
console.log(smi);
150149
if (smi !== undefined) {
151150
setSmiles(smi);
152151
setMode("smiles");

components/executionsCards/JobCard/JobInputFields.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import type { Dispatch, ReactNode, SetStateAction } from "react";
2+
import { useState } from "react";
23

34
import { Grid, Typography } from "@mui/material";
45

56
import type { ProjectId } from "../../../hooks/projectHooks";
6-
import { FILE_PROTOCOL } from "../../../utils/app/urls";
7+
import { FILE_PROTOCOL, removeFileProtocolFromInputData } from "../../../utils/app/urls";
78
import { FileSelector } from "../../FileSelector";
89
import type { InputData } from "./JobModal";
910
import { MultipleMoleculeInput } from "./MultipleMoleculeInput";
@@ -51,10 +52,12 @@ export interface JobInputFieldsProps {
5152
export const JobInputFields = ({
5253
projectId,
5354
inputs,
54-
initialValues,
55+
initialValues: initialInitialValues,
5556
inputsData,
5657
onChange,
5758
}: JobInputFieldsProps) => {
59+
// capture initialValue in state as we need to mutate it
60+
const [initialValues, setInitialValues] = useState(initialInitialValues);
5861
return (
5962
<>
6063
{Object.entries(inputs.properties).map(
@@ -67,7 +70,7 @@ export const JobInputFields = ({
6770
multiple={!!multiple}
6871
projectId={projectId}
6972
targetType={type}
70-
value={inputsData[key] || initialValues?.[key]}
73+
value={inputsData[key] || removeFileProtocolFromInputData(initialValues?.[key])}
7174
onSelect={(selection) => onChange({ ...inputsData, [key]: selection })}
7275
/>
7376
</InputSection>
@@ -84,7 +87,16 @@ export const JobInputFields = ({
8487
mimeTypes={mimeTypes}
8588
projectId={projectId}
8689
protocol={FILE_PROTOCOL}
87-
reset={() => onChange({ ...inputsData, [key]: undefined })}
90+
reset={() => {
91+
// when using initialValues (from a previous instance) we have to clean this up
92+
// too if E.g. the file/smiles radio is changed
93+
const updatedInitialValue = { ...initialValues };
94+
delete updatedInitialValue[key];
95+
setInitialValues(updatedInitialValue);
96+
97+
// Then reset current input data
98+
onChange({ ...inputsData, [key]: undefined });
99+
}}
88100
value={inputsData[key] || initialValues?.[key]}
89101
onFileSelect={(selection) => onChange({ ...inputsData, [key]: selection })}
90102
onMoleculesChange={(newValue) =>

components/executionsCards/JobCard/MultipleMoleculeInput.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useRef, useState } from "react";
1+
import { useMemo, useRef, useState } from "react";
22

33
import {
44
Box,
@@ -12,8 +12,7 @@ import {
1212
import { nanoid } from "nanoid";
1313

1414
import { useIsASketcherOpen } from "../../../state/sketcherState";
15-
import type { FILE_PROTOCOL } from "../../../utils/app/urls";
16-
import { addFileProtocol, removeFileProtocol } from "../../../utils/app/urls";
15+
import { addFileProtocol, FILE_PROTOCOL, removeFileProtocol } from "../../../utils/app/urls";
1716
import type { FileSelection, SharedProps } from "../../FileSelector";
1817
import { FileSelector } from "../../FileSelector";
1918
import { SMILESInput } from "../../SMILESInput";
@@ -61,7 +60,17 @@ export const MultipleMoleculeInput = ({
6160
reset,
6261
}: MultipleMoleculeInputProps) => {
6362
const uuid = useRef(nanoid()).current;
64-
const [inputMethod, setInputMethod] = useState<InputMethod>("smiles");
63+
const initialValue = useRef(value).current;
64+
const method = useMemo(() => {
65+
if (typeof initialValue === "string") {
66+
return initialValue.startsWith(FILE_PROTOCOL) ? "files" : "smiles";
67+
}
68+
return initialValue?.map((val) => val.startsWith(FILE_PROTOCOL)).every((v) => v)
69+
? "files"
70+
: "smiles";
71+
}, [initialValue]);
72+
73+
const [inputMethod, setInputMethod] = useState<InputMethod>(method);
6574

6675
return (
6776
<>

utils/app/urls.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* Manage the *file* Protocol used in file selectors
33
*/
44

5+
import type { InputData } from "../../components/executionsCards/JobCard/JobModal";
6+
57
export const FILE_PROTOCOL = "file://";
68

79
/**
@@ -12,4 +14,12 @@ export type FILE_PROTOCOL = typeof FILE_PROTOCOL;
1214
export const removeFileProtocol = (file: string) =>
1315
file.startsWith(FILE_PROTOCOL) ? file.slice(FILE_PROTOCOL.length) : file;
1416

17+
export const removeFileProtocolFromInputData = (file: InputData[string]) => {
18+
if (Array.isArray(file)) {
19+
return file.map(removeFileProtocol);
20+
} else if (typeof file === "string") {
21+
return removeFileProtocol(file);
22+
}
23+
};
24+
1525
export const addFileProtocol = (file: string) => `${FILE_PROTOCOL}${file}`;

0 commit comments

Comments
 (0)