fixed devices summary not loading through context
This commit is contained in:
parent
b0274ad639
commit
9eb9740525
6 changed files with 27 additions and 23 deletions
|
|
@ -385,7 +385,7 @@ export default function ResponsiveTable<T extends Object>(props: Props<T>) {
|
|||
</Box>}
|
||||
</Grid2>
|
||||
<Grid2>
|
||||
{ columns &&
|
||||
{ columns && !hideKeys &&
|
||||
<IconButton onClick={openColumnMenu} >
|
||||
<ViewColumn />
|
||||
</IconButton>
|
||||
|
|
|
|||
|
|
@ -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 />}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ import GroupSettings from "group/GroupSettings";
|
|||
import { Device, Group, groupScope } from "models";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { useState } from "react";
|
||||
// import ObjectTeams from "teams/ObjectTeams";
|
||||
import ObjectUsers from "user/ObjectUsers";
|
||||
import RemoveSelfFromObject from "user/RemoveSelfFromObject";
|
||||
import ShareObject from "user/ShareObject";
|
||||
|
|
@ -26,14 +25,7 @@ import { isOffline } from "utils/environment";
|
|||
import { makeStyles } from "@mui/styles";
|
||||
import ObjectTeams from "teams/ObjectTeams";
|
||||
|
||||
// const useStyles = makeStyles((theme: Theme) => {
|
||||
// // const isMobile = useMobile()
|
||||
// return ({
|
||||
|
||||
// });
|
||||
// });
|
||||
|
||||
const useStyles = makeStyles((theme: Theme) => {
|
||||
const useStyles = makeStyles((_theme: Theme) => {
|
||||
return ({
|
||||
shareIcon: {
|
||||
color: blue["500"],
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
import { createStyles, List, ListItem, ListItemText, Theme } from "@mui/material";
|
||||
// import { Theme } from "@material-ui/core/styles/createMuiTheme";
|
||||
// import withStyles, { WithStyles } from "@material-ui/core/styles/withStyles";
|
||||
import React from "react";
|
||||
import { Group } from "models";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { withStyles, WithStyles } from "@mui/styles";
|
||||
|
||||
const styles = (theme: Theme) =>
|
||||
const styles = (_theme: Theme) =>
|
||||
createStyles({
|
||||
listDirectionRow: {
|
||||
display: "flex",
|
||||
|
|
|
|||
|
|
@ -469,7 +469,7 @@ export default function Devices() {
|
|||
<Tab wrapped value={"never"} label={<CreateGroupIcon className={classes.green} />} onClick={() => openGroupSettings(undefined, "add")} />
|
||||
</Tabs>
|
||||
</Box>
|
||||
<DevicesSummary setFieldContains={setFieldContains} />
|
||||
<DevicesSummary setFieldContains={setFieldContains} group={getGroup()} />
|
||||
<ResponsiveTable<Device>
|
||||
title={<SmartBreadcrumb prependPaths={getGroup() && ["groups", getGroup().id().toString()]} groupName={getGroup() && getGroup().name()} paddingBottom={1}/>}
|
||||
subtitle={subtitle}
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
types?: string[]
|
||||
) => {
|
||||
let url = pondURL("/deviceStatistics");
|
||||
if (types && types.length > 0 && types[0] === "team")
|
||||
if (types && types.length > 0)
|
||||
url = pondURL(
|
||||
"/deviceStatistics/" +
|
||||
(keys ? "?keys=" + keys.toString() : "") +
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue