summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-server/src/main/webui/redux
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-web/opendc-web-server/src/main/webui/redux')
-rw-r--r--opendc-web/opendc-web-server/src/main/webui/redux/actions/topology/room.js33
-rw-r--r--opendc-web/opendc-web-server/src/main/webui/redux/reducers/construction-mode.js13
-rw-r--r--opendc-web/opendc-web-server/src/main/webui/redux/reducers/topology/machine.js8
3 files changed, 45 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,
})
}
}
diff --git a/opendc-web/opendc-web-server/src/main/webui/redux/reducers/construction-mode.js b/opendc-web/opendc-web-server/src/main/webui/redux/reducers/construction-mode.js
index d0aac5ae..8520e794 100644
--- a/opendc-web/opendc-web-server/src/main/webui/redux/reducers/construction-mode.js
+++ b/opendc-web/opendc-web-server/src/main/webui/redux/reducers/construction-mode.js
@@ -37,7 +37,20 @@ export function inRackConstructionMode(state = false, action) {
}
}
+export function currentRackPrefab(state = null, action) {
+ switch (action.type) {
+ case START_RACK_CONSTRUCTION:
+ return action.rackPrefab || null
+ case STOP_RACK_CONSTRUCTION:
+ case GO_DOWN_ONE_INTERACTION_LEVEL:
+ return null
+ default:
+ return state
+ }
+}
+
export const construction = combineReducers({
currentRoomInConstruction,
inRackConstructionMode,
+ currentRackPrefab,
})
diff --git a/opendc-web/opendc-web-server/src/main/webui/redux/reducers/topology/machine.js b/opendc-web/opendc-web-server/src/main/webui/redux/reducers/topology/machine.js
index 1789257b..5cf38726 100644
--- a/opendc-web/opendc-web-server/src/main/webui/redux/reducers/topology/machine.js
+++ b/opendc-web/opendc-web-server/src/main/webui/redux/reducers/topology/machine.js
@@ -2,11 +2,19 @@ import produce from 'immer'
import { STORE_TOPOLOGY } from '../../actions/topology'
import { DELETE_MACHINE, ADD_UNIT, DELETE_UNIT } from '../../actions/topology/machine'
import { ADD_MACHINE, DELETE_RACK } from '../../actions/topology/rack'
+import { ADD_RACK_TO_TILE } from '../../actions/topology/room'
function machine(state = {}, action, { racks }) {
switch (action.type) {
case STORE_TOPOLOGY:
return action.entities.machines || {}
+ case ADD_RACK_TO_TILE:
+ return produce(state, (draft) => {
+ const { entities } = action
+ if (entities && entities.machines) {
+ Object.assign(draft, entities.machines)
+ }
+ })
case ADD_MACHINE:
return produce(state, (draft) => {
const { machine } = action