@@ -2,21 +2,26 @@ import { useState } from "react";
22import { Button , Form } from "react-bootstrap" ;
33import { useDispatch } from "react-redux" ;
44import ListFiltersHeader from "../../shared/ListFiltersHeader" ;
5+ import { LogMessage } from '../../shared/types/LogMessage' ;
56import {
67 useGetDebugSessionMutation ,
78 useGetDoNotLoadConfigOnNextBootQuery ,
89 useSetDoNotLoadConfigOnNextBootMutation ,
10+ useSetLoadConfigMutation ,
911 useSetRestartMutation ,
1012 useStopDebugSessionMutation ,
1113} from "../../store/apiSlice" ;
1214import ConsoleWindow from "./ConsoleWindow" ;
1315import { DebugFilters } from "./DebugFilters" ;
16+ import MinimumLogLevelDropdown from './MinimumLogLevelDropdown' ;
17+ import RestartConfirmModal from "./RestartConfirmModal" ;
1418import { useFilteredMessages } from "./hooks/useFilteredMessages" ;
1519
1620const DebugConsole = ( ) => {
1721 //* HOOKS ***********************************************************/
1822 const [ websocket , setWebsocket ] = useState < WebSocket > ( ) ;
19- const [ messages , setMessages ] = useState < Message [ ] > ( [ ] ) ;
23+ const [ messages , setMessages ] = useState < LogMessage [ ] > ( [ ] ) ;
24+ const [ showModal , setShowModal ] = useState ( false ) ;
2025 const dispatch = useDispatch ( ) ;
2126
2227 const { data : doNotLoadConfigOnNextBoot } =
@@ -26,6 +31,7 @@ const DebugConsole = () => {
2631 const [ stopSession ] = useStopDebugSessionMutation ( ) ;
2732 const [ setDoNotLoadConfig ] = useSetDoNotLoadConfigOnNextBootMutation ( ) ;
2833 const [ restart ] = useSetRestartMutation ( ) ;
34+ const [ loadConfig ] = useSetLoadConfigMutation ( ) ;
2935
3036 //* EFFECTS *********************************************************/
3137 const filteredItems = useFilteredMessages ( messages ) ;
@@ -55,14 +61,17 @@ const DebugConsole = () => {
5561 } ;
5662
5763 const clickRestart = ( ) => {
58- console . log ( "Restarting program" ) ;
64+ setShowModal ( true ) ;
65+ } ;
5966
60- restart ( ) ;
67+ const clickLoadConfig = ( ) => {
68+ console . log ( "Loading config" ) ;
69+ loadConfig ( ) ;
6170 } ;
6271
6372 const onMessage = ( event : { data : string } ) => {
6473 const data = JSON . parse ( event . data ) ;
65- console . log ( data ) ;
74+ // console.log(data);
6675 setMessages ( ( messages ) => [ ...messages , data ] ) ;
6776 } ;
6877
@@ -72,45 +81,65 @@ const DebugConsole = () => {
7281 return (
7382 < >
7483 < div className = "d-flex flex-column overflow-hidden h-100" >
75- < div className = "d-flex align-items-center justify-content-start" >
84+ < div className = "d-flex align-items-center justify-content-start mb-2" >
85+ < h2 > Debug Console</ h2 >
86+ </ div >
87+ < div className = "d-flex align-items-center justify-content-start mb-2" >
7688 < Button className = "mx-1" variant = "primary" size = "sm" onClick = { join } >
7789 Start Debug Session
7890 </ Button >
7991 < Button className = "mx-1" variant = "primary" size = "sm" onClick = { stop } >
8092 Stop Debug Session
8193 </ Button >
94+ < MinimumLogLevelDropdown />
8295 < Form . Check
83- type = "checkbox"
84- className = "mx-1"
85- label = "Do Not Load Config on Next Boot"
86- name = "doNotLoadConfig"
87- id = "doNotLoadConfig"
96+ type = "checkbox"
97+ className = "mx-1"
98+ label = "Do Not Load Config on Next Boot"
99+ name = "doNotLoadConfig"
100+ id = "doNotLoadConfig"
88101 checked = { doNotLoadConfigOnNextBoot ?. doNotLoadConfigOnNextBoot }
89- onChange = { ( ) => setDoNotLoadConfig ( ! doNotLoadConfigOnNextBoot ?. doNotLoadConfigOnNextBoot ) }
102+ onChange = { ( ) =>
103+ setDoNotLoadConfig (
104+ ! doNotLoadConfigOnNextBoot ?. doNotLoadConfigOnNextBoot
105+ )
106+ }
90107 />
91- < Button className = "mx-1" variant = "primary" size = "sm" onClick = { clickRestart } >
108+ < Button
109+ className = "mx-1"
110+ variant = "primary"
111+ size = "sm"
112+ onClick = { clickLoadConfig }
113+ disabled = { ! doNotLoadConfigOnNextBoot . doNotLoadConfigOnNextBoot }
114+ >
115+ Load Config
116+ </ Button >
117+ < Button
118+ className = "mx-1"
119+ variant = "primary"
120+ size = "sm"
121+ onClick = { clickRestart }
122+ >
92123 Restart Program
93124 </ Button >
94125 < span className = "ps-2" > Message Count: { messages . length } </ span >
95126 </ div >
96- < div className = "d-flex align-items-center justify-content-start" >
97- < h5 > Debug Console</ h5 >
98- </ div >
99127 < ListFiltersHeader showSearch filters = { < DebugFilters /> } />
100- < ConsoleWindow filteredItems = { filteredItems } />
128+ < ConsoleWindow filteredItems = { filteredItems } />
101129 </ div >
130+
131+ < RestartConfirmModal
132+ show = { showModal }
133+ handleClose = { ( ) => setShowModal ( false ) }
134+ handleConfirm = { ( ) => {
135+ restart ( ) ;
136+ setShowModal ( false ) ;
137+ } }
138+ />
102139 </ >
103140 ) ;
104141} ;
105142
106143export default DebugConsole ;
107144
108- export interface Message {
109- Timestamp : string ;
110- MessageTemplate : string ;
111- RenderedMessage : String ;
112- Level : string ;
113- Properties ?: {
114- Key : string ;
115- } ;
116- }
145+
0 commit comments