fixed devices summary not loading through context

This commit is contained in:
Carter 2025-03-06 14:34:46 -06:00
parent b0274ad639
commit 9eb9740525
6 changed files with 27 additions and 23 deletions

View file

@ -9,6 +9,7 @@ import { green } from "@mui/material/colors";
import { makeStyles } from "@mui/styles";
import classNames from "classnames";
import CircleGraphIcon from "common/CircleGraphIcon";
import { Group } from "models";
import { getContextKeys, getContextTypes } from "pbHelpers/Context";
import { pond } from "protobuf-ts/pond";
import { useDeviceAPI } from "providers";
@ -34,10 +35,11 @@ const useStyles = makeStyles((theme: Theme) => {
interface Props {
setFieldContains: React.Dispatch<React.SetStateAction<Map<string, string>>>,
group?: Group;
}
export default function DevicesSummary(props: Props) {
const { setFieldContains } = props;
const { setFieldContains, group } = props;
const deviceAPI = useDeviceAPI()
const theme = useTheme()
const classes = useStyles()
@ -46,11 +48,23 @@ export default function DevicesSummary(props: Props) {
const [loadingStats, setLoadingStats] = useState(false)
const [selected, setSelected] = useState("");
const getKeys = () => {
let keys = getContextKeys()
if (group) keys.push(group.id().toString())
return keys
}
const getTypes = () => {
let types = getContextTypes()
if (group) types.push("group")
return types
}
const loadDeviceStatistics = () => {
setLoadingStats(true)
deviceAPI.statistics(
getContextKeys(),
getContextTypes()
getKeys(),
getTypes()
).then(resp => {
let stats = pond.DeviceStatistics.fromObject(resp.data.stats)
setStats(stats)
@ -61,7 +75,7 @@ export default function DevicesSummary(props: Props) {
useEffect(() => {
loadDeviceStatistics()
}, [])
}, [group])
useEffect(() => {
switch (selected) {
@ -101,7 +115,7 @@ export default function DevicesSummary(props: Props) {
<Grid2>
<CircleGraphIcon
sx={{ marginRight: 1, marginLeft: 1 }}
progress={100}
progress={loadingStats ? undefined : 100}
color={"info"}
icon={<AutoAwesomeMosaic />}
/>
@ -131,7 +145,7 @@ export default function DevicesSummary(props: Props) {
<Grid2>
<CircleGraphIcon
sx={{ marginRight: 1, marginLeft: 1 }}
progress={getPercent(stats.active)}
progress={!loadingStats ? getPercent(stats.active) : undefined}
color={"success"}
icon={<Check />}
/>
@ -161,7 +175,7 @@ export default function DevicesSummary(props: Props) {
<Grid2>
<CircleGraphIcon
sx={{ marginRight: 1, marginLeft: 1 }}
progress={getPercent(stats.warning)}
progress={!loadingStats ? getPercent(stats.warning) : undefined}
color="warning"
icon={<Battery20 />}
/>
@ -191,7 +205,7 @@ export default function DevicesSummary(props: Props) {
<Grid2>
<CircleGraphIcon
sx={{ marginRight: 1, marginLeft: 1 }}
progress={100}
progress={!loadingStats ? getPercent(stats.warning) : undefined}
color={green[50]}
icon={<PermScanWifi />}
/>