summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/redux/sagas/topology.js
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-07-07 15:07:11 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-07-07 15:07:11 +0200
commitaa788a3ad18badfac8beaabdaffc88b9e52f9306 (patch)
tree2046d0a401ca0853d5e85de9d6360edcb79f7ebd /opendc-web/opendc-web-ui/src/redux/sagas/topology.js
parent1ce8bf170cda2afab334cd330325cd4fbb97dab4 (diff)
ui: Remove current ids state from Redux
This change removes the current active identifiers from the Redux state. Instead, we use the router query to track the active project, portfolio and topology.
Diffstat (limited to 'opendc-web/opendc-web-ui/src/redux/sagas/topology.js')
-rw-r--r--opendc-web/opendc-web-ui/src/redux/sagas/topology.js28
1 files changed, 10 insertions, 18 deletions
diff --git a/opendc-web/opendc-web-ui/src/redux/sagas/topology.js b/opendc-web/opendc-web-ui/src/redux/sagas/topology.js
index e5fd3d39..4f7bc8db 100644
--- a/opendc-web/opendc-web-ui/src/redux/sagas/topology.js
+++ b/opendc-web/opendc-web-ui/src/redux/sagas/topology.js
@@ -38,31 +38,23 @@ export function* fetchAndStoreAllTopologiesOfProject(projectId, setTopology = fa
export function* onAddTopology(action) {
try {
- const currentProjectId = yield select((state) => state.currentProjectId)
+ const { projectId, duplicateId, name } = action
let topologyToBeCreated
- if (action.duplicateId) {
- topologyToBeCreated = yield getTopologyAsObject(action.duplicateId, false)
- topologyToBeCreated = Object.assign({}, topologyToBeCreated, {
- name: action.name,
- })
+ if (duplicateId) {
+ topologyToBeCreated = yield getTopologyAsObject(duplicateId, false)
+ topologyToBeCreated = { ...topologyToBeCreated, name }
} else {
topologyToBeCreated = { name: action.name, rooms: [] }
}
const auth = yield getContext('auth')
- const topology = yield call(
- addTopology,
- auth,
- Object.assign({}, topologyToBeCreated, {
- projectId: currentProjectId,
- })
- )
+ const topology = yield call(addTopology, auth, { ...topologyToBeCreated, projectId })
yield fetchAndStoreTopology(topology._id)
- const topologyIds = yield select((state) => state.objects.project[currentProjectId].topologyIds)
+ const topologyIds = yield select((state) => state.objects.project[projectId].topologyIds)
yield put(
- addPropToStoreObject('project', currentProjectId, {
+ addPropToStoreObject('project', projectId, {
topologyIds: topologyIds.concat([topology._id]),
})
)
@@ -74,8 +66,8 @@ export function* onAddTopology(action) {
export function* onDeleteTopology(action) {
try {
- const currentProjectId = yield select((state) => state.currentProjectId)
- const topologyIds = yield select((state) => state.objects.project[currentProjectId].topologyIds)
+ const topology = yield select((state) => state.objects.topologies[action.id])
+ const topologyIds = yield select((state) => state.objects.project[topology.projectId].topologyIds)
const currentTopologyId = yield select((state) => state.currentTopologyId)
if (currentTopologyId === action.id) {
yield put(setCurrentTopology(topologyIds.filter((t) => t !== action.id)[0]))
@@ -85,7 +77,7 @@ export function* onDeleteTopology(action) {
yield call(deleteTopology, auth, action.id)
yield put(
- addPropToStoreObject('project', currentProjectId, {
+ addPropToStoreObject('project', topology.projectId, {
topologyIds: topologyIds.filter((id) => id !== action.id),
})
)