Skip to content

Commit 5d5a384

Browse files
committed
fixing eslint errors on ubuntu
1 parent 773af4f commit 5d5a384

File tree

1 file changed

+77
-48
lines changed

1 file changed

+77
-48
lines changed

src/components/Tables/PowerSummaryTable.js

Lines changed: 77 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Tooltip } from 'antd';
55
import { PowerCell } from './TableCells';
66
import { fixed, color } from '../../utils/common';
77
import { State } from '../ComponentsLib';
8-
import { api, PATCH, GET, deviceInfo } from '../../utils/serverAPI';
8+
import { GET, deviceInfo } from '../../utils/serverAPI';
99
import '../style/PowerSummaryTable.css';
1010

1111
function PowerSummaryTableToolTip({ title, statusColor }) {
@@ -18,7 +18,9 @@ function PowerSummaryTableToolTip({ title, statusColor }) {
1818
);
1919
}
2020

21-
function PowerSummaryTable({ title, data = [], total = 0, percent = 0, deviceId = 'MPW1' }) {
21+
function PowerSummaryTable({
22+
title, data = [], total = 0, percent = 0, deviceId = 'MPW1',
23+
}) {
2224
const [thermalData, setThermalData] = useState({
2325
ambientTypical: 25,
2426
ambientWorstCase: 50,
@@ -45,54 +47,55 @@ function PowerSummaryTable({ title, data = [], total = 0, percent = 0, deviceId
4547
GET(deviceInfo(deviceId), (result) => {
4648
if (result && result.specification) {
4749
const { specification } = result;
48-
50+
4951
// Process thermal data
5052
setThermalData({
5153
ambientTypical: specification.thermal?.ambient?.typical || 25,
5254
ambientWorstCase: specification.thermal?.ambient?.worstcase || 50,
5355
thetaJa: specification.thermal?.theta_ja || 10,
5456
});
55-
57+
5658
// Process power data
5759
setPowerData({
5860
powerBudget: specification.power?.budget || 1.0,
5961
fpgaScaling: (specification.power?.typical_dynamic_scaling?.fpga_complex || 0) * 100,
60-
pcScaling: (specification.power?.typical_dynamic_scaling?.processing_complex || 0) * 100,
62+
pcScaling:
63+
(specification.power?.typical_dynamic_scaling?.processing_complex || 0) * 100,
6164
});
6265
}
6366
});
6467
} catch (error) {
6568
console.error('Error fetching data:', error);
6669
}
6770
};
68-
71+
6972
fetchData(); // Trigger the fetch function
70-
}, [deviceId]); // Re-run effect when deviceId changes
73+
}, [deviceId]); // Re-run effect when deviceId changes
7174

72-
const updateBackend = async (deviceId, thermalData, powerData) => {
75+
const updateBackend = async (deviceIdParam, thermalDataParam, powerDataParam) => {
7376
const updatedData = {
7477
specification: {
75-
thermal: {
76-
ambient: {
77-
typical: thermalData.ambientTypical || 0,
78-
worsecase: thermalData.ambientWorstCase || 0, // Note: This matches the schema
79-
},
80-
theta_ja: thermalData.thetaJa || 0,
78+
thermal: {
79+
ambient: {
80+
typical: thermalDataParam.ambientTypical || 0,
81+
worsecase: thermalDataParam.ambientWorstCase || 0, // Matches schema
8182
},
82-
power: {
83-
budget: powerData.powerBudget || 0,
84-
typical_dynamic_scaling: {
85-
fpga_complex: powerData.fpgaScaling || 0,
86-
processing_complex: powerData.pcScaling || 0,
87-
},
83+
theta_ja: thermalDataParam.thetaJa || 0,
84+
},
85+
power: {
86+
budget: powerDataParam.powerBudget || 0,
87+
typical_dynamic_scaling: {
88+
fpga_complex: powerDataParam.fpgaScaling || 0,
89+
processing_complex: powerDataParam.pcScaling || 0,
8890
},
91+
},
8992
},
90-
};
91-
93+
};
94+
9295
console.log('PATCH Payload:', JSON.stringify(updatedData, null, 2));
9396

9497
try {
95-
const response = await fetch(`http://127.0.0.1:5000/devices/${deviceId}`, {
98+
const response = await fetch(`http://127.0.0.1:5000/devices/${deviceIdParam}`, {
9699
method: 'PATCH',
97100
headers: {
98101
'Content-Type': 'application/json',
@@ -116,9 +119,9 @@ function PowerSummaryTable({ title, data = [], total = 0, percent = 0, deviceId
116119
const updatedPowerData = { ...powerData };
117120

118121
if (field in thermalData) {
119-
updatedThermalData[field] = isNaN(parseFloat(value)) ? 0 : parseFloat(value);
122+
updatedThermalData[field] = Number.isNaN(parseFloat(value)) ? 0 : parseFloat(value);
120123
} else {
121-
updatedPowerData[field] = isNaN(parseFloat(value)) ? 0 : parseFloat(value);
124+
updatedPowerData[field] = Number.isNaN(parseFloat(value)) ? 0 : parseFloat(value);
122125
}
123126

124127
setThermalData(updatedThermalData);
@@ -128,7 +131,7 @@ function PowerSummaryTable({ title, data = [], total = 0, percent = 0, deviceId
128131
};
129132

130133
const enforceNumericInput = (e) => {
131-
const value = e.target.value;
134+
const { value } = e.target;
132135
const valid = /^-?\d*\.?\d*%?$/.test(value);
133136
if (!valid) {
134137
e.target.value = value.slice(0, -1);
@@ -141,24 +144,30 @@ function PowerSummaryTable({ title, data = [], total = 0, percent = 0, deviceId
141144
}
142145
};
143146

144-
const getErrors = (messages) =>
145-
messages?.filter((item) => item.some((inner) => inner.type === 'error')) || [];
146-
const getWarnings = (messages) =>
147-
messages?.filter((item) => item.some((inner) => inner.type === 'warn')) || [];
147+
const getErrors = (messages) => messages?.filter((item) => item.some((inner) => inner.type === 'error')) || [];
148+
const getWarnings = (messages) => messages?.filter((item) => item.some((inner) => inner.type === 'warn')) || [];
148149

149-
const buildMessage = (messages) =>
150-
messages.reduce((acc, item, currentIndex) => {
151-
item.forEach((i, index) => acc.push(<span key={`${currentIndex}+${index}`}>{i.text}<br /></span>));
152-
return acc;
153-
}, []);
150+
const buildMessage = (messages) => messages.reduce((acc, item) => { // Removed `currentIndex`
151+
item.forEach((i) => acc.push(
152+
<span key={i.id}>
153+
{' '}
154+
{/* Replace with the unique property */}
155+
{i.text}
156+
<br />
157+
</span>,
158+
));
159+
return acc;
160+
}, []);
154161

155162
const message = (messages) => {
156163
const errors = getErrors(messages);
157164
return errors.length > 0 ? buildMessage(errors) : buildMessage(getWarnings(messages));
158165
};
159166

160-
const statusColor = (messages) =>
161-
color(getErrors(messages).length > 0, getWarnings(messages).length > 0);
167+
const statusColor = (messages) => color(
168+
getErrors(messages).length > 0,
169+
getWarnings(messages).length > 0,
170+
);
162171

163172
return (
164173
<div className="pst-container main-border">
@@ -168,7 +177,7 @@ function PowerSummaryTable({ title, data = [], total = 0, percent = 0, deviceId
168177
<table className="spec-table">
169178
<thead>
170179
<tr>
171-
<th></th>
180+
<th />
172181
<th className="typical-header">Typical</th>
173182
<th className="worst-header">Worst-Case</th>
174183
</tr>
@@ -184,7 +193,8 @@ function PowerSummaryTable({ title, data = [], total = 0, percent = 0, deviceId
184193
onInput={enforceNumericInput}
185194
ref={ambientTypicalRef}
186195
onKeyDown={(e) => handleKeyDown(e, ambientWorstCaseRef)}
187-
/>{' '}
196+
/>
197+
{' '}
188198
°C
189199
</td>
190200
<td className="value-cell">
@@ -195,7 +205,8 @@ function PowerSummaryTable({ title, data = [], total = 0, percent = 0, deviceId
195205
onInput={enforceNumericInput}
196206
ref={ambientWorstCaseRef}
197207
onKeyDown={(e) => handleKeyDown(e, thetaJaRef)}
198-
/>{' '}
208+
/>
209+
{' '}
199210
°C
200211
</td>
201212
</tr>
@@ -209,7 +220,8 @@ function PowerSummaryTable({ title, data = [], total = 0, percent = 0, deviceId
209220
onInput={enforceNumericInput}
210221
ref={thetaJaRef}
211222
onKeyDown={(e) => handleKeyDown(e, powerBudgetRef)}
212-
/>{' '}
223+
/>
224+
{' '}
213225
°C/W
214226
</td>
215227
</tr>
@@ -229,7 +241,8 @@ function PowerSummaryTable({ title, data = [], total = 0, percent = 0, deviceId
229241
onInput={enforceNumericInput}
230242
ref={powerBudgetRef}
231243
onKeyDown={(e) => handleKeyDown(e, fpgaScalingRef)}
232-
/>{' '}
244+
/>
245+
{' '}
233246
W
234247
</td>
235248
</tr>
@@ -244,7 +257,8 @@ function PowerSummaryTable({ title, data = [], total = 0, percent = 0, deviceId
244257
onInput={enforceNumericInput}
245258
ref={fpgaScalingRef}
246259
onKeyDown={(e) => handleKeyDown(e, pcScalingRef)}
247-
/>{' '}
260+
/>
261+
{' '}
248262
%
249263
</td>
250264
<td className="scaling-cell">
@@ -255,7 +269,8 @@ function PowerSummaryTable({ title, data = [], total = 0, percent = 0, deviceId
255269
onChange={(e) => handleFieldUpdate('pcScaling', e.target.value)}
256270
onInput={enforceNumericInput}
257271
ref={pcScalingRef}
258-
/>{' '}
272+
/>
273+
{' '}
259274
%
260275
</td>
261276
</tr>
@@ -268,8 +283,10 @@ function PowerSummaryTable({ title, data = [], total = 0, percent = 0, deviceId
268283
<div>
269284
<table className="pst-table">
270285
<tbody>
271-
{data.map((item, index) => (
272-
<tr key={index}>
286+
{data.map((item) => (
287+
<tr key={item.id}>
288+
{' '}
289+
{/* Use a unique property like `id` */}
273290
<td className="dot-td">
274291
<State messages={item.messages} baseClass="dot" />
275292
</td>
@@ -279,7 +296,8 @@ function PowerSummaryTable({ title, data = [], total = 0, percent = 0, deviceId
279296
{`${fixed(item.percent || 0, 0)} %`}
280297
</td>
281298
<td className="fixed-col">
282-
{(getErrors(item.messages).length > 0 || getWarnings(item.messages).length > 0) && (
299+
{(getErrors(item.messages).length > 0
300+
|| getWarnings(item.messages).length > 0) && (
283301
<PowerSummaryTableToolTip
284302
title={message(item.messages)}
285303
statusColor={statusColor(item.messages)}
@@ -309,7 +327,18 @@ function PowerSummaryTable({ title, data = [], total = 0, percent = 0, deviceId
309327

310328
PowerSummaryTable.propTypes = {
311329
title: PropTypes.string.isRequired,
312-
data: PropTypes.array.isRequired,
330+
data: PropTypes.arrayOf(
331+
PropTypes.shape({
332+
text: PropTypes.string, // Example property
333+
power: PropTypes.number, // Example property
334+
messages: PropTypes.arrayOf(
335+
PropTypes.shape({
336+
type: PropTypes.string.isRequired,
337+
content: PropTypes.string,
338+
}),
339+
), // Nested array of objects
340+
}),
341+
).isRequired,
313342
total: PropTypes.number.isRequired,
314343
percent: PropTypes.number.isRequired,
315344
deviceId: PropTypes.string.isRequired,

0 commit comments

Comments
 (0)