1- import ClearIcon from "@mui/icons-material/Clear"
21import DeleteIcon from "@mui/icons-material/Delete"
32import EditRoadIcon from "@mui/icons-material/EditRoad"
43import MoreVertIcon from "@mui/icons-material/MoreVert"
@@ -10,12 +9,10 @@ import {
109 Card ,
1110 CardContent ,
1211 IconButton ,
13- InputAdornment ,
1412 ListItemIcon ,
1513 ListItemText ,
1614 Menu ,
1715 MenuItem ,
18- TextField ,
1916 Typography ,
2017 useTheme ,
2118} from "@mui/material"
@@ -26,6 +23,7 @@ import React, { FC, useEffect, useState } from "react"
2623import { useGeneratePlotlyGraphQuery } from "../hooks/useGeneratePlotlyGraphQuery"
2724import { usePlotlyColorTheme } from "../state"
2825import { StudyDetail } from "../types/optuna"
26+ import { SmartTextField } from "./SmartTextField"
2927
3028const plotDomIdPrefix = "graph-by-llm"
3129
@@ -142,30 +140,17 @@ const GraphByLLMItem: FC<{
142140
143141 { isEditingGraph && (
144142 < Box sx = { { display : "flex" , marginBottom : theme . spacing ( 2 ) } } >
145- < TextField
143+ < SmartTextField
146144 id = { `graph-by-llm-item-query-${ id } ` }
145+ value = { queryInput }
146+ setValue = { setQueryInput }
147147 variant = "outlined"
148148 placeholder = "Enter the part you want to edit in the graph"
149149 fullWidth
150150 size = "small"
151- value = { queryInput }
152- onChange = { ( e ) => setQueryInput ( e . target . value ) }
153- slotProps = { {
154- input : {
155- endAdornment : queryInput && (
156- < InputAdornment position = "end" >
157- < IconButton
158- aria-label = "clear filter"
159- onClick = { ( ) => setQueryInput ( "" ) }
160- edge = "end"
161- size = "small"
162- disabled = { isReGeneratingPlotlyGraph }
163- >
164- < ClearIcon />
165- </ IconButton >
166- </ InputAdornment >
167- ) ,
168- } ,
151+ clearButtonDisabled = { isReGeneratingPlotlyGraph }
152+ handleSubmit = { ( ) => {
153+ reGeneratePlotlyGraph ( queryInput )
169154 } }
170155 />
171156 < Button
@@ -231,6 +216,21 @@ export const GraphByLLM: FC<{
231216 > ( [ ] )
232217 const [ queryInput , setQueryInput ] = useState ( "" )
233218
219+ const handleSubmit = ( ) => {
220+ if ( study === null ) return
221+ generatePlotlyGraph ( study , queryInput ) . then ( ( result ) => {
222+ setGraphs ( ( prev ) => [
223+ ...prev ,
224+ {
225+ id : String ( new Date ( ) . getTime ( ) ) ,
226+ functionStr : result . functionStr ,
227+ title : result . graphTitle ,
228+ plotData : result . plotData ,
229+ } ,
230+ ] )
231+ } )
232+ }
233+
234234 return (
235235 < Stack
236236 spacing = { 2 }
@@ -280,51 +280,23 @@ export const GraphByLLM: FC<{
280280 />
281281 ) ) }
282282 < Box sx = { { display : "flex" } } >
283- < TextField
283+ < SmartTextField
284284 id = "graph-by-llm-query"
285285 variant = "outlined"
286286 placeholder = "Enter your query to generate a graph, e.g., 'Plot objective value vs trial number'"
287287 fullWidth
288288 size = "small"
289289 value = { queryInput }
290- onChange = { ( e ) => setQueryInput ( e . target . value ) }
291- slotProps = { {
292- input : {
293- endAdornment : queryInput && (
294- < InputAdornment position = "end" >
295- < IconButton
296- aria-label = "clear filter"
297- onClick = { ( ) => setQueryInput ( "" ) }
298- edge = "end"
299- size = "small"
300- disabled = { isProcessing }
301- >
302- < ClearIcon />
303- </ IconButton >
304- </ InputAdornment >
305- ) ,
306- } ,
307- } }
290+ setValue = { setQueryInput }
291+ clearButtonDisabled = { isProcessing }
292+ handleSubmit = { handleSubmit }
308293 />
309294 < LoadingButton
310295 sx = { { marginLeft : theme . spacing ( 2 ) } }
311296 variant = "contained"
312297 loading = { isProcessing }
313298 disabled = { queryInput . trim ( ) === "" }
314- onClick = { ( ) => {
315- if ( study === null ) return
316- generatePlotlyGraph ( study , queryInput ) . then ( ( result ) => {
317- setGraphs ( ( prev ) => [
318- ...prev ,
319- {
320- id : String ( new Date ( ) . getTime ( ) ) ,
321- functionStr : result . functionStr ,
322- title : result . graphTitle ,
323- plotData : result . plotData ,
324- } ,
325- ] )
326- } )
327- } }
299+ onClick = { handleSubmit }
328300 >
329301 Generate
330302 </ LoadingButton >
0 commit comments