hotfix for how the device was being loaded when you open the device drawer of the construction map
This commit is contained in:
parent
41aa84d28f
commit
5ebbd01c3a
2 changed files with 27 additions and 42 deletions
|
|
@ -31,6 +31,7 @@ import React, { useCallback, useEffect, useState } from "react";
|
|||
//import { Redirect } from "react-router";
|
||||
import { or } from "utils/types";
|
||||
import DeviceActions from "./DeviceActions";
|
||||
import { getContextKeys, getContextTypes } from "pbHelpers/Context";
|
||||
|
||||
const useStyles = makeStyles((theme: Theme) => ({
|
||||
title: {
|
||||
|
|
@ -97,45 +98,28 @@ export default function Device(props: Props) {
|
|||
const load = useCallback(() => {
|
||||
if (user.id() === "") return;
|
||||
setIsLoading(true);
|
||||
//let devicePromise = deviceAPI.get(deviceID);
|
||||
let userPromise = userAPI.getUser(user.id(), deviceScope(deviceID.toString()));
|
||||
let componentsPromise = componentAPI.list(
|
||||
deviceID,
|
||||
undefined,
|
||||
[deviceID.toString()],
|
||||
["device"],
|
||||
true,
|
||||
as
|
||||
);
|
||||
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);
|
||||
});
|
||||
deviceAPI.getPageData(deviceID, getContextKeys(), getContextTypes(), as).then(resp => {
|
||||
console.log(resp)
|
||||
let rawComponents: Array<any> = or(resp.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);
|
||||
|
||||
setComponents(rComponents);
|
||||
|
||||
setInteractions(interactionsRes);
|
||||
setPermissions(userRes.permissions);
|
||||
setPreferences(userRes.preferences);
|
||||
|
||||
setDevice(props.device);
|
||||
setLongitude(props.device.status.longitude ? props.device.status.longitude : NaN);
|
||||
setLatitude(props.device.status.latitude ? props.device.status.latitude : NaN);
|
||||
let available = FindAvailablePositions(
|
||||
Array.from(rComponents.values()),
|
||||
props.device.settings.product
|
||||
);
|
||||
setAvailablePositions(available.GetAvailability());
|
||||
setAvailableOffsets(available.offsetAvailability);
|
||||
})
|
||||
.catch((err: any) => {
|
||||
setInteractions(resp.data.interactions.map(i => Interaction.create(i)))
|
||||
setPermissions(resp.data.permissions)
|
||||
setDevice(props.device);
|
||||
setLongitude(props.device.status.longitude ? props.device.status.longitude : NaN);
|
||||
setLatitude(props.device.status.latitude ? props.device.status.latitude : NaN);
|
||||
let available = FindAvailablePositions(
|
||||
Array.from(rComponents.values()),
|
||||
props.device.settings.product
|
||||
);
|
||||
setAvailablePositions(available.GetAvailability());
|
||||
setAvailableOffsets(available.offsetAvailability);
|
||||
}).catch(err => {
|
||||
setDevice(DeviceModel.create());
|
||||
setComponents(new Map());
|
||||
setInteractions([]);
|
||||
|
|
@ -145,8 +129,9 @@ export default function Device(props: Props) {
|
|||
setPreferences(pond.UserPreferences.create());
|
||||
setInvalidDevice(true);
|
||||
error(err);
|
||||
})
|
||||
.finally(() => setIsLoading(false));
|
||||
}).finally(() => {
|
||||
setIsLoading(false)
|
||||
})
|
||||
usageAPI
|
||||
.getUsage(deviceID, moment().subtract(1, "days"))
|
||||
.then((res: any) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue