@@ -7,14 +7,15 @@ import {
77 Button ,
88 CircularProgress ,
99} from "@mui/material" ;
10+ import JsonView from "@uiw/react-json-view" ;
1011import { AppService } from "../../services/AppService" ;
11- import { escapeNewLine } from "../../utils/Utils" ;
1212
1313interface AdvancedTabProps { }
1414
1515const AdvancedTab : React . FC < AdvancedTabProps > = ( ) : JSX . Element => {
1616 const [ command , setCommand ] = useState < string > ( "" ) ;
17- const [ output , setOutput ] = useState < string > ( "" ) ;
17+ const [ commandHistory , setCommandHistory ] = useState < string [ ] > ( [ ] ) ;
18+ const [ outputLines , setOutputLines ] = useState < Array < string | object > > ( [ ] ) ;
1819 const [ loadingCommand , setLoadingCommand ] = useState < boolean > ( false ) ;
1920 const appService = new AppService ( ) ;
2021
@@ -25,7 +26,7 @@ const AdvancedTab: React.FC<AdvancedTabProps> = (): JSX.Element => {
2526 if ( outputRef . current ) {
2627 outputRef . current . scrollTop = outputRef . current . scrollHeight ;
2728 }
28- } , [ output ] ) ;
29+ } , [ outputLines ] ) ;
2930
3031 const handleCommandChange = ( event : React . ChangeEvent < HTMLInputElement > ) => {
3132 setCommand ( event . target . value ) ;
@@ -36,9 +37,15 @@ const AdvancedTab: React.FC<AdvancedTabProps> = (): JSX.Element => {
3637 event . preventDefault ( ) ;
3738
3839 const output = await appService . runCustomCommand ( command ) ;
39-
40+
4041 // Append the command and output to the output box
41- setOutput ( ( prevOutput ) => prevOutput + `>> ${ command } \n${ output } \n\n` ) ;
42+ try {
43+ const jsonOutput = JSON . parse ( output ) ;
44+ setOutputLines ( ( prevOutputLines ) => [ ...prevOutputLines , jsonOutput ] ) ;
45+ } catch ( error ) {
46+ setOutputLines ( ( prevOutputLines ) => [ ...prevOutputLines , output ] ) ;
47+ }
48+ setCommandHistory ( ( prevCommandHistory ) => [ ...prevCommandHistory , command ] ) ;
4249
4350 // Clear the input field
4451 setCommand ( "" ) ;
@@ -52,7 +59,8 @@ const AdvancedTab: React.FC<AdvancedTabProps> = (): JSX.Element => {
5259 < Alert severity = "warning" variant = "filled" >
5360 < AlertTitle > Advanced Users Only</ AlertTitle >
5461 This tab is designed for advanced users. It allows sending commands
55- to the rocketpool binary and displays the output obtained.
62+ to the rocketpool binary and displays the output obtained. Type --help
63+ for a list of available commands.
5664 </ Alert >
5765 </ Box >
5866 </ div >
@@ -71,21 +79,48 @@ const AdvancedTab: React.FC<AdvancedTabProps> = (): JSX.Element => {
7179 sx = { { backgroundColor : "grey.200" } }
7280 ref = { outputRef }
7381 >
74- < pre
75- style = { {
76- whiteSpace : "pre-wrap" ,
77- margin : 0 ,
78- fontFamily : "Ubuntu Mono, monospace" ,
79- fontSize : "14px" ,
80- lineHeight : "1.4" ,
81- color : "#555555" ,
82- textAlign : "left" ,
83- overflowWrap : "break-word" ,
84- wordBreak : "break-all" ,
85- } }
86- >
87- { escapeNewLine ( output ) }
88- </ pre >
82+ { outputLines . map ( ( line , index ) => (
83+ < div key = { `output-line-${ index } ` } >
84+ < pre
85+ style = { {
86+ margin : 0 ,
87+ fontFamily : "Ubuntu Mono, monospace" ,
88+ fontSize : "14px" ,
89+ color : "#555555" ,
90+ textAlign : "left" ,
91+ fontWeight : "bold" ,
92+ } }
93+ >
94+ rocketpoold-api:~$ { commandHistory [ index ] }
95+ </ pre >
96+ { typeof line === "object" ? (
97+ < JsonView
98+ value = { line }
99+ displayDataTypes = { false }
100+ collapsed
101+ shortenTextAfterLength = { 100 }
102+ style = { {
103+ textAlign : "left"
104+ } }
105+ />
106+ ) : (
107+ < pre
108+ style = { {
109+ whiteSpace : "pre-wrap" ,
110+ margin : 0 ,
111+ fontFamily : "Ubuntu Mono, monospace" ,
112+ fontSize : "14px" ,
113+ lineHeight : "1.4" ,
114+ color : "#555555" ,
115+ textAlign : "left" ,
116+ overflowWrap : "break-word" ,
117+ wordBreak : "break-all" ,
118+ } } >
119+ { line || "Error: Invalid command" }
120+ </ pre >
121+ ) }
122+ </ div >
123+ ) ) }
89124 </ Box >
90125 < form
91126 onSubmit = { handleSubmit }
0 commit comments