@@ -3,6 +3,7 @@ import SplitPane from "react-split-pane";
3
3
import JSONRPCRequestEditor from "./JSONRPCRequestEditor" ;
4
4
import PlayCircle from "@material-ui/icons/PlayCircleFilled" ;
5
5
import CloseIcon from "@material-ui/icons/Close" ;
6
+ import History from "@material-ui/icons/History" ;
6
7
import PlusIcon from "@material-ui/icons/Add" ;
7
8
import CheckCircle from "@material-ui/icons/CheckCircle" ;
8
9
import {
@@ -16,6 +17,11 @@ import {
16
17
Tabs ,
17
18
Tooltip ,
18
19
Grid ,
20
+ Dialog ,
21
+ ListItem ,
22
+ List ,
23
+ ListItemText ,
24
+ Container ,
19
25
} from "@material-ui/core" ;
20
26
import { Client , RequestManager , HTTPTransport , WebSocketTransport } from "@open-rpc/client-js" ;
21
27
import Brightness3Icon from "@material-ui/icons/Brightness3" ;
@@ -126,6 +132,9 @@ const Inspector: React.FC<IProps> = (props) => {
126
132
const [ url , setUrl ] = useState ( props . url || "" ) ;
127
133
const [ debouncedUrl ] = useDebounce ( url , 1000 ) ;
128
134
const [ client , error ] = useClient ( debouncedUrl ) ;
135
+ const [ historyOpen , setHistoryOpen ] = useState ( ) ;
136
+ const [ requestHistory , setRequestHistory ] : [ any [ ] , Dispatch < any > ] = useState ( [ ] ) ;
137
+ const [ historySelectedIndex , setHistorySelectedIndex ] = useState ( 0 ) ;
129
138
useEffect ( ( ) => {
130
139
if ( props . openrpcMethodObject ) {
131
140
setJson ( {
@@ -173,7 +182,11 @@ const Inspector: React.FC<IProps> = (props) => {
173
182
const r = { jsonrpc : "2.0" , result, id } ;
174
183
setResults ( r ) ;
175
184
setTabResults ( tabIndex , r ) ;
185
+ const newHistory : any = [ ...requestHistory , { ...tabs [ tabIndex ] } ] ;
186
+ setRequestHistory ( newHistory ) ;
176
187
} catch ( e ) {
188
+ const newHistory : any = [ ...requestHistory , { ...tabs [ tabIndex ] } ] ;
189
+ setRequestHistory ( newHistory ) ;
177
190
setResults ( e ) ;
178
191
setTabResults ( tabIndex , e ) ;
179
192
}
@@ -229,8 +242,70 @@ const Inspector: React.FC<IProps> = (props) => {
229
242
setTabIndex ( newValue ) ;
230
243
} ;
231
244
245
+ const onHistoryPlayClick = ( ) => {
246
+ if ( requestHistory [ historySelectedIndex ] ) {
247
+ setJson ( requestHistory [ historySelectedIndex ] . content ) ;
248
+ setUrl ( requestHistory [ historySelectedIndex ] . url ) ;
249
+ setOpenRpcDocument ( requestHistory [ historySelectedIndex ] . openrpcDocument ) ;
250
+ setResults ( undefined ) ;
251
+ setHistoryOpen ( false ) ;
252
+ }
253
+ } ;
254
+
232
255
return (
233
256
< >
257
+ < Dialog onClose = { ( ) => setHistoryOpen ( false ) } aria-labelledby = "simple-dialog-title" open = { historyOpen } >
258
+ < Container maxWidth = "sm" >
259
+ < Grid
260
+ container
261
+ justify = "space-between"
262
+ alignItems = "center"
263
+ style = { { padding : "30px" , paddingTop : "10px" , paddingBottom : "10px" } } >
264
+ < Typography color = "textPrimary" > History</ Typography >
265
+ {
266
+ requestHistory . length === 0
267
+ ? null
268
+ : < Tooltip title = "Use" >
269
+ < IconButton onClick = { onHistoryPlayClick } >
270
+ < PlayCircle />
271
+ </ IconButton >
272
+ </ Tooltip >
273
+ }
274
+ </ Grid >
275
+ {
276
+ requestHistory . length === 0
277
+ ? < Typography style = { { padding : "30px" } } > No History Yet.</ Typography >
278
+ : < Grid container style = { { paddingBottom : "30px" } } >
279
+ < List style = { { padding : "10px" , overflowY : "scroll" , height : "250px" , width : "200px" } } >
280
+ { requestHistory . map ( ( requestHistoryItem : any , historyIndex : number ) => (
281
+ < ListItem button
282
+ onClick = { ( ) => setHistorySelectedIndex ( historyIndex ) }
283
+ selected = { historyIndex === historySelectedIndex } >
284
+ < ListItemText
285
+ primary = { requestHistoryItem . content . method || "Empty Method" }
286
+ secondary = { requestHistoryItem . url || "Empty Url" }
287
+ />
288
+ </ ListItem >
289
+ ) ) }
290
+ </ List >
291
+ < MonacoEditor
292
+ width = "300px"
293
+ height = "250px"
294
+ value = {
295
+ requestHistory [ historySelectedIndex ]
296
+ ? JSON . stringify ( requestHistory [ historySelectedIndex ] . content , null , 4 )
297
+ : ""
298
+ }
299
+ language = "json"
300
+ editorDidMount = { ( ) => {
301
+ // noop
302
+ } }
303
+ />
304
+ </ Grid >
305
+ }
306
+ </ Container >
307
+ </ Dialog >
308
+
234
309
< div style = { { position : "relative" } } >
235
310
< Tabs
236
311
style = { { background : "transparent" } }
@@ -258,28 +333,32 @@ const Inspector: React.FC<IProps> = (props) => {
258
333
}
259
334
{ tabIndex === index
260
335
?
261
- < IconButton onClick = {
262
- ( ev ) => handleClose ( ev , index )
263
- } style = { { position : "absolute" , right : "10px" , top : "25%" } } size = "small" >
264
- < CloseIcon />
265
- </ IconButton >
336
+ < Tooltip title = "Close Tab" >
337
+ < IconButton onClick = {
338
+ ( ev ) => handleClose ( ev , index )
339
+ } style = { { position : "absolute" , right : "10px" , top : "25%" } } size = "small" >
340
+ < CloseIcon />
341
+ </ IconButton >
342
+ </ Tooltip >
266
343
: null
267
344
}
268
345
</ div >
269
346
} > </ Tab >
270
347
) ) }
271
348
< Tab disableRipple style = { { minWidth : "50px" } } label = {
272
- < IconButton onClick = { ( ) => setTabs ( [
273
- ...tabs ,
274
- {
275
- name : "New Tab" ,
276
- content : { ...emptyJSONRPC } ,
277
- url : "" ,
278
- } ,
279
- ] ,
280
- ) } >
281
- < PlusIcon scale = { 0.5 } />
282
- </ IconButton >
349
+ < Tooltip title = "Create New Tab" >
350
+ < IconButton onClick = { ( ) => setTabs ( [
351
+ ...tabs ,
352
+ {
353
+ name : "New Tab" ,
354
+ content : { ...emptyJSONRPC } ,
355
+ url : "" ,
356
+ } ,
357
+ ] ,
358
+ ) } >
359
+ < PlusIcon scale = { 0.5 } />
360
+ </ IconButton >
361
+ </ Tooltip >
283
362
} >
284
363
</ Tab >
285
364
</ Tabs >
@@ -293,9 +372,21 @@ const Inspector: React.FC<IProps> = (props) => {
293
372
src = "https://github.com/open-rpc/design/raw/master/icons/open-rpc-logo-noText/open-rpc-logo-noText%20(PNG)/128x128.png" //tslint:disable-line
294
373
/>
295
374
< Typography variant = "h6" color = "textSecondary" > Inspector</ Typography >
296
- < IconButton onClick = { handlePlayButton } >
297
- < PlayCircle />
298
- </ IconButton >
375
+ { /* <Button
376
+ onClick={() => setHistoryOpen(true)}
377
+ variant="outlined"
378
+ style={{
379
+ fontSize: "0.6rem",
380
+ marginRight: "5px",
381
+ marginLeft: "15px",
382
+ paddingLeft: "10px",
383
+ paddingRight: "10px",
384
+ }}>History</Button> */ }
385
+ < Tooltip title = "Play" >
386
+ < IconButton onClick = { handlePlayButton } >
387
+ < PlayCircle />
388
+ </ IconButton >
389
+ </ Tooltip >
299
390
< InputBase
300
391
startAdornment = { openrpcDocument
301
392
?
@@ -323,12 +414,20 @@ const Inspector: React.FC<IProps> = (props) => {
323
414
fullWidth
324
415
style = { { background : "rgba(0,0,0,0.1)" , borderRadius : "4px" , padding : "0px 10px" , marginRight : "5px" } }
325
416
/>
417
+ < Tooltip title = "History" >
418
+ < IconButton onClick = { ( ) => setHistoryOpen ( true ) } >
419
+ < History />
420
+ </ IconButton >
421
+ </ Tooltip >
326
422
{
327
423
props . hideToggleTheme
328
424
? null
329
- : < IconButton onClick = { handleToggleDarkMode } >
330
- { props . darkMode ? < Brightness3Icon /> : < WbSunnyIcon /> }
331
- </ IconButton >
425
+ :
426
+ < Tooltip title = "Toggle Theme" >
427
+ < IconButton onClick = { handleToggleDarkMode } >
428
+ { props . darkMode ? < Brightness3Icon /> : < WbSunnyIcon /> }
429
+ </ IconButton >
430
+ </ Tooltip >
332
431
}
333
432
</ Toolbar >
334
433
</ AppBar >
0 commit comments