diff options
| author | Georgios Andreadis <info@gandreadis.com> | 2020-07-01 13:33:31 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-08-24 19:47:17 +0200 |
| commit | de8f12d74faef5fa3f9e38d1340948cab2d06ea3 (patch) | |
| tree | 678bf1af3e5fa2334f0df43388d45294785bbf1e /frontend/src/reducers | |
| parent | 44236756c4cf689806dc17c6950a2cff3e9227bf (diff) | |
Manually generate IDs
Diffstat (limited to 'frontend/src/reducers')
| -rw-r--r-- | frontend/src/reducers/auth.js | 18 | ||||
| -rw-r--r-- | frontend/src/reducers/construction-mode.js | 78 | ||||
| -rw-r--r-- | frontend/src/reducers/current-ids.js | 41 | ||||
| -rw-r--r-- | frontend/src/reducers/index.js | 62 | ||||
| -rw-r--r-- | frontend/src/reducers/interaction-level.js | 112 | ||||
| -rw-r--r-- | frontend/src/reducers/map.js | 52 | ||||
| -rw-r--r-- | frontend/src/reducers/modals.js | 127 | ||||
| -rw-r--r-- | frontend/src/reducers/objects.js | 138 | ||||
| -rw-r--r-- | frontend/src/reducers/simulation-list.js | 52 | ||||
| -rw-r--r-- | frontend/src/reducers/simulation-mode.js | 91 | ||||
| -rw-r--r-- | frontend/src/reducers/states.js | 50 |
11 files changed, 396 insertions, 425 deletions
diff --git a/frontend/src/reducers/auth.js b/frontend/src/reducers/auth.js index 635929d4..399a4b10 100644 --- a/frontend/src/reducers/auth.js +++ b/frontend/src/reducers/auth.js @@ -1,12 +1,12 @@ -import { LOG_IN_SUCCEEDED, LOG_OUT } from "../actions/auth"; +import { LOG_IN_SUCCEEDED, LOG_OUT } from '../actions/auth' export function auth(state = {}, action) { - switch (action.type) { - case LOG_IN_SUCCEEDED: - return action.payload; - case LOG_OUT: - return {}; - default: - return state; - } + switch (action.type) { + case LOG_IN_SUCCEEDED: + return action.payload + case LOG_OUT: + return {} + default: + return state + } } diff --git a/frontend/src/reducers/construction-mode.js b/frontend/src/reducers/construction-mode.js index b5e6e781..3b500b59 100644 --- a/frontend/src/reducers/construction-mode.js +++ b/frontend/src/reducers/construction-mode.js @@ -1,50 +1,46 @@ -import { combineReducers } from "redux"; -import { OPEN_EXPERIMENT_SUCCEEDED } from "../actions/experiments"; -import { GO_DOWN_ONE_INTERACTION_LEVEL } from "../actions/interaction-level"; +import { combineReducers } from 'redux' +import { OPEN_EXPERIMENT_SUCCEEDED } from '../actions/experiments' +import { GO_DOWN_ONE_INTERACTION_LEVEL } from '../actions/interaction-level' import { - CANCEL_NEW_ROOM_CONSTRUCTION_SUCCEEDED, - FINISH_NEW_ROOM_CONSTRUCTION, - FINISH_ROOM_EDIT, - START_NEW_ROOM_CONSTRUCTION_SUCCEEDED, - START_ROOM_EDIT -} from "../actions/topology/building"; -import { - DELETE_ROOM, - START_RACK_CONSTRUCTION, - STOP_RACK_CONSTRUCTION -} from "../actions/topology/room"; + CANCEL_NEW_ROOM_CONSTRUCTION_SUCCEEDED, + FINISH_NEW_ROOM_CONSTRUCTION, + FINISH_ROOM_EDIT, + START_NEW_ROOM_CONSTRUCTION_SUCCEEDED, + START_ROOM_EDIT, +} from '../actions/topology/building' +import { DELETE_ROOM, START_RACK_CONSTRUCTION, STOP_RACK_CONSTRUCTION } from '../actions/topology/room' export function currentRoomInConstruction(state = -1, action) { - switch (action.type) { - case START_NEW_ROOM_CONSTRUCTION_SUCCEEDED: - return action.roomId; - case START_ROOM_EDIT: - return action.roomId; - case CANCEL_NEW_ROOM_CONSTRUCTION_SUCCEEDED: - case FINISH_NEW_ROOM_CONSTRUCTION: - case OPEN_EXPERIMENT_SUCCEEDED: - case FINISH_ROOM_EDIT: - case DELETE_ROOM: - return -1; - default: - return state; - } + switch (action.type) { + case START_NEW_ROOM_CONSTRUCTION_SUCCEEDED: + return action.roomId + case START_ROOM_EDIT: + return action.roomId + case CANCEL_NEW_ROOM_CONSTRUCTION_SUCCEEDED: + case FINISH_NEW_ROOM_CONSTRUCTION: + case OPEN_EXPERIMENT_SUCCEEDED: + case FINISH_ROOM_EDIT: + case DELETE_ROOM: + return -1 + default: + return state + } } export function inRackConstructionMode(state = false, action) { - switch (action.type) { - case START_RACK_CONSTRUCTION: - return true; - case STOP_RACK_CONSTRUCTION: - case OPEN_EXPERIMENT_SUCCEEDED: - case GO_DOWN_ONE_INTERACTION_LEVEL: - return false; - default: - return state; - } + switch (action.type) { + case START_RACK_CONSTRUCTION: + return true + case STOP_RACK_CONSTRUCTION: + case OPEN_EXPERIMENT_SUCCEEDED: + case GO_DOWN_ONE_INTERACTION_LEVEL: + return false + default: + return state + } } export const construction = combineReducers({ - currentRoomInConstruction, - inRackConstructionMode -}); + currentRoomInConstruction, + inRackConstructionMode, +}) diff --git a/frontend/src/reducers/current-ids.js b/frontend/src/reducers/current-ids.js index 4e16630d..6a605d9f 100644 --- a/frontend/src/reducers/current-ids.js +++ b/frontend/src/reducers/current-ids.js @@ -1,28 +1,25 @@ -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 { OPEN_EXPERIMENT_SUCCEEDED } from '../actions/experiments' +import { OPEN_SIMULATION_SUCCEEDED } from '../actions/simulations' +import { RESET_CURRENT_DATACENTER, SET_CURRENT_DATACENTER } from '../actions/topology/building' export function currentDatacenterId(state = -1, action) { - switch (action.type) { - case SET_CURRENT_DATACENTER: - return action.datacenterId; - case RESET_CURRENT_DATACENTER: - return -1; - default: - return state; - } + switch (action.type) { + case SET_CURRENT_DATACENTER: + return action.datacenterId + case RESET_CURRENT_DATACENTER: + return -1 + default: + return state + } } export function currentSimulationId(state = -1, action) { - switch (action.type) { - case OPEN_SIMULATION_SUCCEEDED: - return action.id; - case OPEN_EXPERIMENT_SUCCEEDED: - return action.simulationId; - default: - return state; - } + switch (action.type) { + case OPEN_SIMULATION_SUCCEEDED: + return action.id + case OPEN_EXPERIMENT_SUCCEEDED: + return action.simulationId + default: + return state + } } diff --git a/frontend/src/reducers/index.js b/frontend/src/reducers/index.js index 6f4d0c94..a5b14f4a 100644 --- a/frontend/src/reducers/index.js +++ b/frontend/src/reducers/index.js @@ -1,37 +1,31 @@ -import { combineReducers } from "redux"; -import { auth } from "./auth"; -import { construction } from "./construction-mode"; -import { currentDatacenterId, currentSimulationId } from "./current-ids"; -import { interactionLevel } from "./interaction-level"; -import { map } from "./map"; -import { modals } from "./modals"; -import { objects } from "./objects"; -import { simulationList } from "./simulation-list"; -import { - currentExperimentId, - currentTick, - isPlaying, - lastSimulatedTick, - loadMetric -} from "./simulation-mode"; -import { states } from "./states"; +import { combineReducers } from 'redux' +import { auth } from './auth' +import { construction } from './construction-mode' +import { currentDatacenterId, currentSimulationId } from './current-ids' +import { interactionLevel } from './interaction-level' +import { map } from './map' +import { modals } from './modals' +import { objects } from './objects' +import { simulationList } from './simulation-list' +import { currentExperimentId, currentTick, isPlaying, lastSimulatedTick, loadMetric } from './simulation-mode' +import { states } from './states' const rootReducer = combineReducers({ - objects, - states, - modals, - simulationList, - construction, - map, - currentSimulationId, - currentDatacenterId, - currentExperimentId, - currentTick, - lastSimulatedTick, - loadMetric, - isPlaying, - interactionLevel, - auth -}); + objects, + states, + modals, + simulationList, + construction, + map, + currentSimulationId, + currentDatacenterId, + currentExperimentId, + currentTick, + lastSimulatedTick, + loadMetric, + isPlaying, + interactionLevel, + auth, +}) -export default rootReducer; +export default rootReducer diff --git a/frontend/src/reducers/interaction-level.js b/frontend/src/reducers/interaction-level.js index 581906c5..12d5d70e 100644 --- a/frontend/src/reducers/interaction-level.js +++ b/frontend/src/reducers/interaction-level.js @@ -1,59 +1,59 @@ -import { OPEN_EXPERIMENT_SUCCEEDED } from "../actions/experiments"; +import { OPEN_EXPERIMENT_SUCCEEDED } from '../actions/experiments' import { - GO_DOWN_ONE_INTERACTION_LEVEL, - GO_FROM_BUILDING_TO_ROOM, - GO_FROM_RACK_TO_MACHINE, - GO_FROM_ROOM_TO_RACK -} from "../actions/interaction-level"; -import { OPEN_SIMULATION_SUCCEEDED } from "../actions/simulations"; -import { SET_CURRENT_DATACENTER } from "../actions/topology/building"; + GO_DOWN_ONE_INTERACTION_LEVEL, + GO_FROM_BUILDING_TO_ROOM, + GO_FROM_RACK_TO_MACHINE, + GO_FROM_ROOM_TO_RACK, +} from '../actions/interaction-level' +import { OPEN_SIMULATION_SUCCEEDED } from '../actions/simulations' +import { SET_CURRENT_DATACENTER } 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: - return { - mode: "BUILDING" - }; - case GO_FROM_BUILDING_TO_ROOM: - return { - mode: "ROOM", - roomId: action.roomId - }; - case GO_FROM_ROOM_TO_RACK: - return { - mode: "RACK", - roomId: state.roomId, - tileId: action.tileId - }; - case GO_FROM_RACK_TO_MACHINE: - return { - mode: "MACHINE", - roomId: state.roomId, - tileId: state.tileId, - position: action.position - }; - case GO_DOWN_ONE_INTERACTION_LEVEL: - if (state.mode === "ROOM") { - return { - mode: "BUILDING" - }; - } else if (state.mode === "RACK") { - return { - mode: "ROOM", - roomId: state.roomId - }; - } else if (state.mode === "MACHINE") { - return { - mode: "RACK", - roomId: state.roomId, - tileId: state.tileId - }; - } else { - return state; - } - default: - return state; - } +export function interactionLevel(state = { mode: 'BUILDING' }, action) { + switch (action.type) { + case OPEN_EXPERIMENT_SUCCEEDED: + case OPEN_SIMULATION_SUCCEEDED: + case SET_CURRENT_DATACENTER: + return { + mode: 'BUILDING', + } + case GO_FROM_BUILDING_TO_ROOM: + return { + mode: 'ROOM', + roomId: action.roomId, + } + case GO_FROM_ROOM_TO_RACK: + return { + mode: 'RACK', + roomId: state.roomId, + tileId: action.tileId, + } + case GO_FROM_RACK_TO_MACHINE: + return { + mode: 'MACHINE', + roomId: state.roomId, + tileId: state.tileId, + position: action.position, + } + case GO_DOWN_ONE_INTERACTION_LEVEL: + if (state.mode === 'ROOM') { + return { + mode: 'BUILDING', + } + } else if (state.mode === 'RACK') { + return { + mode: 'ROOM', + roomId: state.roomId, + } + } else if (state.mode === 'MACHINE') { + return { + mode: 'RACK', + roomId: state.roomId, + tileId: state.tileId, + } + } else { + return state + } + default: + return state + } } diff --git a/frontend/src/reducers/map.js b/frontend/src/reducers/map.js index b75dc051..de712c15 100644 --- a/frontend/src/reducers/map.js +++ b/frontend/src/reducers/map.js @@ -1,39 +1,35 @@ -import { combineReducers } from "redux"; -import { - SET_MAP_DIMENSIONS, - SET_MAP_POSITION, - SET_MAP_SCALE -} from "../actions/map"; +import { combineReducers } from 'redux' +import { SET_MAP_DIMENSIONS, SET_MAP_POSITION, SET_MAP_SCALE } from '../actions/map' export function position(state = { x: 0, y: 0 }, action) { - switch (action.type) { - case SET_MAP_POSITION: - return { x: action.x, y: action.y }; - default: - return state; - } + switch (action.type) { + case SET_MAP_POSITION: + return { x: action.x, y: action.y } + default: + return state + } } export function dimensions(state = { width: 600, height: 400 }, action) { - switch (action.type) { - case SET_MAP_DIMENSIONS: - return { width: action.width, height: action.height }; - default: - return state; - } + switch (action.type) { + case SET_MAP_DIMENSIONS: + return { width: action.width, height: action.height } + default: + return state + } } export function scale(state = 1, action) { - switch (action.type) { - case SET_MAP_SCALE: - return action.scale; - default: - return state; - } + switch (action.type) { + case SET_MAP_SCALE: + return action.scale + default: + return state + } } export const map = combineReducers({ - position, - dimensions, - scale -}); + position, + dimensions, + scale, +}) diff --git a/frontend/src/reducers/modals.js b/frontend/src/reducers/modals.js index 78527feb..04e9ab49 100644 --- a/frontend/src/reducers/modals.js +++ b/frontend/src/reducers/modals.js @@ -1,75 +1,66 @@ -import { combineReducers } from "redux"; -import { OPEN_EXPERIMENT_SUCCEEDED } from "../actions/experiments"; +import { combineReducers } from 'redux' +import { OPEN_EXPERIMENT_SUCCEEDED } from '../actions/experiments' +import { CLOSE_NEW_EXPERIMENT_MODAL, OPEN_NEW_EXPERIMENT_MODAL } from '../actions/modals/experiments' +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_NEW_EXPERIMENT_MODAL, - OPEN_NEW_EXPERIMENT_MODAL -} from "../actions/modals/experiments"; -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_DELETE_MACHINE_MODAL, - CLOSE_DELETE_RACK_MODAL, - CLOSE_DELETE_ROOM_MODAL, - CLOSE_EDIT_RACK_NAME_MODAL, - CLOSE_EDIT_ROOM_NAME_MODAL, - OPEN_DELETE_MACHINE_MODAL, - OPEN_DELETE_RACK_MODAL, - OPEN_DELETE_ROOM_MODAL, - OPEN_EDIT_RACK_NAME_MODAL, - OPEN_EDIT_ROOM_NAME_MODAL -} from "../actions/modals/topology"; + CLOSE_DELETE_MACHINE_MODAL, + CLOSE_DELETE_RACK_MODAL, + CLOSE_DELETE_ROOM_MODAL, + CLOSE_EDIT_RACK_NAME_MODAL, + CLOSE_EDIT_ROOM_NAME_MODAL, + OPEN_DELETE_MACHINE_MODAL, + OPEN_DELETE_RACK_MODAL, + OPEN_DELETE_ROOM_MODAL, + OPEN_EDIT_RACK_NAME_MODAL, + OPEN_EDIT_ROOM_NAME_MODAL, +} from '../actions/modals/topology' function modal(openAction, closeAction) { - return function(state = false, action) { - switch (action.type) { - case openAction: - return true; - case closeAction: - case OPEN_EXPERIMENT_SUCCEEDED: - return false; - default: - return state; + return function(state = false, action) { + switch (action.type) { + case openAction: + return true + case closeAction: + case OPEN_EXPERIMENT_SUCCEEDED: + return false + default: + return state + } } - }; } 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, + ), + 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 99d91092..2e9644d0 100644 --- a/frontend/src/reducers/objects.js +++ b/frontend/src/reducers/objects.js @@ -1,80 +1,80 @@ -import { combineReducers } from "redux"; +import { combineReducers } from 'redux' import { - ADD_ID_TO_STORE_OBJECT_LIST_PROP, - ADD_PROP_TO_STORE_OBJECT, - ADD_TO_STORE, - REMOVE_ID_FROM_STORE_OBJECT_LIST_PROP -} from "../actions/objects"; + ADD_ID_TO_STORE_OBJECT_LIST_PROP, + ADD_PROP_TO_STORE_OBJECT, + ADD_TO_STORE, + REMOVE_ID_FROM_STORE_OBJECT_LIST_PROP, +} from '../actions/objects' 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"), - 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"), - trace: object("trace"), - scheduler: object("scheduler"), - experiment: object("experiment") -}); + 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'), + 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'), + trace: object('trace'), + scheduler: object('scheduler'), + experiment: object('experiment'), +}) function object(type) { - return objectWithId(type, object => object.id); + return objectWithId(type, object => object.id) } function objectWithId(type, getId) { - return (state = {}, action) => { - if (action.objectType !== type) { - return state; - } + return (state = {}, action) => { + if (action.objectType !== type) { + return state + } - if (action.type === ADD_TO_STORE) { - return Object.assign({}, state, { - [getId(action.object)]: action.object - }); - } else if (action.type === ADD_PROP_TO_STORE_OBJECT) { - return Object.assign({}, state, { - [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 - ] - }) - }); - } 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 - ) - }) - }); - } + if (action.type === ADD_TO_STORE) { + return Object.assign({}, state, { + [getId(action.object)]: action.object, + }) + } else if (action.type === ADD_PROP_TO_STORE_OBJECT) { + return Object.assign({}, state, { + [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, + ], + }), + }) + } 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, + ), + }), + }) + } - return state; - }; + return state + } } diff --git a/frontend/src/reducers/simulation-list.js b/frontend/src/reducers/simulation-list.js index 9afa3586..78f3c4fe 100644 --- a/frontend/src/reducers/simulation-list.js +++ b/frontend/src/reducers/simulation-list.js @@ -1,34 +1,34 @@ -import { combineReducers } from "redux"; +import { combineReducers } from 'redux' import { - ADD_SIMULATION_SUCCEEDED, - DELETE_SIMULATION_SUCCEEDED, - SET_AUTH_VISIBILITY_FILTER -} from "../actions/simulations"; -import { FETCH_AUTHORIZATIONS_OF_CURRENT_USER_SUCCEEDED } from "../actions/users"; + ADD_SIMULATION_SUCCEEDED, + DELETE_SIMULATION_SUCCEEDED, + SET_AUTH_VISIBILITY_FILTER, +} from '../actions/simulations' +import { FETCH_AUTHORIZATIONS_OF_CURRENT_USER_SUCCEEDED } from '../actions/users' export function authorizationsOfCurrentUser(state = [], action) { - switch (action.type) { - case FETCH_AUTHORIZATIONS_OF_CURRENT_USER_SUCCEEDED: - return action.authorizationsOfCurrentUser; - case ADD_SIMULATION_SUCCEEDED: - return [...state, action.authorization]; - case DELETE_SIMULATION_SUCCEEDED: - return state.filter(authorization => authorization[1] !== action.id); - default: - return state; - } + switch (action.type) { + case FETCH_AUTHORIZATIONS_OF_CURRENT_USER_SUCCEEDED: + return action.authorizationsOfCurrentUser + case ADD_SIMULATION_SUCCEEDED: + return [...state, action.authorization] + case DELETE_SIMULATION_SUCCEEDED: + return state.filter(authorization => authorization[1] !== action.id) + default: + return state + } } -export function authVisibilityFilter(state = "SHOW_ALL", action) { - switch (action.type) { - case SET_AUTH_VISIBILITY_FILTER: - return action.filter; - default: - return state; - } +export function authVisibilityFilter(state = 'SHOW_ALL', action) { + switch (action.type) { + case SET_AUTH_VISIBILITY_FILTER: + return action.filter + default: + return state + } } export const simulationList = combineReducers({ - authorizationsOfCurrentUser, - authVisibilityFilter -}); + authorizationsOfCurrentUser, + authVisibilityFilter, +}) diff --git a/frontend/src/reducers/simulation-mode.js b/frontend/src/reducers/simulation-mode.js index 02041468..ea15ffa9 100644 --- a/frontend/src/reducers/simulation-mode.js +++ b/frontend/src/reducers/simulation-mode.js @@ -1,61 +1,58 @@ -import { OPEN_EXPERIMENT_SUCCEEDED } from "../actions/experiments"; -import { CHANGE_LOAD_METRIC } from "../actions/simulation/load-metric"; -import { SET_PLAYING } from "../actions/simulation/playback"; -import { - GO_TO_TICK, - SET_LAST_SIMULATED_TICK -} from "../actions/simulation/tick"; -import { OPEN_SIMULATION_SUCCEEDED } from "../actions/simulations"; +import { OPEN_EXPERIMENT_SUCCEEDED } from '../actions/experiments' +import { CHANGE_LOAD_METRIC } from '../actions/simulation/load-metric' +import { SET_PLAYING } from '../actions/simulation/playback' +import { GO_TO_TICK, SET_LAST_SIMULATED_TICK } from '../actions/simulation/tick' +import { OPEN_SIMULATION_SUCCEEDED } from '../actions/simulations' export function currentExperimentId(state = -1, action) { - switch (action.type) { - case OPEN_EXPERIMENT_SUCCEEDED: - return action.experimentId; - case OPEN_SIMULATION_SUCCEEDED: - return -1; - default: - return state; - } + switch (action.type) { + case OPEN_EXPERIMENT_SUCCEEDED: + return action.experimentId + case OPEN_SIMULATION_SUCCEEDED: + return -1 + default: + return state + } } export function currentTick(state = 0, action) { - switch (action.type) { - case GO_TO_TICK: - return action.tick; - case OPEN_EXPERIMENT_SUCCEEDED: - return 0; - default: - return state; - } + switch (action.type) { + case GO_TO_TICK: + return action.tick + case OPEN_EXPERIMENT_SUCCEEDED: + return 0 + default: + return state + } } -export function loadMetric(state = "LOAD", action) { - switch (action.type) { - case CHANGE_LOAD_METRIC: - return action.metric; - default: - return state; - } +export function loadMetric(state = 'LOAD', action) { + switch (action.type) { + case CHANGE_LOAD_METRIC: + return action.metric + default: + return state + } } export function isPlaying(state = false, action) { - switch (action.type) { - case SET_PLAYING: - return action.playing; - case OPEN_EXPERIMENT_SUCCEEDED: - return false; - default: - return state; - } + switch (action.type) { + case SET_PLAYING: + return action.playing + case OPEN_EXPERIMENT_SUCCEEDED: + return false + default: + return state + } } export function lastSimulatedTick(state = -1, action) { - switch (action.type) { - case SET_LAST_SIMULATED_TICK: - return action.tick; - case OPEN_EXPERIMENT_SUCCEEDED: - return -1; - default: - return state; - } + switch (action.type) { + case SET_LAST_SIMULATED_TICK: + return action.tick + case OPEN_EXPERIMENT_SUCCEEDED: + return -1 + default: + return state + } } diff --git a/frontend/src/reducers/states.js b/frontend/src/reducers/states.js index 793f7b7d..e4c2fd19 100644 --- a/frontend/src/reducers/states.js +++ b/frontend/src/reducers/states.js @@ -1,33 +1,33 @@ -import { combineReducers } from "redux"; -import { ADD_BATCH_TO_STATES } from "../actions/states"; +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") -}); + task: objectStates('task'), + room: objectStates('room'), + rack: objectStates('rack'), + machine: objectStates('machine'), +}) function objectStates(type) { - return (state = {}, action) => { - if (action.objectType !== type) { - return state; - } + return (state = {}, action) => { + if (action.objectType !== type) { + return state + } - if (action.type === ADD_BATCH_TO_STATES) { - const batch = {}; - for (let i in action.objects) { - batch[action.objects[i].tick] = Object.assign( - {}, - state[action.objects[i].tick], - batch[action.objects[i].tick], - { [action.objects[i][action.objectType + "Id"]]: action.objects[i] } - ); - } + if (action.type === ADD_BATCH_TO_STATES) { + const batch = {} + for (let i in action.objects) { + batch[action.objects[i].tick] = Object.assign( + {}, + state[action.objects[i].tick], + batch[action.objects[i].tick], + { [action.objects[i][action.objectType + 'Id']]: action.objects[i] }, + ) + } - return Object.assign({}, state, batch); - } + return Object.assign({}, state, batch) + } - return state; - }; + return state + } } |
