11import React from 'react' ;
2- import PropTypes from 'prop-types' ;
32
43import {
54 Button ,
@@ -9,19 +8,19 @@ import {
98 Dialog ,
109 ListItemIcon ,
1110 List ,
12- ListItem ,
1311 Grid2 ,
1412 ListItemText ,
1513 Input ,
1614 InputAdornment ,
1715 IconButton ,
16+ ListItemButton ,
1817} from '@mui/material' ;
1918
2019import { Check as IconOk , Cancel as IconCancel , Close as IconClose } from '@mui/icons-material' ;
2120
22- import { I18n } from '@iobroker/adapter-react-v5' ;
21+ import { type AdminConnection , I18n } from '@iobroker/adapter-react-v5' ;
2322
24- const styles = {
23+ const styles : Record < string , React . CSSProperties > = {
2524 buttonIcon : {
2625 marginRight : 8 ,
2726 } ,
@@ -41,8 +40,28 @@ const styles = {
4140 } ,
4241} ;
4342
44- class DialogAdapterDebug extends React . Component {
45- constructor ( props ) {
43+ interface DialogAdapterDebugProps {
44+ socket : AdminConnection ;
45+ onDebug : ( instance : string , adapterToDebug : string ) => void ;
46+ onClose : ( ) => void ;
47+ title ?: string ;
48+ }
49+ interface DialogAdapterDebugState {
50+ instances : {
51+ id : string ;
52+ enabled : boolean ;
53+ host : string ;
54+ icon : string ;
55+ } [ ] ;
56+ jsInstance : string ;
57+ filter : string ;
58+ showAskForStop : boolean ;
59+ jsInstanceHost : string ;
60+ adapterToDebug : string ;
61+ }
62+
63+ class DialogAdapterDebug extends React . Component < DialogAdapterDebugProps , DialogAdapterDebugState > {
64+ constructor ( props : DialogAdapterDebugProps ) {
4665 super ( props ) ;
4766 this . state = {
4867 instances : [ ] ,
@@ -54,9 +73,14 @@ class DialogAdapterDebug extends React.Component {
5473 } ;
5574 }
5675
57- componentDidMount ( ) {
58- this . props . socket . getAdapterInstances ( ) . then ( instances => {
59- instances = instances
76+ componentDidMount ( ) : void {
77+ void this . props . socket . getAdapterInstances ( ) . then ( oInstances => {
78+ const instances : {
79+ id : string ;
80+ enabled : boolean ;
81+ host : string ;
82+ icon : string ;
83+ } [ ] = oInstances
6084 . filter ( i => i && ! i . common ?. onlyWWW )
6185 . map ( item => {
6286 const name = item . _id . replace ( / ^ s y s t e m \. a d a p t e r \. / , '' ) ;
@@ -69,17 +93,19 @@ class DialogAdapterDebug extends React.Component {
6993 } ;
7094 } ) ;
7195 instances . sort ( ( a , b ) => ( a . id > b . id ? 1 : a . id < b . id ? - 1 : 0 ) ) ;
72- let jsInstance = this . state . jsInstance || '' ;
73- let jsInstanceObj = this . state . jsInstance && instances . find ( item => item . id === this . state . jsInstance ) ;
74- let jsInstanceHost ;
96+ let jsInstance : string = this . state . jsInstance || '' ;
97+ const jsInstanceObj = this . state . jsInstance
98+ ? instances . find ( item => item . id === this . state . jsInstance )
99+ : null ;
100+ let jsInstanceHost : string ;
75101
76102 // check if selected instance is in the list
77103 if ( ! this . state . jsInstance || ! jsInstanceObj ) {
78- jsInstance = instances . find ( item => item . id . startsWith ( 'javascript.' ) ) ; // take the first one
79- jsInstanceHost = jsInstance ? jsInstance . host : '' ;
80- jsInstance = jsInstance ? jsInstance . id : '' ;
104+ const oJsInstance = instances . find ( item => item . id . startsWith ( 'javascript.' ) ) ; // take the first one
105+ jsInstanceHost = oJsInstance ? .host || '' ;
106+ jsInstance = oJsInstance ? .id || '' ;
81107 } else {
82- jsInstanceHost = jsInstanceObj ? jsInstanceObj . host : '' ;
108+ jsInstanceHost = jsInstanceObj ? .host || '' ;
83109 }
84110
85111 let adapterToDebug = this . state . adapterToDebug || '' ;
@@ -91,21 +117,23 @@ class DialogAdapterDebug extends React.Component {
91117 } ) ;
92118 }
93119
94- handleOk = ( ) => {
120+ handleOk = ( ) : void => {
95121 // TODO
96- if ( this . state . instances . find ( item => item . id === this . state . adapterToDebug ) . enabled ) {
97- return this . props . socket . getObject ( `system.adapter.${ this . state . adapterToDebug } ` ) . then ( obj => {
98- obj . common . enabled = false ;
99- this . props . socket
100- . setObject ( obj . _id , obj )
101- . then ( ( ) => this . props . onDebug ( this . state . jsInstance , this . state . adapterToDebug ) ) ;
122+ if ( this . state . instances . find ( item => item . id === this . state . adapterToDebug ) ?. enabled ) {
123+ void this . props . socket . getObject ( `system.adapter.${ this . state . adapterToDebug } ` ) . then ( obj => {
124+ if ( obj ) {
125+ obj . common . enabled = false ;
126+ void this . props . socket
127+ . setObject ( obj . _id , obj )
128+ . then ( ( ) => this . props . onDebug ( this . state . jsInstance , this . state . adapterToDebug ) ) ;
129+ }
102130 } ) ;
103- } else {
104- this . props . onDebug ( this . state . jsInstance , this . state . adapterToDebug ) ;
131+ return ;
105132 }
133+ this . props . onDebug ( this . state . jsInstance , this . state . adapterToDebug ) ;
106134 } ;
107135
108- renderJavascriptList ( ) {
136+ renderJavascriptList ( ) : React . JSX . Element | null {
109137 const js = this . state . instances . filter ( item => item . id . startsWith ( 'javascript.' ) ) ;
110138 if ( js . length < 2 ) {
111139 return null ;
@@ -115,8 +143,9 @@ class DialogAdapterDebug extends React.Component {
115143 < div style = { styles . title } > { I18n . t ( 'Host' ) } </ div >
116144 < List component = "nav" >
117145 { js . map ( item => (
118- < ListItem
119- button
146+ < ListItemButton
147+ component = "div"
148+ key = { item . id }
120149 selected = { this . state . jsInstance === item . id }
121150 onClick = { ( ) => this . setState ( { jsInstance : item . id , jsInstanceHost : item . host } ) }
122151 >
@@ -128,14 +157,14 @@ class DialogAdapterDebug extends React.Component {
128157 />
129158 </ ListItemIcon >
130159 < ListItemText primary = { item . id } />
131- </ ListItem >
160+ </ ListItemButton >
132161 ) ) }
133162 </ List >
134163 </ Grid2 >
135164 ) ;
136165 }
137166
138- renderInstances ( ) {
167+ renderInstances ( ) : React . JSX . Element {
139168 if ( ! this . state . jsInstance ) {
140169 return < Grid2 /> ;
141170 }
@@ -151,8 +180,8 @@ class DialogAdapterDebug extends React.Component {
151180 < div style = { styles . title } > { I18n . t ( 'Instances' ) } </ div >
152181 < List component = "nav" >
153182 { instances . map ( item => (
154- < ListItem
155- button
183+ < ListItemButton
184+ key = { item . id }
156185 selected = { this . state . adapterToDebug === item . id }
157186 onDoubleClick = { ( ) => this . setState ( { adapterToDebug : item . id } , ( ) => this . handleOk ( ) ) }
158187 onClick = { ( ) => this . setState ( { adapterToDebug : item . id } ) }
@@ -165,14 +194,14 @@ class DialogAdapterDebug extends React.Component {
165194 />
166195 </ ListItemIcon >
167196 < ListItemText primary = { item . id } />
168- </ ListItem >
197+ </ ListItemButton >
169198 ) ) }
170199 </ List >
171200 </ Grid2 >
172201 ) ;
173202 }
174203
175- render ( ) {
204+ render ( ) : React . JSX . Element {
176205 return (
177206 < Dialog
178207 maxWidth = "md"
@@ -245,10 +274,4 @@ class DialogAdapterDebug extends React.Component {
245274 }
246275}
247276
248- DialogAdapterDebug . propTypes = {
249- socket : PropTypes . object . isRequired ,
250- onClose : PropTypes . func . isRequired ,
251- onDebug : PropTypes . func . isRequired ,
252- } ;
253-
254277export default DialogAdapterDebug ;
0 commit comments