summaryrefslogtreecommitdiff
path: root/src/reducers
diff options
context:
space:
mode:
authorGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-08-25 17:48:12 +0200
committerGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-23 10:05:44 +0200
commitc47a27b826f7d76410308a4151611a366f9eaf46 (patch)
treec1ca374204714cedabcacb8620848b903a0bf8d6 /src/reducers
parent1ddbbd3563af77a218020021ea50a8832900b4db (diff)
Fetch and display datacenter topology
Diffstat (limited to 'src/reducers')
-rw-r--r--src/reducers/index.js5
-rw-r--r--src/reducers/objects.js24
-rw-r--r--src/reducers/topology.js10
3 files changed, 30 insertions, 9 deletions
diff --git a/src/reducers/index.js b/src/reducers/index.js
index 40a51a04..287a9762 100644
--- a/src/reducers/index.js
+++ b/src/reducers/index.js
@@ -2,7 +2,8 @@ import {combineReducers} from "redux";
import {auth} from "./auth";
import {modals} from "./modals";
import {objects} from "./objects";
-import {authorizationsOfCurrentUser, authVisibilityFilter} from "./simulations";
+import {authorizationsOfCurrentUser, authVisibilityFilter, currentSimulationId} from "./simulations";
+import {currentDatacenterId} from "./topology";
const rootReducer = combineReducers({
auth,
@@ -10,6 +11,8 @@ const rootReducer = combineReducers({
modals,
authorizationsOfCurrentUser,
authVisibilityFilter,
+ currentSimulationId,
+ currentDatacenterId,
});
export default rootReducer;
diff --git a/src/reducers/objects.js b/src/reducers/objects.js
index 60cd2711..4fbffea6 100644
--- a/src/reducers/objects.js
+++ b/src/reducers/objects.js
@@ -1,5 +1,5 @@
import {combineReducers} from "redux";
-import {ADD_TO_STORE} from "../actions/objects";
+import {ADD_PROP_TO_STORE_OBJECT, ADD_TO_STORE} from "../actions/objects";
export const objects = combineReducers({
simulation: object("simulation"),
@@ -27,14 +27,22 @@ function object(type) {
function objectWithId(type, getId) {
return (state = {}, action) => {
- if (action.type === ADD_TO_STORE) {
- if (action.objectType === type) {
- return Object.assign(
- state,
- {[getId(action.object)]: action.object}
- );
- }
+ 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)}
+ );
+ }
+
+ return state;
};
}
diff --git a/src/reducers/topology.js b/src/reducers/topology.js
new file mode 100644
index 00000000..caafb7c1
--- /dev/null
+++ b/src/reducers/topology.js
@@ -0,0 +1,10 @@
+import {FETCH_LATEST_DATACENTER_SUCCEEDED} from "../actions/topology";
+
+export function currentDatacenterId(state = -1, action) {
+ switch (action.type) {
+ case FETCH_LATEST_DATACENTER_SUCCEEDED:
+ return action.datacenterId;
+ default:
+ return state;
+ }
+}