Improve home page
This commit is contained in:
parent
cb798dfd14
commit
7f9db9f2cc
@ -11,12 +11,14 @@ import {
|
|||||||
Tooltip,
|
Tooltip,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { DeviceRelay } from "../api/DeviceApi";
|
import { Device, DeviceApi, DeviceRelay, DeviceURL } from "../api/DeviceApi";
|
||||||
import { RelayApi, RelaysStatus } from "../api/RelayApi";
|
import { RelayApi, RelaysStatus } from "../api/RelayApi";
|
||||||
import { AsyncWidget } from "../widgets/AsyncWidget";
|
import { AsyncWidget } from "../widgets/AsyncWidget";
|
||||||
import { BoolText } from "../widgets/BoolText";
|
import { BoolText } from "../widgets/BoolText";
|
||||||
import { SolarEnergyRouteContainer } from "../widgets/SolarEnergyRouteContainer";
|
import { SolarEnergyRouteContainer } from "../widgets/SolarEnergyRouteContainer";
|
||||||
import { TimeWidget } from "../widgets/TimeWidget";
|
import { TimeWidget } from "../widgets/TimeWidget";
|
||||||
|
import { EditDeviceRelaysDialog } from "../dialogs/EditDeviceRelaysDialog";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
export function RelaysListRoute(p: {
|
export function RelaysListRoute(p: {
|
||||||
homeWidget?: boolean;
|
homeWidget?: boolean;
|
||||||
@ -24,10 +26,12 @@ export function RelaysListRoute(p: {
|
|||||||
const loadKey = React.useRef(1);
|
const loadKey = React.useRef(1);
|
||||||
|
|
||||||
const [list, setList] = React.useState<DeviceRelay[] | undefined>();
|
const [list, setList] = React.useState<DeviceRelay[] | undefined>();
|
||||||
|
const [devices, setDevices] = React.useState<Device[] | undefined>();
|
||||||
const [status, setStatus] = React.useState<RelaysStatus | undefined>();
|
const [status, setStatus] = React.useState<RelaysStatus | undefined>();
|
||||||
|
|
||||||
const load = async () => {
|
const load = async () => {
|
||||||
setList(await RelayApi.GetList());
|
setList(await RelayApi.GetList());
|
||||||
|
setDevices(await DeviceApi.ValidatedList());
|
||||||
setStatus(await RelayApi.GetRelaysStatus());
|
setStatus(await RelayApi.GetRelaysStatus());
|
||||||
|
|
||||||
list?.sort((a, b) => b.priority - a.priority);
|
list?.sort((a, b) => b.priority - a.priority);
|
||||||
@ -39,6 +43,7 @@ export function RelaysListRoute(p: {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
<SolarEnergyRouteContainer
|
<SolarEnergyRouteContainer
|
||||||
label="Relays list"
|
label="Relays list"
|
||||||
homeWidget={p.homeWidget}
|
homeWidget={p.homeWidget}
|
||||||
@ -56,21 +61,35 @@ export function RelaysListRoute(p: {
|
|||||||
errMsg="Failed to load the list of relays!"
|
errMsg="Failed to load the list of relays!"
|
||||||
load={load}
|
load={load}
|
||||||
build={() => (
|
build={() => (
|
||||||
<RelaysList onReload={reload} list={list!} status={status!} />
|
<RelaysList
|
||||||
|
onReload={reload}
|
||||||
|
list={list!}
|
||||||
|
devices={devices!}
|
||||||
|
status={status!}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</SolarEnergyRouteContainer>
|
</SolarEnergyRouteContainer>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function RelaysList(p: {
|
function RelaysList(p: {
|
||||||
list: DeviceRelay[];
|
list: DeviceRelay[];
|
||||||
|
devices: Device[];
|
||||||
status: RelaysStatus;
|
status: RelaysStatus;
|
||||||
onReload: () => void;
|
onReload: () => void;
|
||||||
}): React.ReactElement {
|
}): 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 (
|
return (
|
||||||
<TableContainer component={Paper}>
|
<TableContainer component={Paper}>
|
||||||
<Table sx={{ minWidth: 650 }} aria-label="simple table">
|
<Table sx={{ minWidth: 650 }}>
|
||||||
<TableHead>
|
<TableHead>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell>Name</TableCell>
|
<TableCell>Name</TableCell>
|
||||||
@ -85,6 +104,8 @@ function RelaysList(p: {
|
|||||||
<TableRow
|
<TableRow
|
||||||
key={row.name}
|
key={row.name}
|
||||||
sx={{ "&:last-child td, &:last-child th": { border: 0 } }}
|
sx={{ "&:last-child td, &:last-child th": { border: 0 } }}
|
||||||
|
hover
|
||||||
|
onDoubleClick={() => openDevicePage(row)}
|
||||||
>
|
>
|
||||||
<TableCell>{row.name}</TableCell>
|
<TableCell>{row.name}</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
|
@ -103,7 +103,7 @@ export default function StatCard({
|
|||||||
{interval}
|
{interval}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Box sx={{ width: "100%", height: 50 }}>
|
<Box sx={{ width: "100%", height: 100 }}>
|
||||||
{data && interval && (
|
{data && interval && (
|
||||||
<SparkLineChart
|
<SparkLineChart
|
||||||
colors={[chartColor]}
|
colors={[chartColor]}
|
||||||
|
Loading…
Reference in New Issue
Block a user