update battery view

This commit is contained in:
Noe 2024-03-11 16:08:20 +01:00
parent f77a86c4fc
commit d9ae1d7b94
1 changed files with 18 additions and 11 deletions

View File

@ -36,12 +36,22 @@ function BatteryView(props: BatteryViewProps) {
} }
const currentLocation = useLocation(); const currentLocation = useLocation();
const navigate = useNavigate(); const navigate = useNavigate();
const numOfBatteries = props.values.batteryView.length; const sortedBatteryView = [...props.values.batteryView].sort(
(a, b) => b.BatteryId - a.BatteryId
);
const handleMainStatsButton = () => { const handleMainStatsButton = () => {
navigate(routes.mainstats); navigate(routes.mainstats);
}; };
const findBatteryData = (batteryId: number) => {
for (let i = 0; i < props.values.batteryView.length; i++) {
if (props.values.batteryView[i].BatteryId == batteryId) {
return props.values.batteryView[i];
}
}
};
return ( return (
<> <>
<Container maxWidth="xl"> <Container maxWidth="xl">
@ -97,14 +107,14 @@ function BatteryView(props: BatteryViewProps) {
<MainStats s3Credentials={props.s3Credentials}></MainStats> <MainStats s3Credentials={props.s3Credentials}></MainStats>
} }
/> />
{Array.from({ length: numOfBatteries }).map((_, i) => ( {props.values.batteryView.map((battery) => (
<Route <Route
key={routes.detailed_view + i} key={routes.detailed_view + battery.BatteryId}
path={routes.detailed_view + i} path={routes.detailed_view + battery.BatteryId}
element={ element={
<DetailedBatteryView <DetailedBatteryView
s3Credentials={props.s3Credentials} s3Credentials={props.s3Credentials}
batteryData={props.values.batteryView[i]} batteryData={findBatteryData(battery.BatteryId)}
></DetailedBatteryView> ></DetailedBatteryView>
} }
/> />
@ -138,7 +148,7 @@ function BatteryView(props: BatteryViewProps) {
</TableRow> </TableRow>
</TableHead> </TableHead>
<TableBody> <TableBody>
{props.values.batteryView.map((battery) => ( {sortedBatteryView.map((battery) => (
<TableRow <TableRow
key={battery.BatteryId} key={battery.BatteryId}
style={{ style={{
@ -153,12 +163,9 @@ function BatteryView(props: BatteryViewProps) {
> >
<Link <Link
style={{ color: 'black' }} style={{ color: 'black' }}
to={ to={routes.detailed_view + battery.BatteryId.toString()}
routes.detailed_view +
(battery.BatteryId - 1).toString()
}
> >
{'Battery ' + battery.BatteryId} {'Node ' + battery.BatteryId}
</Link> </Link>
</TableCell> </TableCell>
<TableCell <TableCell