From 7f9db9f2cc101a5a745a7a04e305add0c5f63570 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 26 Sep 2024 23:21:56 +0200 Subject: [PATCH] Improve home page --- .../src/routes/RelaysListRoute.tsx | 67 ++++++++++++------- central_frontend/src/widgets/StatCard.tsx | 2 +- 2 files changed, 45 insertions(+), 24 deletions(-) diff --git a/central_frontend/src/routes/RelaysListRoute.tsx b/central_frontend/src/routes/RelaysListRoute.tsx index bb69731..8a04555 100644 --- a/central_frontend/src/routes/RelaysListRoute.tsx +++ b/central_frontend/src/routes/RelaysListRoute.tsx @@ -11,12 +11,14 @@ import { Tooltip, } from "@mui/material"; import React from "react"; -import { DeviceRelay } from "../api/DeviceApi"; +import { Device, DeviceApi, DeviceRelay, DeviceURL } from "../api/DeviceApi"; import { RelayApi, RelaysStatus } from "../api/RelayApi"; import { AsyncWidget } from "../widgets/AsyncWidget"; import { BoolText } from "../widgets/BoolText"; import { SolarEnergyRouteContainer } from "../widgets/SolarEnergyRouteContainer"; import { TimeWidget } from "../widgets/TimeWidget"; +import { EditDeviceRelaysDialog } from "../dialogs/EditDeviceRelaysDialog"; +import { useNavigate } from "react-router-dom"; export function RelaysListRoute(p: { homeWidget?: boolean; @@ -24,10 +26,12 @@ export function RelaysListRoute(p: { const loadKey = React.useRef(1); const [list, setList] = React.useState(); + const [devices, setDevices] = React.useState(); const [status, setStatus] = React.useState(); const load = async () => { setList(await RelayApi.GetList()); + setDevices(await DeviceApi.ValidatedList()); setStatus(await RelayApi.GetRelaysStatus()); list?.sort((a, b) => b.priority - a.priority); @@ -39,38 +43,53 @@ export function RelaysListRoute(p: { }; return ( - - - - - - } - > - ( - - )} - /> - + <> + + + + + + } + > + ( + + )} + /> + + ); } function RelaysList(p: { list: DeviceRelay[]; + devices: Device[]; status: RelaysStatus; onReload: () => void; }): React.ReactElement { + const navigate = useNavigate(); + + const openDevicePage = (relay: DeviceRelay) => { + const dev = p.devices.find((d) => d.relays.find((r) => r.id === relay.id)); + navigate(DeviceURL(dev!)); + }; + return ( - +
Name @@ -85,6 +104,8 @@ function RelaysList(p: { openDevicePage(row)} > {row.name} diff --git a/central_frontend/src/widgets/StatCard.tsx b/central_frontend/src/widgets/StatCard.tsx index 64872ab..7a8d91b 100644 --- a/central_frontend/src/widgets/StatCard.tsx +++ b/central_frontend/src/widgets/StatCard.tsx @@ -103,7 +103,7 @@ export default function StatCard({ {interval} - + {data && interval && (