From 0c15fdab70d433b6f5338176c3359e7a6ff0ff57 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Fri, 8 Sep 2017 21:15:03 +0200 Subject: Implement unit count limit per machine --- src/sagas/topology.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/sagas') diff --git a/src/sagas/topology.js b/src/sagas/topology.js index d674c695..9c5087cc 100644 --- a/src/sagas/topology.js +++ b/src/sagas/topology.js @@ -21,6 +21,11 @@ import { updateMachineInRackOnTile, updateRackOnTile } from "../api/routes/tiles"; +import { + DEFAULT_RACK_POWER_CAPACITY, + DEFAULT_RACK_SLOT_CAPACITY, + MAX_NUM_UNITS_PER_MACHINE +} from "../components/map/MapConstants"; import { fetchAndStoreAllCPUs, fetchAndStoreAllGPUs, @@ -236,8 +241,8 @@ export function* onAddRackToTile(action) { const rack = yield call(addRackToTile, action.tileId, { id: -1, name: "Rack", - capacity: 42, - powerCapacityW: 100 + capacity: DEFAULT_RACK_SLOT_CAPACITY, + powerCapacityW: DEFAULT_RACK_POWER_CAPACITY }); rack.machineIds = new Array(rack.capacity).fill(null); yield put(addToStore("rack", rack)); @@ -286,6 +291,11 @@ export function* onAddUnit(action) { const position = yield select(state => state.interactionLevel.position); const machine = yield select(state => state.objects.machine[state.objects.rack[ state.objects.tile[tileId].objectId].machineIds[position - 1]]); + + if (machine[action.unitType + "Ids"].length >= MAX_NUM_UNITS_PER_MACHINE) { + return; + } + const updatedMachine = Object.assign({}, machine, {[action.unitType + "Ids"]: [...machine[action.unitType + "Ids"], action.id]}); -- cgit v1.2.3