summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/components/topologies/map/RackEnergyFillContainer.js
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-09-20 11:04:34 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2022-09-20 16:07:06 +0200
commit0b3d0ba3193ebcdeadc6a4b0a192eeb06e9add29 (patch)
treef01e4990efd17b1ab0ed520ec39cd3aa5a0a0b09 /opendc-web/opendc-web-ui/src/components/topologies/map/RackEnergyFillContainer.js
parent98bc4c3e9458aea98890b770493f14327a7bc7c4 (diff)
fix(web/ui): Do not fail on stale Redux state
This change fixes an issue where switching between different topologies would fail due to stale Redux state. We have updated the components to take into account that ids may not exist in the Redux store.
Diffstat (limited to 'opendc-web/opendc-web-ui/src/components/topologies/map/RackEnergyFillContainer.js')
-rw-r--r--opendc-web/opendc-web-ui/src/components/topologies/map/RackEnergyFillContainer.js34
1 files changed, 18 insertions, 16 deletions
diff --git a/opendc-web/opendc-web-ui/src/components/topologies/map/RackEnergyFillContainer.js b/opendc-web/opendc-web-ui/src/components/topologies/map/RackEnergyFillContainer.js
index be1f3e45..a1ca7426 100644
--- a/opendc-web/opendc-web-ui/src/components/topologies/map/RackEnergyFillContainer.js
+++ b/opendc-web/opendc-web-ui/src/components/topologies/map/RackEnergyFillContainer.js
@@ -3,24 +3,26 @@ import PropTypes from 'prop-types'
import { useSelector } from 'react-redux'
import RackFillBar from './elements/RackFillBar'
-function RackSpaceFillContainer({ tileId, ...props }) {
+function RackSpaceFillContainer({ rackId, ...props }) {
const fillFraction = useSelector((state) => {
+ const rack = state.topology.racks[rackId]
+ if (!rack) {
+ return 0
+ }
+
+ const { machines, cpus, gpus, memories, storages } = state.topology
let energyConsumptionTotal = 0
- const rack = state.topology.racks[state.topology.tiles[tileId].rack]
- const machineIds = rack.machines
- machineIds.forEach((machineId) => {
- if (machineId !== null) {
- const machine = state.topology.machines[machineId]
- machine.cpus.forEach((id) => (energyConsumptionTotal += state.topology.cpus[id].energyConsumptionW))
- machine.gpus.forEach((id) => (energyConsumptionTotal += state.topology.gpus[id].energyConsumptionW))
- machine.memories.forEach(
- (id) => (energyConsumptionTotal += state.topology.memories[id].energyConsumptionW)
- )
- machine.storages.forEach(
- (id) => (energyConsumptionTotal += state.topology.storages[id].energyConsumptionW)
- )
+
+ for (const machineId of rack.machines) {
+ if (!machineId) {
+ continue
}
- })
+ const machine = machines[machineId]
+ machine.cpus.forEach((id) => (energyConsumptionTotal += cpus[id].energyConsumptionW))
+ machine.gpus.forEach((id) => (energyConsumptionTotal += gpus[id].energyConsumptionW))
+ machine.memories.forEach((id) => (energyConsumptionTotal += memories[id].energyConsumptionW))
+ machine.storages.forEach((id) => (energyConsumptionTotal += storages[id].energyConsumptionW))
+ }
return Math.min(1, energyConsumptionTotal / rack.powerCapacityW)
})
@@ -28,7 +30,7 @@ function RackSpaceFillContainer({ tileId, ...props }) {
}
RackSpaceFillContainer.propTypes = {
- tileId: PropTypes.string.isRequired,
+ rackId: PropTypes.string.isRequired,
}
export default RackSpaceFillContainer