summaryrefslogtreecommitdiff
path: root/frontend/src/sagas/topology.js
diff options
context:
space:
mode:
authorjc0b <j@jc0b.computer>2020-07-22 16:28:47 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-08-24 19:48:21 +0200
commitd7469b9ebb01cf36a78cc98aab31fa8f307c4f65 (patch)
treed0535fa0cfe95001302fbd2b0d046d51caab6ffd /frontend/src/sagas/topology.js
parent67b6ec800df8e023efadb60ae5f7919030b19789 (diff)
parent9e7cb3bd367607b32e102c3a87b68b33c53dec46 (diff)
Merge branch 'master' onto working copy
Diffstat (limited to 'frontend/src/sagas/topology.js')
-rw-r--r--frontend/src/sagas/topology.js28
1 files changed, 19 insertions, 9 deletions
diff --git a/frontend/src/sagas/topology.js b/frontend/src/sagas/topology.js
index e915f9ff..bba1ebb1 100644
--- a/frontend/src/sagas/topology.js
+++ b/frontend/src/sagas/topology.js
@@ -16,7 +16,7 @@ import {
DEFAULT_RACK_SLOT_CAPACITY,
MAX_NUM_UNITS_PER_MACHINE,
} from '../components/app/map/MapConstants'
-import { fetchAndStoreTopology, updateTopologyOnServer } from './objects'
+import { fetchAndStoreTopology, getTopologyAsObject, updateTopologyOnServer } from './objects'
import { uuid } from 'uuidv4'
import { addTopology, deleteTopology } from '../api/routes/topologies'
@@ -40,11 +40,21 @@ export function* onAddTopology(action) {
try {
const currentProjectId = yield select((state) => state.currentProjectId)
+ let topologyToBeCreated
+ if (action.duplicateId) {
+ topologyToBeCreated = yield getTopologyAsObject(action.duplicateId, false)
+ topologyToBeCreated = Object.assign({}, topologyToBeCreated, {
+ name: action.name,
+ })
+ } else {
+ topologyToBeCreated = { name: action.name, rooms: [] }
+ }
+
const topology = yield call(
addTopology,
- Object.assign({}, action.topology, {
+ Object.assign({}, topologyToBeCreated, {
projectId: currentProjectId,
- }),
+ })
)
yield fetchAndStoreTopology(topology._id)
@@ -52,7 +62,7 @@ export function* onAddTopology(action) {
yield put(
addPropToStoreObject('project', currentProjectId, {
topologyIds: topologyIds.concat([topology._id]),
- }),
+ })
)
yield put(setCurrentTopology(topology._id))
} catch (error) {
@@ -74,7 +84,7 @@ export function* onDeleteTopology(action) {
yield put(
addPropToStoreObject('project', currentProjectId, {
topologyIds: topologyIds.filter((id) => id !== action.id),
- }),
+ })
)
} catch (error) {
console.error(error)
@@ -258,7 +268,7 @@ export function* onAddUnit(action) {
const position = yield select((state) => state.interactionLevel.position)
const machine = yield select(
(state) =>
- state.objects.machine[state.objects.rack[state.objects.tile[tileId].rackId].machineIds[position - 1]],
+ state.objects.machine[state.objects.rack[state.objects.tile[tileId].rackId].machineIds[position - 1]]
)
if (machine[action.unitType + 'Ids'].length >= MAX_NUM_UNITS_PER_MACHINE) {
@@ -269,7 +279,7 @@ export function* onAddUnit(action) {
yield put(
addPropToStoreObject('machine', machine._id, {
[action.unitType + 'Ids']: units,
- }),
+ })
)
yield updateTopologyOnServer(topologyId)
} catch (error) {
@@ -284,7 +294,7 @@ export function* onDeleteUnit(action) {
const position = yield select((state) => state.interactionLevel.position)
const machine = yield select(
(state) =>
- state.objects.machine[state.objects.rack[state.objects.tile[tileId].rackId].machineIds[position - 1]],
+ state.objects.machine[state.objects.rack[state.objects.tile[tileId].rackId].machineIds[position - 1]]
)
const unitIds = machine[action.unitType + 'Ids'].slice()
unitIds.splice(action.index, 1)
@@ -292,7 +302,7 @@ export function* onDeleteUnit(action) {
yield put(
addPropToStoreObject('machine', machine._id, {
[action.unitType + 'Ids']: unitIds,
- }),
+ })
)
yield updateTopologyOnServer(topologyId)
} catch (error) {