Skip to content

Commit b8b8ac2

Browse files
committed
Enabling toggle to turn on/off ACPU power
1 parent 94f5660 commit b8b8ac2

File tree

2 files changed

+89
-23
lines changed

2 files changed

+89
-23
lines changed

src/components/Tables/ACPUTable.js

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ 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
37+
const handleToggle = () => {
38+
setDisable(!disable);
39+
};
40+
3641
function fetchPort(port, link) {
3742
server.GET(server.peripheralPath(device, `${link}/${port.href}`), (data) => {
3843
const ep = parseInt(port.href.slice(-1), 10);
@@ -46,7 +51,6 @@ function ACPUTable({ device, update, notify }) {
4651
function fetchAcpuData(link) {
4752
if (link !== '') {
4853
server.GET(server.peripheralPath(device, link), (data) => {
49-
// resolve cycling
5054
if (data.name !== acpuData.name
5155
|| data.frequency !== acpuData.frequency
5256
|| data.load !== acpuData.load) {
@@ -75,7 +79,7 @@ function ACPUTable({ device, update, notify }) {
7579
function fetchData() {
7680
server.GET(server.api.fetch(server.Elem.peripherals, device), (data) => {
7781
const acpu = getPeripherals(data, 'acpu');
78-
setDisable(acpu.length === 0);
82+
setDisable(true);
7983
if (acpu.length > 0) {
8084
const link = acpu[0].href;
8185
setHref(link);
@@ -124,7 +128,6 @@ function ACPUTable({ device, update, notify }) {
124128
}
125129

126130
const deleteRow = (index) => {
127-
// no delete method for acpu. this is just clear name of the endpoint which mean disable
128131
const val = endpoints[index].data;
129132
val.name = '';
130133
server.PATCH(server.peripheralPath(device, `${href}/ep/${endpoints[index].ep}`), val, () => fetchAcpuData(href));
@@ -147,9 +150,20 @@ function ACPUTable({ device, update, notify }) {
147150

148151
const powerHeader = ['Power', '%'];
149152
const title = 'ACPU';
153+
150154
return (
151155
<div className="component-table-head">
152156
<ComponentLabel name={title} />
157+
158+
{/* Toggle Switch for ACPU */}
159+
<div className="toggle-container">
160+
<label htmlFor="acpu-toggle">ACPU Power</label>
161+
<label className="toggle-switch">
162+
<input type="checkbox" onChange={handleToggle} checked={!disable} />
163+
<span className="slider" />
164+
</label>
165+
</div>
166+
153167
<div className="cpu-container">
154168
<PowerTable
155169
title="ACPU power"
@@ -172,28 +186,28 @@ function ACPUTable({ device, update, notify }) {
172186
<Dropdown value={acpuData.load} onChangeHandler={(value) => handleChange('load', value)} items={loadActivity} disabled={disable} />
173187
</div>
174188
</div>
189+
175190
<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-
}
191+
{endpoints.map((row, index) => (
192+
(row.data !== undefined && row.data.name !== '')
193+
&& (
194+
<tr key={row.ep}>
195+
<StatusColumn messages={row.data.consumption.messages} />
196+
<Actions
197+
onEditClick={() => { setEditIndex(index); setModalOpen(true); }}
198+
onDeleteClick={() => deleteRow(index)}
199+
/>
200+
<td>{row.data.name}</td>
201+
<SelectionCell val={row.data.activity} values={loadActivity} />
202+
<PercentsCell val={row.data.read_write_rate} />
203+
<PercentsCell val={row.data.toggle_rate} precition={1} />
204+
<BandwidthCell val={row.data.consumption.calculated_bandwidth} />
205+
<PowerCell val={row.data.consumption.noc_power} />
206+
</tr>
207+
)
208+
))}
196209
</TableBase>
210+
197211
{modalOpen && (
198212
<ABCPUModal
199213
title={title}

src/components/style/ACPUTable.css

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,55 @@
2626
padding-right: 10px;
2727
padding-left: 10px;
2828
}
29+
30+
.toggle-container {
31+
display: flex;
32+
align-items: center;
33+
gap: 0.5rem;
34+
margin-bottom: 0.5rem;
35+
margin-left: 0.3rem;
36+
width: 100%;
37+
}
38+
39+
.toggle-label {
40+
flex-grow: 1;
41+
margin-left: 0.5rem;
42+
}
43+
44+
.toggle-switch {
45+
position: relative;
46+
width: 35px;
47+
height: 18px;
48+
}
49+
50+
.slider {
51+
position: absolute;
52+
cursor: pointer;
53+
top: 0;
54+
left: 0;
55+
right: 0;
56+
bottom: 0;
57+
background-color: #ccc;
58+
transition: 0.4s;
59+
border-radius: 18px;
60+
}
61+
62+
.slider:before {
63+
position: absolute;
64+
content: "";
65+
height: 14px;
66+
width: 14px;
67+
border-radius: 50%;
68+
left: 2px;
69+
bottom: 2px;
70+
background-color: white;
71+
transition: 0.4s;
72+
}
73+
74+
input:checked + .slider {
75+
background-color: #4CAF50;
76+
}
77+
78+
input:checked + .slider:before {
79+
transform: translateX(17px);
80+
}

0 commit comments

Comments
 (0)