Skip to content

Commit b6a710c

Browse files
committed
fix(sketcher): imrpove layout of buttons when sketcher is open
1 parent 7b6b4a8 commit b6a710c

File tree

2 files changed

+51
-42
lines changed

2 files changed

+51
-42
lines changed

components/SMILESInput.tsx

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect, useState } from "react";
22

3-
import { Edit as EditIcon } from "@mui/icons-material";
4-
import { Box, Button, IconButton, TextField, Tooltip } from "@mui/material";
3+
import { DeleteForever as DeleteForeverIcon, Edit as EditIcon } from "@mui/icons-material";
4+
import { Box, Button, ButtonGroup, IconButton, TextField, Tooltip } from "@mui/material";
55
import { captureException } from "@sentry/nextjs";
66
import dynamic from "next/dynamic";
77

@@ -21,11 +21,16 @@ export interface SMILESInputProps {
2121
*/
2222
value: string;
2323
/**
24-
* called when the the sketcher is closed and saved
24+
* called when the sketcher is closed and saved
2525
* @param smiles the new smiles value
2626
* @returns nothing
2727
*/
2828
onSave: (smiles: string) => void;
29+
/**
30+
* called when the delete button is clicked
31+
* @returns nothing
32+
*/
33+
onDelete: () => void;
2934
/**
3035
* whether the sketcher is displayed by default or not
3136
*/
@@ -47,10 +52,11 @@ export interface SMILESInputProps {
4752
*/
4853
export const SMILESInput = ({
4954
value,
50-
onSave,
5155
initialMode = "smiles",
52-
width = "500px",
56+
width = "700px",
5357
height = "500px",
58+
onSave,
59+
onDelete,
5460
}: SMILESInputProps) => {
5561
const { enqueueError } = useEnqueueError();
5662

@@ -65,6 +71,9 @@ export const SMILESInput = ({
6571
if (mode === "smiles") {
6672
return (
6773
<>
74+
<IconButton sx={{ mr: 1 }} onClick={onDelete}>
75+
<DeleteForeverIcon />
76+
</IconButton>
6877
<TextField label="SMILES" value={smiles} onChange={(event) => onSave(event.target.value)} />
6978
<Tooltip title="Use a molecule sketcher">
7079
<IconButton sx={{ ml: 1 }} onClick={() => setMode("sketcher")}>
@@ -76,35 +85,42 @@ export const SMILESInput = ({
7685
}
7786

7887
return (
79-
<>
80-
<Box height={height} width={width}>
88+
<Box display="flex" flexDirection="column" gap={1} width={width}>
89+
<Box height={height}>
8190
<Sketcher smiles={smiles} />
8291
</Box>
83-
84-
<Button
85-
onClick={async () => {
86-
const ketcher = global.ketcher;
87-
try {
88-
const smi = await ketcher?.getSmiles();
89-
if (smi) {
90-
setSmiles(smi);
91-
setMode("smiles");
92-
onSave(smi);
93-
global.ketcher = undefined;
94-
} else {
95-
enqueueError("Smiles not obtained");
96-
}
97-
} catch (error) {
98-
if (error !== undefined) {
99-
console.error(error);
100-
enqueueError(getErrorMessage(error));
101-
captureException(error);
92+
<ButtonGroup size="small" sx={{ alignSelf: "end" }} variant="outlined">
93+
<Button color="warning" onClick={onDelete}>
94+
Delete
95+
</Button>
96+
<Button color="info" onClick={() => setMode("smiles")}>
97+
Cancel
98+
</Button>
99+
<Button
100+
onClick={async () => {
101+
const ketcher = global.ketcher;
102+
try {
103+
const smi = await ketcher?.getSmiles();
104+
if (smi) {
105+
setSmiles(smi);
106+
setMode("smiles");
107+
onSave(smi);
108+
global.ketcher = undefined;
109+
} else {
110+
enqueueError("Smiles not obtained");
111+
}
112+
} catch (error) {
113+
if (error !== undefined) {
114+
console.error(error);
115+
enqueueError(getErrorMessage(error));
116+
captureException(error);
117+
}
102118
}
103-
}
104-
}}
105-
>
106-
Save
107-
</Button>
108-
</>
119+
}}
120+
>
121+
Save
122+
</Button>
123+
</ButtonGroup>
124+
</Box>
109125
);
110126
};

components/executionsCards/JobCard/MultipleMoleculeInput.tsx

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

3-
import { Clear as RemoveIcon } from "@mui/icons-material";
43
import {
54
Box,
65
Button,
76
FormControl,
87
FormControlLabel,
98
FormLabel,
10-
IconButton,
119
Radio,
1210
RadioGroup,
1311
} from "@mui/material";
@@ -118,18 +116,13 @@ export const SketcherInputs = ({ value, onMoleculesChange }: SketcherInputsProps
118116
<>
119117
{valueArray.map((smiles, index) => (
120118
<Box key={index} mb={2}>
121-
<IconButton
122-
sx={{ mr: 1 }}
123-
onClick={() => {
119+
<SMILESInput
120+
value={smiles}
121+
onDelete={() => {
124122
const newValue = [...valueArray];
125123
newValue.splice(index, 1);
126124
onMoleculesChange(newValue);
127125
}}
128-
>
129-
<RemoveIcon />
130-
</IconButton>
131-
<SMILESInput
132-
value={smiles}
133126
onSave={(smi) => {
134127
const newValue = [...valueArray];
135128
newValue[index] = smi;

0 commit comments

Comments
 (0)