hotfix for how the device was being loaded when you open the device drawer of the construction map

This commit is contained in:
csawatzky 2026-01-28 15:29:55 -06:00
parent 41aa84d28f
commit 5ebbd01c3a
2 changed files with 27 additions and 42 deletions

4
package-lock.json generated
View file

@ -42,7 +42,7 @@
"mui-tel-input": "^7.0.0", "mui-tel-input": "^7.0.0",
"notistack": "^3.0.1", "notistack": "^3.0.1",
"openweathermap-ts": "^1.2.10", "openweathermap-ts": "^1.2.10",
"protobuf-ts": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#staging", "protobuf-ts": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#master",
"query-string": "^9.2.1", "query-string": "^9.2.1",
"react": "^18.3.1", "react": "^18.3.1",
"react-beautiful-dnd": "^13.1.1", "react-beautiful-dnd": "^13.1.1",
@ -10953,7 +10953,7 @@
}, },
"node_modules/protobuf-ts": { "node_modules/protobuf-ts": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#c9ef7906fd97cda8ef4bd149ec4a796159a7c067", "resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#bcf085706791036841f7047a5b37f00c18e54574",
"dependencies": { "dependencies": {
"protobufjs": "^6.8.8" "protobufjs": "^6.8.8"
} }

View file

@ -31,6 +31,7 @@ import React, { useCallback, useEffect, useState } from "react";
//import { Redirect } from "react-router"; //import { Redirect } from "react-router";
import { or } from "utils/types"; import { or } from "utils/types";
import DeviceActions from "./DeviceActions"; import DeviceActions from "./DeviceActions";
import { getContextKeys, getContextTypes } from "pbHelpers/Context";
const useStyles = makeStyles((theme: Theme) => ({ const useStyles = makeStyles((theme: Theme) => ({
title: { title: {
@ -97,45 +98,28 @@ export default function Device(props: Props) {
const load = useCallback(() => { const load = useCallback(() => {
if (user.id() === "") return; if (user.id() === "") return;
setIsLoading(true); setIsLoading(true);
//let devicePromise = deviceAPI.get(deviceID); deviceAPI.getPageData(deviceID, getContextKeys(), getContextTypes(), as).then(resp => {
let userPromise = userAPI.getUser(user.id(), deviceScope(deviceID.toString())); console.log(resp)
let componentsPromise = componentAPI.list( let rawComponents: Array<any> = or(resp.data.components, []);
deviceID, let rComponents: Map<string, Component> = new Map();
undefined, rawComponents.forEach((rawComponent: any) => {
[deviceID.toString()], let component = Component.any(rawComponent);
["device"], rComponents.set(component.key(), component);
true, });
as setComponents(rComponents);
);
let interactionsPromise = interactionsAPI.listInteractionsByDevice(deviceID, undefined, as);
let groupPromise: Promise<any> = Promise.resolve(undefined);
Promise.all([userPromise, componentsPromise, interactionsPromise, groupPromise])
.then(([userRes, componentsRes, interactionsRes]) => {
//let rDevice = DeviceModel.any(deviceRes.data);
let rawComponents: Array<any> = or(componentsRes.data.components, []);
let rComponents: Map<string, Component> = new Map();
rawComponents.forEach((rawComponent: any) => {
let component = Component.any(rawComponent);
rComponents.set(component.key(), component);
});
setComponents(rComponents); setInteractions(resp.data.interactions.map(i => Interaction.create(i)))
setPermissions(resp.data.permissions)
setInteractions(interactionsRes); setDevice(props.device);
setPermissions(userRes.permissions); setLongitude(props.device.status.longitude ? props.device.status.longitude : NaN);
setPreferences(userRes.preferences); setLatitude(props.device.status.latitude ? props.device.status.latitude : NaN);
let available = FindAvailablePositions(
setDevice(props.device); Array.from(rComponents.values()),
setLongitude(props.device.status.longitude ? props.device.status.longitude : NaN); props.device.settings.product
setLatitude(props.device.status.latitude ? props.device.status.latitude : NaN); );
let available = FindAvailablePositions( setAvailablePositions(available.GetAvailability());
Array.from(rComponents.values()), setAvailableOffsets(available.offsetAvailability);
props.device.settings.product }).catch(err => {
);
setAvailablePositions(available.GetAvailability());
setAvailableOffsets(available.offsetAvailability);
})
.catch((err: any) => {
setDevice(DeviceModel.create()); setDevice(DeviceModel.create());
setComponents(new Map()); setComponents(new Map());
setInteractions([]); setInteractions([]);
@ -145,8 +129,9 @@ export default function Device(props: Props) {
setPreferences(pond.UserPreferences.create()); setPreferences(pond.UserPreferences.create());
setInvalidDevice(true); setInvalidDevice(true);
error(err); error(err);
}) }).finally(() => {
.finally(() => setIsLoading(false)); setIsLoading(false)
})
usageAPI usageAPI
.getUsage(deviceID, moment().subtract(1, "days")) .getUsage(deviceID, moment().subtract(1, "days"))
.then((res: any) => { .then((res: any) => {