summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/components/topologies/map/RackSpaceFillContainer.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/RackSpaceFillContainer.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/RackSpaceFillContainer.js')
-rw-r--r--opendc-web/opendc-web-ui/src/components/topologies/map/RackSpaceFillContainer.js11
1 files changed, 8 insertions, 3 deletions
diff --git a/opendc-web/opendc-web-ui/src/components/topologies/map/RackSpaceFillContainer.js b/opendc-web/opendc-web-ui/src/components/topologies/map/RackSpaceFillContainer.js
index 0c15d54b..2039a9d3 100644
--- a/opendc-web/opendc-web-ui/src/components/topologies/map/RackSpaceFillContainer.js
+++ b/opendc-web/opendc-web-ui/src/components/topologies/map/RackSpaceFillContainer.js
@@ -25,13 +25,18 @@ import PropTypes from 'prop-types'
import { useSelector } from 'react-redux'
import RackFillBar from './elements/RackFillBar'
-function RackSpaceFillContainer({ tileId, ...props }) {
- const rack = useSelector((state) => state.topology.racks[state.topology.tiles[tileId].rack])
+function RackSpaceFillContainer({ rackId, ...props }) {
+ const rack = useSelector((state) => state.topology.racks[rackId])
+
+ if (!rack) {
+ return null
+ }
+
return <RackFillBar {...props} type="space" fillFraction={rack.machines.length / rack.capacity} />
}
RackSpaceFillContainer.propTypes = {
- tileId: PropTypes.string.isRequired,
+ rackId: PropTypes.string.isRequired,
}
export default RackSpaceFillContainer