smart bread crumbs can be given a navigation state

This commit is contained in:
Carter 2025-05-12 10:14:31 -06:00
parent 809acae6fc
commit 61bdff0cef
4 changed files with 16 additions and 8 deletions

View file

@ -12,7 +12,7 @@ import {
} from "@mui/material"; } from "@mui/material";
import { Replay } from "@mui/icons-material"; import { Replay } from "@mui/icons-material";
import { useMobile } from "hooks"; import { useMobile } from "hooks";
import { ReactNode, useEffect, useRef } from "react"; import { ReactNode } from "react";
import { useLocation } from "react-router"; import { useLocation } from "react-router";
import { Link as RouterLink } from "react-router-dom"; import { Link as RouterLink } from "react-router-dom";
import { or } from "utils/types"; import { or } from "utils/types";
@ -58,12 +58,13 @@ interface Props {
paddingTop?: number; paddingTop?: number;
paddingBottom?: number; paddingBottom?: number;
prependPaths?: string[]; prependPaths?: string[];
state?: any;
} }
interface LinkRouterProps extends LinkProps { interface LinkRouterProps extends LinkProps {
to: string; to: string;
replace?: boolean; replace?: boolean;
state?: any;
} }
const LinkRouter = (props: LinkRouterProps) => <Link {...props} component={RouterLink as any} />; const LinkRouter = (props: LinkRouterProps) => <Link {...props} component={RouterLink as any} />;
@ -74,7 +75,7 @@ export default function SmartBreadcrumb(props: Props) {
const location = useLocation(); const location = useLocation();
const isMobile = useMobile(); const isMobile = useMobile();
const classes = useStyles(); const classes = useStyles();
const { loading, reload } = props; const { loading, reload, state } = props;
const groupID = (): string => { const groupID = (): string => {
let index = prependPaths?.indexOf("groups") let index = prependPaths?.indexOf("groups")
@ -316,7 +317,7 @@ export default function SmartBreadcrumb(props: Props) {
links.push( links.push(
<Chip <Chip
key={"support-chip"} key={"support-chip"}
variant={"outlined"} variant={"filled"}
label={ label={
<Typography variant="subtitle1" color="textPrimary"> <Typography variant="subtitle1" color="textPrimary">
Support Support
@ -341,6 +342,7 @@ export default function SmartBreadcrumb(props: Props) {
color={lastPath ? "textPrimary" : "textSecondary"} color={lastPath ? "textPrimary" : "textSecondary"}
variant="subtitle1" variant="subtitle1"
to={to} to={to}
state={state}
sx={{ '&:hover': { color: getThemeType() === "dark" ? 'white' : "black" }}} sx={{ '&:hover': { color: getThemeType() === "dark" ? 'white' : "black" }}}
className={classes.textOverflow}> className={classes.textOverflow}>
{label} {label}

View file

@ -176,12 +176,12 @@ export default function StatusPlenum(props: Props) {
> >
<Grid2> <Grid2>
<Typography variant="body2" style={{ color: blue[300]}}> <Typography variant="body2" style={{ color: blue[300]}}>
{device.status.sen5x?.voc.toFixed(1)}% V: {device.status.sen5x?.voc.toFixed(1)}%
</Typography> </Typography>
</Grid2> </Grid2>
<Grid2> <Grid2>
<Typography variant="body2" style={{ color: blue[400]}}> <Typography variant="body2" style={{ color: blue[400]}}>
{device.status.sen5x?.nox.toFixed(1)}% N: {device.status.sen5x?.nox.toFixed(1)}%
</Typography> </Typography>
</Grid2> </Grid2>
</Grid2> </Grid2>

View file

@ -30,6 +30,7 @@ export default function DevicePage() {
const groupID = useParams<{ groupID: string }>()?.groupID ?? ""; const groupID = useParams<{ groupID: string }>()?.groupID ?? "";
const { state } = useLocation(); const { state } = useLocation();
const [{ as, team, user }] = useGlobalState() const [{ as, team, user }] = useGlobalState()
// console.log(state)
const [device, setDevice] = useState<Device>(state?.device ? Device.create(state.device) : Device.create()) const [device, setDevice] = useState<Device>(state?.device ? Device.create(state.device) : Device.create())
const [loading, setLoading] = useState(false) const [loading, setLoading] = useState(false)
const [permissions, setPermissions] = useState<pond.Permission[]>([]) const [permissions, setPermissions] = useState<pond.Permission[]>([])
@ -54,6 +55,11 @@ export default function DevicePage() {
const loadDevice = () => { const loadDevice = () => {
// console.log("load device page data") // console.log("load device page data")
if (loading) return if (loading) return
console.log(state)
if (state?.device) {
console.log(Device.create(state.device))
return
}
setLoading(true) setLoading(true)
deviceAPI.getPageData(deviceID, getContextKeys(), getContextTypes(), as).then(resp => { deviceAPI.getPageData(deviceID, getContextKeys(), getContextTypes(), as).then(resp => {
let device = Device.any(resp.data.device) let device = Device.any(resp.data.device)
@ -418,7 +424,7 @@ export default function DevicePage() {
<PageContainer padding={isMobile ? 0 : 2}> <PageContainer padding={isMobile ? 0 : 2}>
<Grid container justifyContent={"space-between"}> <Grid container justifyContent={"space-between"}>
<Grid> <Grid>
<SmartBreadcrumb /> <SmartBreadcrumb deviceName={device.name()} />
</Grid> </Grid>
<Grid> <Grid>
<AddComponentManualDialog <AddComponentManualDialog

View file

@ -134,7 +134,7 @@ export default function DeviceSupport() {
return ( return (
<PageContainer> <PageContainer>
<SmartBreadcrumb deviceName={device.name()} /> <SmartBreadcrumb deviceName={device.name()} state={{device: device}} />
<Tabs <Tabs
style={{ position: "sticky" }} style={{ position: "sticky" }}
value={tabNumber} value={tabNumber}