1
1
import { useEffect , useState } from "react" ;
2
2
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" ;
5
5
import { captureException } from "@sentry/nextjs" ;
6
6
import dynamic from "next/dynamic" ;
7
7
@@ -21,11 +21,16 @@ export interface SMILESInputProps {
21
21
*/
22
22
value : string ;
23
23
/**
24
- * called when the the sketcher is closed and saved
24
+ * called when the sketcher is closed and saved
25
25
* @param smiles the new smiles value
26
26
* @returns nothing
27
27
*/
28
28
onSave : ( smiles : string ) => void ;
29
+ /**
30
+ * called when the delete button is clicked
31
+ * @returns nothing
32
+ */
33
+ onDelete : ( ) => void ;
29
34
/**
30
35
* whether the sketcher is displayed by default or not
31
36
*/
@@ -47,10 +52,11 @@ export interface SMILESInputProps {
47
52
*/
48
53
export const SMILESInput = ( {
49
54
value,
50
- onSave,
51
55
initialMode = "smiles" ,
52
- width = "500px " ,
56
+ width = "700px " ,
53
57
height = "500px" ,
58
+ onSave,
59
+ onDelete,
54
60
} : SMILESInputProps ) => {
55
61
const { enqueueError } = useEnqueueError ( ) ;
56
62
@@ -65,6 +71,9 @@ export const SMILESInput = ({
65
71
if ( mode === "smiles" ) {
66
72
return (
67
73
< >
74
+ < IconButton sx = { { mr : 1 } } onClick = { onDelete } >
75
+ < DeleteForeverIcon />
76
+ </ IconButton >
68
77
< TextField label = "SMILES" value = { smiles } onChange = { ( event ) => onSave ( event . target . value ) } />
69
78
< Tooltip title = "Use a molecule sketcher" >
70
79
< IconButton sx = { { ml : 1 } } onClick = { ( ) => setMode ( "sketcher" ) } >
@@ -76,35 +85,42 @@ export const SMILESInput = ({
76
85
}
77
86
78
87
return (
79
- < >
80
- < Box height = { height } width = { width } >
88
+ < Box display = "flex" flexDirection = "column" gap = { 1 } width = { width } >
89
+ < Box height = { height } >
81
90
< Sketcher smiles = { smiles } />
82
91
</ 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
+ }
102
118
}
103
- }
104
- } }
105
- >
106
- Save
107
- </ Button >
108
- </ >
119
+ } }
120
+ >
121
+ Save
122
+ </ Button >
123
+ </ ButtonGroup >
124
+ </ Box >
109
125
) ;
110
126
} ;
0 commit comments