summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-server/src/main/webui/redux/actions
diff options
context:
space:
mode:
authorvincent van beek <vincent@vlogic.nl>2026-03-27 14:22:41 +0100
committerGitHub <noreply@github.com>2026-03-27 13:22:41 +0000
commit235057cd170f1583db14bf93ea7d2de39e492356 (patch)
tree157e9214c3f835d007bdbd265e3ca883e1326fcb /opendc-web/opendc-web-server/src/main/webui/redux/actions
parent0ffde21b0337c606e2d0ece5bd5434a930a87dcd (diff)
add prefabs for racks (#392)
* add prefabs for racks
Diffstat (limited to 'opendc-web/opendc-web-server/src/main/webui/redux/actions')
-rw-r--r--opendc-web/opendc-web-server/src/main/webui/redux/actions/topology/room.js33
1 files changed, 24 insertions, 9 deletions
diff --git a/opendc-web/opendc-web-server/src/main/webui/redux/actions/topology/room.js b/opendc-web/opendc-web-server/src/main/webui/redux/actions/topology/room.js
index 14cc126c..70c93d1f 100644
--- a/opendc-web/opendc-web-server/src/main/webui/redux/actions/topology/room.js
+++ b/opendc-web/opendc-web-server/src/main/webui/redux/actions/topology/room.js
@@ -1,4 +1,6 @@
import { v4 as uuid } from 'uuid'
+import { normalize } from 'normalizr'
+import { Rack as RackSchema } from '../../../util/topology-schema'
import {
DEFAULT_RACK_SLOT_CAPACITY,
DEFAULT_RACK_POWER_CAPACITY,
@@ -31,9 +33,10 @@ export function editRoomName(roomId, name) {
}
}
-export function startRackConstruction() {
+export function startRackConstruction(rackPrefab) {
return {
type: START_RACK_CONSTRUCTION,
+ rackPrefab,
}
}
@@ -45,22 +48,34 @@ export function stopRackConstruction() {
export function addRackToTile(positionX, positionY) {
return (dispatch, getState) => {
- const { topology, interactionLevel } = getState()
+ const { topology, interactionLevel, construction } = getState()
const currentRoom = topology.rooms[interactionLevel.roomId]
const tiles = currentRoom.tiles.map((tileId) => topology.tiles[tileId])
const tile = findTileWithPosition(tiles, positionX, positionY)
if (tile !== null) {
+ const prefab = construction.currentRackPrefab
+ const rackId = uuid()
+ const rack = prefab
+ ? {
+ ...prefab.rack,
+ id: rackId,
+ machines: (prefab.rack.machines || []).map((m) => ({ ...m, id: uuid(), rackId })),
+ }
+ : {
+ id: rackId,
+ name: 'Rack',
+ capacity: DEFAULT_RACK_SLOT_CAPACITY,
+ powerCapacityW: DEFAULT_RACK_POWER_CAPACITY,
+ machines: [],
+ }
+
+ const { entities, result: normalizedRackId } = normalize(rack, RackSchema)
dispatch({
type: ADD_RACK_TO_TILE,
tileId: tile.id,
- rack: {
- id: uuid(),
- name: 'Rack',
- capacity: DEFAULT_RACK_SLOT_CAPACITY,
- powerCapacityW: DEFAULT_RACK_POWER_CAPACITY,
- machines: [],
- },
+ rack: entities.racks[normalizedRackId],
+ entities,
})
}
}