From 235057cd170f1583db14bf93ea7d2de39e492356 Mon Sep 17 00:00:00 2001 From: vincent van beek Date: Fri, 27 Mar 2026 14:22:41 +0100 Subject: add prefabs for racks (#392) * add prefabs for racks --- .../src/main/webui/redux/actions/topology/room.js | 33 ++++++++++++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'opendc-web/opendc-web-server/src/main/webui/redux/actions') 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, }) } } -- cgit v1.2.3