@@ -33,6 +33,15 @@ function ACPUTable({ device, update, notify }) {
3333 const [ disable , setDisable ] = React . useState ( true ) ;
3434 const loadActivity = GetOptions ( 'A45_Load' ) ;
3535
36+ // Toggle handler to enable/disable ACPU fields and freeze parameters
37+ const handleToggle = ( ) => {
38+ if ( ! device || ! href ) {
39+ setDisable ( true ) ;
40+ } else if ( device && href ) {
41+ setDisable ( ! disable ) ; // Toggle the fields' disable state
42+ }
43+ } ;
44+
3645 function fetchPort ( port , link ) {
3746 server . GET ( server . peripheralPath ( device , `${ link } /${ port . href } ` ) , ( data ) => {
3847 const ep = parseInt ( port . href . slice ( - 1 ) , 10 ) ;
@@ -46,7 +55,6 @@ function ACPUTable({ device, update, notify }) {
4655 function fetchAcpuData ( link ) {
4756 if ( link !== '' ) {
4857 server . GET ( server . peripheralPath ( device , link ) , ( data ) => {
49- // resolve cycling
5058 if ( data . name !== acpuData . name
5159 || data . frequency !== acpuData . frequency
5260 || data . load !== acpuData . load ) {
@@ -56,9 +64,7 @@ function ACPUTable({ device, update, notify }) {
5664 load : data . load ,
5765 } ) ;
5866 }
59- setPowerData ( [
60- [ 'Block Power' , data . consumption . block_power , 0 ] ,
61- ] ) ;
67+ setPowerData ( [ [ 'Block Power' , data . consumption . block_power , 0 ] ] ) ;
6268 data . ports . forEach ( ( port ) => fetchPort ( port , link ) ) ;
6369 } ) ;
6470 }
@@ -75,7 +81,7 @@ function ACPUTable({ device, update, notify }) {
7581 function fetchData ( ) {
7682 server . GET ( server . api . fetch ( server . Elem . peripherals , device ) , ( data ) => {
7783 const acpu = getPeripherals ( data , 'acpu' ) ;
78- setDisable ( acpu . length === 0 ) ;
84+ setDisable ( true ) ;
7985 if ( acpu . length > 0 ) {
8086 const link = acpu [ 0 ] . href ;
8187 setHref ( link ) ;
@@ -124,7 +130,6 @@ function ACPUTable({ device, update, notify }) {
124130 }
125131
126132 const deleteRow = ( index ) => {
127- // no delete method for acpu. this is just clear name of the endpoint which mean disable
128133 const val = endpoints [ index ] . data ;
129134 val . name = '' ;
130135 server . PATCH ( server . peripheralPath ( device , `${ href } /ep/${ endpoints [ index ] . ep } ` ) , val , ( ) => fetchAcpuData ( href ) ) ;
@@ -147,9 +152,25 @@ function ACPUTable({ device, update, notify }) {
147152
148153 const powerHeader = [ 'Power' , '%' ] ;
149154 const title = 'ACPU' ;
155+
150156 return (
151157 < div className = "component-table-head" >
152158 < ComponentLabel name = { title } />
159+
160+ { /* Toggle Switch for ACPU */ }
161+ < div className = "toggle-container" >
162+ < label htmlFor = "acpu-toggle" > ACPU Power</ label >
163+ < label className = "toggle-switch" >
164+ < input
165+ type = "checkbox"
166+ onChange = { handleToggle }
167+ checked = { ! disable }
168+ disabled = { ! device || ! href } // Disable toggle based on device and ACPU selection
169+ />
170+ < span className = "slider" />
171+ </ label >
172+ </ div >
173+
153174 < div className = "cpu-container" >
154175 < PowerTable
155176 title = "ACPU power"
@@ -161,39 +182,58 @@ function ACPUTable({ device, update, notify }) {
161182 < div className = "acpu-group-container" >
162183 < div className = "acpu-group" >
163184 < label > ACPU name</ label >
164- < input type = "text" onChange = { ( e ) => handleChange ( 'name' , e . target . value ) } value = { acpuData . name } disabled = { disable } />
185+ < input
186+ type = "text"
187+ onChange = { ( e ) => handleChange ( 'name' , e . target . value ) }
188+ value = { acpuData . name }
189+ disabled = { disable } // Freeze when toggle is off
190+ />
165191 </ div >
166192 < div className = "acpu-group" >
167193 < label > Frequency</ label >
168- < input type = "number" min = { 0 } step = { 1 } onChange = { ( e ) => handleChange ( 'frequency' , e . target . value ) } value = { acpuData . frequency } disabled = { disable } />
194+ < input
195+ type = "number"
196+ min = { 0 }
197+ step = { 1 }
198+ onChange = { ( e ) => handleChange ( 'frequency' , e . target . value ) }
199+ value = { acpuData . frequency }
200+ disabled = { disable } // Freeze when toggle is off
201+ />
169202 </ div >
170203 < div className = "acpu-group" >
171204 < label > Load</ label >
172- < Dropdown value = { acpuData . load } onChangeHandler = { ( value ) => handleChange ( 'load' , value ) } items = { loadActivity } disabled = { disable } />
205+ < Dropdown
206+ value = { acpuData . load }
207+ onChangeHandler = { ( value ) => handleChange ( 'load' , value ) }
208+ items = { loadActivity }
209+ disabled = { disable } // Freeze when toggle is off
210+ />
173211 </ div >
174212 </ div >
213+
175214 < TableBase header = { header } disabled = { disable } onClick = { ( ) => setModalOpen ( true ) } >
176- {
177- endpoints . map ( ( row , index ) => (
178- ( row . data !== undefined && row . data . name !== '' )
179- && (
180- < tr key = { row . ep } >
181- < StatusColumn messages = { row . data . consumption . messages } />
182- < Actions
183- onEditClick = { ( ) => { setEditIndex ( index ) ; setModalOpen ( true ) ; } }
184- onDeleteClick = { ( ) => deleteRow ( index ) }
185- / >
186- < td > { row . data . name } </ td >
187- < SelectionCell val = { row . data . activity } values = { loadActivity } />
188- < PercentsCell val = { row . data . read_write_rate } />
189- < PercentsCell val = { row . data . toggle_rate } precition = { 1 } />
190- < BandwidthCell val = { row . data . consumption . calculated_bandwidth } />
191- < PowerCell val = { row . data . consumption . noc_power } />
192- </ tr >
193- )
194- ) )
195- }
215+ { endpoints . map ( ( row , index ) => (
216+ row . data !== undefined && row . data . name !== ''
217+ && (
218+ < tr key = { row . ep } >
219+ < StatusColumn messages = { row . data . consumption . messages } / >
220+ < Actions
221+ onEditClick = { ( ) => { if ( ! disable ) { setEditIndex ( index ) ; setModalOpen ( true ) ; } } }
222+ onDeleteClick = { ( ) => { if ( ! disable ) { deleteRow ( index ) ; } } }
223+ />
224+ < td > { row . data . name } </ td >
225+ < SelectionCell val = { row . data . activity } values = { loadActivity } disabled = { disable } / >
226+ { ' ' }
227+ { /* Freeze selection */ }
228+ < PercentsCell val = { row . data . read_write_rate } disabled = { disable } />
229+ < PercentsCell val = { row . data . toggle_rate } precition = { 1 } disabled = { disable } />
230+ < BandwidthCell val = { row . data . consumption . calculated_bandwidth } disabled = { disable } />
231+ < PowerCell val = { row . data . consumption . noc_power } disabled = { disable } / >
232+ </ tr >
233+ )
234+ ) ) }
196235 </ TableBase >
236+
197237 { modalOpen && (
198238 < ABCPUModal
199239 title = { title }
0 commit comments