summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/redux/reducers/objects.js
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-07-22 14:57:21 +0200
committerGitHub <noreply@github.com>2021-07-22 14:57:21 +0200
commitb0c5681b28d1c3c87b7d24d8b8d166f5566e7699 (patch)
tree4f7269996928ea480499e3cbe912b15ba994e43f /opendc-web/opendc-web-ui/src/redux/reducers/objects.js
parent51c759e74b088d405b63fdb3e374822308d21366 (diff)
parent7f083b47c2e2333819823fd7835332a0f486b626 (diff)
merge: Address technical debt in topology view v2 (#163)
This pull request aims to address some of the technical debt in the topology view of the OpenDC frontend (v2). * Perform Saga mutations through React Query * Add table view for topology view * Extract topology construction out of Sagas * Toggle to Floor Plan on room select
Diffstat (limited to 'opendc-web/opendc-web-ui/src/redux/reducers/objects.js')
-rw-r--r--opendc-web/opendc-web-ui/src/redux/reducers/objects.js56
1 files changed, 0 insertions, 56 deletions
diff --git a/opendc-web/opendc-web-ui/src/redux/reducers/objects.js b/opendc-web/opendc-web-ui/src/redux/reducers/objects.js
deleted file mode 100644
index 11f6d353..00000000
--- a/opendc-web/opendc-web-ui/src/redux/reducers/objects.js
+++ /dev/null
@@ -1,56 +0,0 @@
-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'
-import { CPU_UNITS, GPU_UNITS, MEMORY_UNITS, STORAGE_UNITS } from '../../util/unit-specifications'
-import { STORE_TOPOLOGY } from '../actions/topologies'
-
-export const objects = combineReducers({
- 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'),
- tile: object('tile'),
- room: object('room'),
- topology: object('topology'),
- prefab: object('prefab'),
-})
-
-function object(type, defaultState = {}) {
- return objectWithId(type, (object) => object._id, defaultState)
-}
-
-function objectWithId(type, getId, defaultState = {}) {
- return (state = defaultState, action) => {
- if (action.type === STORE_TOPOLOGY) {
- return { ...state, ...action.entities[type] }
- } else if (action.objectType !== type) {
- return state
- }
-
- if (action.type === ADD_TO_STORE) {
- return { ...state, [getId(action.object)]: action.object }
- } else if (action.type === ADD_PROP_TO_STORE_OBJECT) {
- return { ...state, [action.objectId]: { ...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
- }
-}