From f119fc78dda4d1e828dde04f378a63a93e3a0a7e Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Thu, 2 Jul 2020 18:39:28 +0200 Subject: Add current progress on frontend port --- frontend/src/reducers/current-ids.js | 10 +++---- frontend/src/reducers/index.js | 4 +-- frontend/src/reducers/interaction-level.js | 4 +-- frontend/src/reducers/modals.js | 45 ++++++++--------------------- frontend/src/reducers/objects.js | 46 +++++++++--------------------- frontend/src/reducers/simulation-list.js | 2 +- frontend/src/reducers/states.js | 3 +- 7 files changed, 37 insertions(+), 77 deletions(-) (limited to 'frontend/src/reducers') diff --git a/frontend/src/reducers/current-ids.js b/frontend/src/reducers/current-ids.js index 6a605d9f..76ae67c7 100644 --- a/frontend/src/reducers/current-ids.js +++ b/frontend/src/reducers/current-ids.js @@ -1,12 +1,12 @@ import { OPEN_EXPERIMENT_SUCCEEDED } from '../actions/experiments' import { OPEN_SIMULATION_SUCCEEDED } from '../actions/simulations' -import { RESET_CURRENT_DATACENTER, SET_CURRENT_DATACENTER } from '../actions/topology/building' +import { RESET_CURRENT_TOPOLOGY, SET_CURRENT_TOPOLOGY } from '../actions/topology/building' -export function currentDatacenterId(state = -1, action) { +export function currentTopologyId(state = -1, action) { switch (action.type) { - case SET_CURRENT_DATACENTER: - return action.datacenterId - case RESET_CURRENT_DATACENTER: + case SET_CURRENT_TOPOLOGY: + return action.topologyId + case RESET_CURRENT_TOPOLOGY: return -1 default: return state diff --git a/frontend/src/reducers/index.js b/frontend/src/reducers/index.js index a5b14f4a..1c3ee145 100644 --- a/frontend/src/reducers/index.js +++ b/frontend/src/reducers/index.js @@ -1,7 +1,7 @@ import { combineReducers } from 'redux' import { auth } from './auth' import { construction } from './construction-mode' -import { currentDatacenterId, currentSimulationId } from './current-ids' +import { currentTopologyId, currentSimulationId } from './current-ids' import { interactionLevel } from './interaction-level' import { map } from './map' import { modals } from './modals' @@ -18,7 +18,7 @@ const rootReducer = combineReducers({ construction, map, currentSimulationId, - currentDatacenterId, + currentTopologyId, currentExperimentId, currentTick, lastSimulatedTick, diff --git a/frontend/src/reducers/interaction-level.js b/frontend/src/reducers/interaction-level.js index 12d5d70e..88c3b30e 100644 --- a/frontend/src/reducers/interaction-level.js +++ b/frontend/src/reducers/interaction-level.js @@ -6,13 +6,13 @@ import { GO_FROM_ROOM_TO_RACK, } from '../actions/interaction-level' import { OPEN_SIMULATION_SUCCEEDED } from '../actions/simulations' -import { SET_CURRENT_DATACENTER } from '../actions/topology/building' +import { SET_CURRENT_TOPOLOGY } from '../actions/topology/building' export function interactionLevel(state = { mode: 'BUILDING' }, action) { switch (action.type) { case OPEN_EXPERIMENT_SUCCEEDED: case OPEN_SIMULATION_SUCCEEDED: - case SET_CURRENT_DATACENTER: + case SET_CURRENT_TOPOLOGY: return { mode: 'BUILDING', } diff --git a/frontend/src/reducers/modals.js b/frontend/src/reducers/modals.js index 04e9ab49..81a0660e 100644 --- a/frontend/src/reducers/modals.js +++ b/frontend/src/reducers/modals.js @@ -4,11 +4,13 @@ import { CLOSE_NEW_EXPERIMENT_MODAL, OPEN_NEW_EXPERIMENT_MODAL } from '../action import { CLOSE_DELETE_PROFILE_MODAL, OPEN_DELETE_PROFILE_MODAL } from '../actions/modals/profile' import { CLOSE_NEW_SIMULATION_MODAL, OPEN_NEW_SIMULATION_MODAL } from '../actions/modals/simulations' import { + CLOSE_CHANGE_TOPOLOGY_MODAL, CLOSE_DELETE_MACHINE_MODAL, CLOSE_DELETE_RACK_MODAL, CLOSE_DELETE_ROOM_MODAL, CLOSE_EDIT_RACK_NAME_MODAL, CLOSE_EDIT_ROOM_NAME_MODAL, + OPEN_CHANGE_TOPOLOGY_MODAL, OPEN_DELETE_MACHINE_MODAL, OPEN_DELETE_RACK_MODAL, OPEN_DELETE_ROOM_MODAL, @@ -17,7 +19,7 @@ import { } from '../actions/modals/topology' function modal(openAction, closeAction) { - return function(state = false, action) { + return function (state = false, action) { switch (action.type) { case openAction: return true @@ -31,36 +33,13 @@ function modal(openAction, closeAction) { } export const modals = combineReducers({ - newSimulationModalVisible: modal( - OPEN_NEW_SIMULATION_MODAL, - CLOSE_NEW_SIMULATION_MODAL, - ), - deleteProfileModalVisible: modal( - OPEN_DELETE_PROFILE_MODAL, - CLOSE_DELETE_PROFILE_MODAL, - ), - editRoomNameModalVisible: modal( - OPEN_EDIT_ROOM_NAME_MODAL, - CLOSE_EDIT_ROOM_NAME_MODAL, - ), - deleteRoomModalVisible: modal( - OPEN_DELETE_ROOM_MODAL, - CLOSE_DELETE_ROOM_MODAL, - ), - editRackNameModalVisible: modal( - OPEN_EDIT_RACK_NAME_MODAL, - CLOSE_EDIT_RACK_NAME_MODAL, - ), - deleteRackModalVisible: modal( - OPEN_DELETE_RACK_MODAL, - CLOSE_DELETE_RACK_MODAL, - ), - deleteMachineModalVisible: modal( - OPEN_DELETE_MACHINE_MODAL, - CLOSE_DELETE_MACHINE_MODAL, - ), - newExperimentModalVisible: modal( - OPEN_NEW_EXPERIMENT_MODAL, - CLOSE_NEW_EXPERIMENT_MODAL, - ), + newSimulationModalVisible: modal(OPEN_NEW_SIMULATION_MODAL, CLOSE_NEW_SIMULATION_MODAL), + deleteProfileModalVisible: modal(OPEN_DELETE_PROFILE_MODAL, CLOSE_DELETE_PROFILE_MODAL), + changeTopologyModalVisible: modal(OPEN_CHANGE_TOPOLOGY_MODAL, CLOSE_CHANGE_TOPOLOGY_MODAL), + editRoomNameModalVisible: modal(OPEN_EDIT_ROOM_NAME_MODAL, CLOSE_EDIT_ROOM_NAME_MODAL), + deleteRoomModalVisible: modal(OPEN_DELETE_ROOM_MODAL, CLOSE_DELETE_ROOM_MODAL), + editRackNameModalVisible: modal(OPEN_EDIT_RACK_NAME_MODAL, CLOSE_EDIT_RACK_NAME_MODAL), + deleteRackModalVisible: modal(OPEN_DELETE_RACK_MODAL, CLOSE_DELETE_RACK_MODAL), + deleteMachineModalVisible: modal(OPEN_DELETE_MACHINE_MODAL, CLOSE_DELETE_MACHINE_MODAL), + newExperimentModalVisible: modal(OPEN_NEW_EXPERIMENT_MODAL, CLOSE_NEW_EXPERIMENT_MODAL), }) diff --git a/frontend/src/reducers/objects.js b/frontend/src/reducers/objects.js index 1dc1e7e8..f52ca369 100644 --- a/frontend/src/reducers/objects.js +++ b/frontend/src/reducers/objects.js @@ -5,41 +5,32 @@ import { ADD_TO_STORE, REMOVE_ID_FROM_STORE_OBJECT_LIST_PROP, } from '../actions/objects' +import { CPU_UNITS, GPU_UNITS, MEMORY_UNITS, STORAGE_UNITS } from '../util/unit-specifications' export const objects = combineReducers({ simulation: object('simulation'), user: object('user'), - authorization: objectWithId('authorization', object => [ - object.userId, - object.simulationId, - ]), - failureModel: object('failureModel'), - cpu: object('cpu'), - gpu: object('gpu'), - memory: object('memory'), - storage: object('storage'), + authorization: objectWithId('authorization', (object) => [object.userId, object.simulationId]), + cpu: object('cpu', CPU_UNITS), + gpu: object('gpu', GPU_UNITS), + memory: object('memory', MEMORY_UNITS), + storage: object('storage', STORAGE_UNITS), machine: object('machine'), rack: object('rack'), - coolingItem: object('coolingItem'), - psu: object('psu'), tile: object('tile'), room: object('room'), - datacenter: object('datacenter'), - section: object('section'), - path: object('path'), - task: object('task'), - job: object('job'), + topology: object('topology'), trace: object('trace'), scheduler: object('scheduler'), experiment: object('experiment'), }) -function object(type) { - return objectWithId(type, object => object._id) +function object(type, defaultState = {}) { + return objectWithId(type, (object) => object._id, defaultState) } -function objectWithId(type, getId) { - return (state = {}, action) => { +function objectWithId(type, getId, defaultState = {}) { + return (state = defaultState, action) => { if (action.objectType !== type) { return state } @@ -50,27 +41,18 @@ function objectWithId(type, getId) { }) } else if (action.type === ADD_PROP_TO_STORE_OBJECT) { return Object.assign({}, state, { - [action.objectId]: Object.assign( - {}, - state[action.objectId], - action.propObject, - ), + [action.objectId]: Object.assign({}, state[action.objectId], action.propObject), }) } else if (action.type === ADD_ID_TO_STORE_OBJECT_LIST_PROP) { return Object.assign({}, state, { [action.objectId]: Object.assign({}, state[action.objectId], { - [action.propName]: [ - ...state[action.objectId][action.propName], - action.id, - ], + [action.propName]: [...state[action.objectId][action.propName], action.id], }), }) } else if (action.type === REMOVE_ID_FROM_STORE_OBJECT_LIST_PROP) { return Object.assign({}, state, { [action.objectId]: Object.assign({}, state[action.objectId], { - [action.propName]: state[action.objectId][action.propName].filter( - id => id !== action.id, - ), + [action.propName]: state[action.objectId][action.propName].filter((id) => id !== action.id), }), }) } diff --git a/frontend/src/reducers/simulation-list.js b/frontend/src/reducers/simulation-list.js index 78f3c4fe..383f4b35 100644 --- a/frontend/src/reducers/simulation-list.js +++ b/frontend/src/reducers/simulation-list.js @@ -13,7 +13,7 @@ export function authorizationsOfCurrentUser(state = [], action) { case ADD_SIMULATION_SUCCEEDED: return [...state, action.authorization] case DELETE_SIMULATION_SUCCEEDED: - return state.filter(authorization => authorization[1] !== action.id) + return state.filter((authorization) => authorization[1] !== action.id) default: return state } diff --git a/frontend/src/reducers/states.js b/frontend/src/reducers/states.js index e4c2fd19..c9bb4158 100644 --- a/frontend/src/reducers/states.js +++ b/frontend/src/reducers/states.js @@ -2,7 +2,6 @@ import { combineReducers } from 'redux' import { ADD_BATCH_TO_STATES } from '../actions/states' export const states = combineReducers({ - task: objectStates('task'), room: objectStates('room'), rack: objectStates('rack'), machine: objectStates('machine'), @@ -21,7 +20,7 @@ function objectStates(type) { {}, state[action.objects[i].tick], batch[action.objects[i].tick], - { [action.objects[i][action.objectType + 'Id']]: action.objects[i] }, + { [action.objects[i][action.objectType + 'Id']]: action.objects[i] } ) } -- cgit v1.2.3