summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-server/src/main/webui/redux/reducers/topology
diff options
context:
space:
mode:
authorvincent van beek <vincent@vlogic.nl>2026-03-27 16:49:40 +0100
committerGitHub <noreply@github.com>2026-03-27 15:49:40 +0000
commit048bf777997bdbf599240645fc66612c98abf3c2 (patch)
treec04e999cb981c98ae9dc0fd83ea70aec9eaa419c /opendc-web/opendc-web-server/src/main/webui/redux/reducers/topology
parent235057cd170f1583db14bf93ea7d2de39e492356 (diff)
Add import topology (#393)
* add a the posibility to import and export topogies in JSON format * fix web-runner integration, there were several bugs and mismatches between new implementations in OpenDC and the UI
Diffstat (limited to 'opendc-web/opendc-web-server/src/main/webui/redux/reducers/topology')
-rw-r--r--opendc-web/opendc-web-server/src/main/webui/redux/reducers/topology/index.js26
1 files changed, 22 insertions, 4 deletions
diff --git a/opendc-web/opendc-web-server/src/main/webui/redux/reducers/topology/index.js b/opendc-web/opendc-web-server/src/main/webui/redux/reducers/topology/index.js
index 2c849387..18d6cde4 100644
--- a/opendc-web/opendc-web-server/src/main/webui/redux/reducers/topology/index.js
+++ b/opendc-web/opendc-web-server/src/main/webui/redux/reducers/topology/index.js
@@ -21,18 +21,36 @@
*/
import { CPU_UNITS, GPU_UNITS, MEMORY_UNITS, STORAGE_UNITS } from '../../../util/unit-specifications'
+import { STORE_TOPOLOGY } from '../../actions/topology'
+import { ADD_RACK_TO_TILE } from '../../actions/topology/room'
import machine from './machine'
import rack from './rack'
import room from './room'
import tile from './tile'
import topology from './topology'
+function unitReducer(defaultUnits, entityType) {
+ return (state = defaultUnits, action) => {
+ if (action.type === STORE_TOPOLOGY) {
+ return { ...defaultUnits, ...((action.entities && action.entities[entityType]) || {}) }
+ } else if (action.type === ADD_RACK_TO_TILE) {
+ return { ...state, ...((action.entities && action.entities[entityType]) || {}) }
+ }
+ return state
+ }
+}
+
+const cpus = unitReducer(CPU_UNITS, 'cpus')
+const gpus = unitReducer(GPU_UNITS, 'gpus')
+const memories = unitReducer(MEMORY_UNITS, 'memories')
+const storages = unitReducer(STORAGE_UNITS, 'storages')
+
function objects(state = {}, action) {
return {
- cpus: CPU_UNITS,
- gpus: GPU_UNITS,
- memories: MEMORY_UNITS,
- storages: STORAGE_UNITS,
+ cpus: cpus(state.cpus, action),
+ gpus: gpus(state.gpus, action),
+ memories: memories(state.memories, action),
+ storages: storages(state.storages, action),
machines: machine(state.machines, action, state),
racks: rack(state.racks, action, state),
tiles: tile(state.tiles, action),