groups tab is now saved to session storage
This commit is contained in:
parent
0cd0921c63
commit
cefb34dbbb
1 changed files with 31 additions and 6 deletions
|
|
@ -27,6 +27,8 @@ import StatusSen5x from "common/StatusSen5x";
|
||||||
import StatusDust from "common/StatusDust";
|
import StatusDust from "common/StatusDust";
|
||||||
import StatusGas from "common/StatusGas";
|
import StatusGas from "common/StatusGas";
|
||||||
import { cloneDeep } from "lodash";
|
import { cloneDeep } from "lodash";
|
||||||
|
import { or } from "utils";
|
||||||
|
import LoadingScreen from "app/LoadingScreen";
|
||||||
|
|
||||||
const useStyles = makeStyles((theme: Theme) => {
|
const useStyles = makeStyles((theme: Theme) => {
|
||||||
return ({
|
return ({
|
||||||
|
|
@ -140,9 +142,22 @@ export default function Devices() {
|
||||||
// const [totalGroups, setTotalGroups] = useState(0);
|
// const [totalGroups, setTotalGroups] = useState(0);
|
||||||
|
|
||||||
const [groupPermissions, setGroupPermissions] = useState<pond.Permission[]>([])
|
const [groupPermissions, setGroupPermissions] = useState<pond.Permission[]>([])
|
||||||
|
const [groupsLoaded, setGroupsLoaded] = useState(false)
|
||||||
|
|
||||||
const groupID = useParams<{ groupID: string }>()?.groupID ?? "all";
|
const groupID = useParams<{ groupID: string }>()?.groupID ?? "all";
|
||||||
const [tab, setTab] = useState(groupID==="all" ? groupID : groupID);
|
// const [tab, setTab] = useState(groupID==="all" ? groupID : groupID);
|
||||||
|
const [tab, setTab] = useState(() => {
|
||||||
|
console.log("groupID: "+groupID)
|
||||||
|
if (groupID!=="all") return groupID
|
||||||
|
const stored = sessionStorage.getItem(location.pathname+"-groups-tab");
|
||||||
|
console.log("stored: "+stored)
|
||||||
|
return stored !== null ? stored : "all";
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log(tab)
|
||||||
|
sessionStorage.setItem(location.pathname+"-groups-tab", tab);
|
||||||
|
}, [tab]);
|
||||||
|
|
||||||
const [selectedGroup, setSelectedGroup] = useState<Group | undefined>(undefined);
|
const [selectedGroup, setSelectedGroup] = useState<Group | undefined>(undefined);
|
||||||
const [groupSettingsMode, setGroupSettingsMode] = useState<
|
const [groupSettingsMode, setGroupSettingsMode] = useState<
|
||||||
|
|
@ -184,7 +199,7 @@ export default function Devices() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setGroupPermissions([])
|
setGroupPermissions([])
|
||||||
if (tab === "all") return
|
if (tab === "all" || !getGroup()) return
|
||||||
groupAPI.getGroupPermissions(getGroup().id()).then(resp => {
|
groupAPI.getGroupPermissions(getGroup().id()).then(resp => {
|
||||||
setGroupPermissions(resp.data.permissions)
|
setGroupPermissions(resp.data.permissions)
|
||||||
})
|
})
|
||||||
|
|
@ -232,7 +247,7 @@ export default function Devices() {
|
||||||
};
|
};
|
||||||
|
|
||||||
const getKeys = () => {
|
const getKeys = () => {
|
||||||
if (tab !== "all") {
|
if (tab !== "all" && getGroup()) {
|
||||||
let keys = getContextKeys()
|
let keys = getContextKeys()
|
||||||
//keys.splice(keys.length - 1, 0, getGroup().id().toString());
|
//keys.splice(keys.length - 1, 0, getGroup().id().toString());
|
||||||
keys.push(getGroup().id().toString());
|
keys.push(getGroup().id().toString());
|
||||||
|
|
@ -274,11 +289,13 @@ export default function Devices() {
|
||||||
updateGroups(newGroups)
|
updateGroups(newGroups)
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
setGroupsLoading(false)
|
setGroupsLoading(false)
|
||||||
|
setGroupsLoaded(true)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadDevices = () => {
|
const loadDevices = () => {
|
||||||
setDevicesLoading(true)
|
setDevicesLoading(true)
|
||||||
|
if (!groupsLoaded) return
|
||||||
deviceAPI.list(
|
deviceAPI.list(
|
||||||
limit,
|
limit,
|
||||||
page*limit,
|
page*limit,
|
||||||
|
|
@ -316,7 +333,7 @@ export default function Devices() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadDevices()
|
loadDevices()
|
||||||
}, [limit, page, order, orderBy, fieldContains, search, tab, as])
|
}, [limit, page, order, orderBy, fieldContains, search, tab, as, groupsLoaded])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadGroups()
|
loadGroups()
|
||||||
|
|
@ -703,6 +720,14 @@ export default function Devices() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log('Current tab value:', tab, typeof tab);
|
||||||
|
}, [tab]);
|
||||||
|
|
||||||
|
if (!groupsLoaded) return (
|
||||||
|
<LoadingScreen message="Loading groups" />
|
||||||
|
)
|
||||||
|
|
||||||
return(
|
return(
|
||||||
<PageContainer padding={isMobile ? 0 : 2}>
|
<PageContainer padding={isMobile ? 0 : 2}>
|
||||||
<Box
|
<Box
|
||||||
|
|
@ -725,7 +750,7 @@ export default function Devices() {
|
||||||
<Tab value={"loading"} label={<Skeleton variant="rectangular" height={24} width={128} animation="pulse" />}/>
|
<Tab value={"loading"} label={<Skeleton variant="rectangular" height={24} width={128} animation="pulse" />}/>
|
||||||
: groups.map((group, index) => {
|
: groups.map((group, index) => {
|
||||||
if (group.id()) return (
|
if (group.id()) return (
|
||||||
<Tab className={classes.tab} wrapped value={index} label={<Typography variant="inherit" noWrap>{group.name()}</Typography>} key={"group-tab-"+index}/>
|
<Tab className={classes.tab} wrapped value={index.toString()} label={<Typography variant="inherit" noWrap>{group.name()}</Typography>} key={"group-tab-"+index}/>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
<Tab wrapped value={"never"} label={<CreateGroupIcon className={classes.green} />} onClick={() => openGroupSettings(undefined, "add")} />
|
<Tab wrapped value={"never"} label={<CreateGroupIcon className={classes.green} />} onClick={() => openGroupSettings(undefined, "add")} />
|
||||||
|
|
@ -784,7 +809,7 @@ export default function Devices() {
|
||||||
newDevices.push(Device.create(device))
|
newDevices.push(Device.create(device))
|
||||||
})
|
})
|
||||||
setDevices(currentRows.concat(newDevices))
|
setDevices(currentRows.concat(newDevices))
|
||||||
}).catch(err => {
|
}).catch(_err => {
|
||||||
|
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue