From b4bdf9fde013bb7ff9579693b64ff575f7b00e44 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Tue, 7 Jul 2020 09:55:10 +0200 Subject: Rename simulations to projects and remove experiment view --- frontend/src/reducers/construction-mode.js | 3 +- frontend/src/reducers/current-ids.js | 8 ++--- frontend/src/reducers/index.js | 16 +++------ frontend/src/reducers/interaction-level.js | 4 +-- frontend/src/reducers/modals.js | 6 ++-- frontend/src/reducers/objects.js | 4 +-- frontend/src/reducers/project-list.js | 30 ++++++++++++++++ frontend/src/reducers/simulation-list.js | 34 ------------------ frontend/src/reducers/simulation-mode.js | 58 ------------------------------ frontend/src/reducers/states.js | 32 ----------------- 10 files changed, 47 insertions(+), 148 deletions(-) create mode 100644 frontend/src/reducers/project-list.js delete mode 100644 frontend/src/reducers/simulation-list.js delete mode 100644 frontend/src/reducers/simulation-mode.js delete mode 100644 frontend/src/reducers/states.js (limited to 'frontend/src/reducers') diff --git a/frontend/src/reducers/construction-mode.js b/frontend/src/reducers/construction-mode.js index fb33da72..b15ac834 100644 --- a/frontend/src/reducers/construction-mode.js +++ b/frontend/src/reducers/construction-mode.js @@ -4,7 +4,8 @@ import { GO_DOWN_ONE_INTERACTION_LEVEL } from '../actions/interaction-level' import { CANCEL_NEW_ROOM_CONSTRUCTION_SUCCEEDED, FINISH_NEW_ROOM_CONSTRUCTION, - FINISH_ROOM_EDIT, SET_CURRENT_TOPOLOGY, + FINISH_ROOM_EDIT, + SET_CURRENT_TOPOLOGY, START_NEW_ROOM_CONSTRUCTION_SUCCEEDED, START_ROOM_EDIT, } from '../actions/topology/building' diff --git a/frontend/src/reducers/current-ids.js b/frontend/src/reducers/current-ids.js index b80d2ecf..0726da6d 100644 --- a/frontend/src/reducers/current-ids.js +++ b/frontend/src/reducers/current-ids.js @@ -1,5 +1,5 @@ import { OPEN_EXPERIMENT_SUCCEEDED } from '../actions/experiments' -import { OPEN_SIMULATION_SUCCEEDED } from '../actions/simulations' +import { OPEN_PROJECT_SUCCEEDED } from '../actions/projects' import { RESET_CURRENT_TOPOLOGY, SET_CURRENT_TOPOLOGY } from '../actions/topology/building' export function currentTopologyId(state = '-1', action) { @@ -13,12 +13,12 @@ export function currentTopologyId(state = '-1', action) { } } -export function currentSimulationId(state = '-1', action) { +export function currentProjectId(state = '-1', action) { switch (action.type) { - case OPEN_SIMULATION_SUCCEEDED: + case OPEN_PROJECT_SUCCEEDED: return action.id case OPEN_EXPERIMENT_SUCCEEDED: - return action.simulationId + return action.projectId default: return state } diff --git a/frontend/src/reducers/index.js b/frontend/src/reducers/index.js index 1c3ee145..6ca95ec6 100644 --- a/frontend/src/reducers/index.js +++ b/frontend/src/reducers/index.js @@ -1,29 +1,21 @@ import { combineReducers } from 'redux' import { auth } from './auth' import { construction } from './construction-mode' -import { currentTopologyId, currentSimulationId } from './current-ids' +import { currentProjectId, currentTopologyId } 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 { projectList } from './project-list' const rootReducer = combineReducers({ objects, - states, modals, - simulationList, + projectList: projectList, construction, map, - currentSimulationId, + currentProjectId, currentTopologyId, - currentExperimentId, - currentTick, - lastSimulatedTick, - loadMetric, - isPlaying, interactionLevel, auth, }) diff --git a/frontend/src/reducers/interaction-level.js b/frontend/src/reducers/interaction-level.js index 88c3b30e..21aba715 100644 --- a/frontend/src/reducers/interaction-level.js +++ b/frontend/src/reducers/interaction-level.js @@ -5,13 +5,13 @@ import { GO_FROM_RACK_TO_MACHINE, GO_FROM_ROOM_TO_RACK, } from '../actions/interaction-level' -import { OPEN_SIMULATION_SUCCEEDED } from '../actions/simulations' +import { OPEN_PROJECT_SUCCEEDED } from '../actions/projects' 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 OPEN_PROJECT_SUCCEEDED: case SET_CURRENT_TOPOLOGY: return { mode: 'BUILDING', diff --git a/frontend/src/reducers/modals.js b/frontend/src/reducers/modals.js index 81a0660e..a042aaea 100644 --- a/frontend/src/reducers/modals.js +++ b/frontend/src/reducers/modals.js @@ -2,7 +2,7 @@ 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_PROJECT_MODAL, OPEN_NEW_PROJECT_MODAL } from '../actions/modals/projects' import { CLOSE_CHANGE_TOPOLOGY_MODAL, CLOSE_DELETE_MACHINE_MODAL, @@ -19,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 @@ -33,7 +33,7 @@ function modal(openAction, closeAction) { } export const modals = combineReducers({ - newSimulationModalVisible: modal(OPEN_NEW_SIMULATION_MODAL, CLOSE_NEW_SIMULATION_MODAL), + newProjectModalVisible: modal(OPEN_NEW_PROJECT_MODAL, CLOSE_NEW_PROJECT_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), diff --git a/frontend/src/reducers/objects.js b/frontend/src/reducers/objects.js index f52ca369..d25eb136 100644 --- a/frontend/src/reducers/objects.js +++ b/frontend/src/reducers/objects.js @@ -8,9 +8,9 @@ import { import { CPU_UNITS, GPU_UNITS, MEMORY_UNITS, STORAGE_UNITS } from '../util/unit-specifications' export const objects = combineReducers({ - simulation: object('simulation'), + project: object('project'), user: object('user'), - authorization: objectWithId('authorization', (object) => [object.userId, object.simulationId]), + authorization: objectWithId('authorization', (object) => [object.userId, object.projectId]), cpu: object('cpu', CPU_UNITS), gpu: object('gpu', GPU_UNITS), memory: object('memory', MEMORY_UNITS), diff --git a/frontend/src/reducers/project-list.js b/frontend/src/reducers/project-list.js new file mode 100644 index 00000000..1f1aa8d0 --- /dev/null +++ b/frontend/src/reducers/project-list.js @@ -0,0 +1,30 @@ +import { combineReducers } from 'redux' +import { ADD_PROJECT_SUCCEEDED, DELETE_PROJECT_SUCCEEDED, SET_AUTH_VISIBILITY_FILTER } from '../actions/projects' +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_PROJECT_SUCCEEDED: + return [...state, action.authorization] + case DELETE_PROJECT_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 const projectList = combineReducers({ + authorizationsOfCurrentUser, + authVisibilityFilter, +}) diff --git a/frontend/src/reducers/simulation-list.js b/frontend/src/reducers/simulation-list.js deleted file mode 100644 index 383f4b35..00000000 --- a/frontend/src/reducers/simulation-list.js +++ /dev/null @@ -1,34 +0,0 @@ -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' - -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 - } -} - -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, -}) diff --git a/frontend/src/reducers/simulation-mode.js b/frontend/src/reducers/simulation-mode.js deleted file mode 100644 index 5f938ec8..00000000 --- a/frontend/src/reducers/simulation-mode.js +++ /dev/null @@ -1,58 +0,0 @@ -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 - } -} - -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 - } -} - -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 - } -} - -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 - } -} diff --git a/frontend/src/reducers/states.js b/frontend/src/reducers/states.js deleted file mode 100644 index c9bb4158..00000000 --- a/frontend/src/reducers/states.js +++ /dev/null @@ -1,32 +0,0 @@ -import { combineReducers } from 'redux' -import { ADD_BATCH_TO_STATES } from '../actions/states' - -export const states = combineReducers({ - room: objectStates('room'), - rack: objectStates('rack'), - machine: objectStates('machine'), -}) - -function objectStates(type) { - 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] } - ) - } - - return Object.assign({}, state, batch) - } - - return state - } -} -- cgit v1.2.3