Fix Loading Error when data not loaded on time from DB.

This commit is contained in:
Andrés Uribe Stengel 2020-07-23 18:32:32 +02:00
parent 8da0b54d2b
commit 4e8d270eba
2 changed files with 18 additions and 5 deletions

View File

@ -73,7 +73,7 @@ export default function Overview() {
</Form>
</Col>
<Col>
<h6>active device: {ConfiguredDevicesCollection.findOne({deviceId: activeDevice.deviceId}).alias}</h6>
<h6>active device: {ConfiguredDevicesCollection.findOne({deviceId: activeDevice.deviceId}) === undefined ? "No device selected" : ConfiguredDevicesCollection.findOne({deviceId: activeDevice.deviceId}).alias}</h6>
</Col>
</Row>

View File

@ -14,19 +14,32 @@ export default function SensorCardDeck() {
});
const sensorData = useTracker(() => {
return SensorDataCollection.find({ device_id: deviceId.deviceId }, { sort: { timestamp: -1 }, limit: 1 }).fetch();
if (deviceId === null || deviceId === undefined) {
return undefined;
} else {
return SensorDataCollection.find({device_id: deviceId.deviceId}, {sort: {timestamp: -1}, limit: 1}).fetch();
}
});
const plantType = useTracker(() => {
return ConfiguredDevicesCollection.findOne({ deviceId: deviceId.deviceId }).type;
if (deviceId === null || deviceId === undefined) {
return undefined;
} else {
return ConfiguredDevicesCollection.findOne({deviceId: deviceId.deviceId});
}
});
const plantTypeData = useTracker(() => {
return PlantTypesCollection.findOne({ plantType: plantType });
if (plantType === null || plantType === undefined) {
return undefined;
} else {
return PlantTypesCollection.findOne({plantType: plantType.type});
}
});
console.log("Sens" + sensorData, plantType, plantTypeData, deviceId);
if (sensorData.length <= 0) {
if (sensorData.length <= 0 || plantType === undefined || deviceId === undefined || plantTypeData === undefined) {
return (
<CardDeck>
<Card>