summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/redux
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-web/opendc-web-ui/src/redux')
-rw-r--r--opendc-web/opendc-web-ui/src/redux/actions/portfolios.js11
-rw-r--r--opendc-web/opendc-web-ui/src/redux/actions/scenarios.js9
-rw-r--r--opendc-web/opendc-web-ui/src/redux/actions/topologies.js3
-rw-r--r--opendc-web/opendc-web-ui/src/redux/reducers/current-ids.js44
-rw-r--r--opendc-web/opendc-web-ui/src/redux/reducers/index.js5
-rw-r--r--opendc-web/opendc-web-ui/src/redux/sagas/portfolios.js48
-rw-r--r--opendc-web/opendc-web-ui/src/redux/sagas/projects.js2
-rw-r--r--opendc-web/opendc-web-ui/src/redux/sagas/scenarios.js8
-rw-r--r--opendc-web/opendc-web-ui/src/redux/sagas/topology.js28
9 files changed, 44 insertions, 114 deletions
diff --git a/opendc-web/opendc-web-ui/src/redux/actions/portfolios.js b/opendc-web/opendc-web-ui/src/redux/actions/portfolios.js
index d37886d8..923cd217 100644
--- a/opendc-web/opendc-web-ui/src/redux/actions/portfolios.js
+++ b/opendc-web/opendc-web-ui/src/redux/actions/portfolios.js
@@ -2,11 +2,11 @@ export const ADD_PORTFOLIO = 'ADD_PORTFOLIO'
export const UPDATE_PORTFOLIO = 'UPDATE_PORTFOLIO'
export const DELETE_PORTFOLIO = 'DELETE_PORTFOLIO'
export const OPEN_PORTFOLIO_SUCCEEDED = 'OPEN_PORTFOLIO_SUCCEEDED'
-export const SET_CURRENT_PORTFOLIO = 'SET_CURRENT_PORTFOLIO'
-export function addPortfolio(portfolio) {
+export function addPortfolio(projectId, portfolio) {
return {
type: ADD_PORTFOLIO,
+ projectId,
portfolio,
}
}
@@ -32,10 +32,3 @@ export function openPortfolioSucceeded(projectId, portfolioId) {
portfolioId,
}
}
-
-export function setCurrentPortfolio(portfolioId) {
- return {
- type: SET_CURRENT_PORTFOLIO,
- portfolioId,
- }
-}
diff --git a/opendc-web/opendc-web-ui/src/redux/actions/scenarios.js b/opendc-web/opendc-web-ui/src/redux/actions/scenarios.js
index c8a90762..644933d6 100644
--- a/opendc-web/opendc-web-ui/src/redux/actions/scenarios.js
+++ b/opendc-web/opendc-web-ui/src/redux/actions/scenarios.js
@@ -2,7 +2,6 @@ export const ADD_SCENARIO = 'ADD_SCENARIO'
export const UPDATE_SCENARIO = 'UPDATE_SCENARIO'
export const DELETE_SCENARIO = 'DELETE_SCENARIO'
export const OPEN_SCENARIO_SUCCEEDED = 'OPEN_SCENARIO_SUCCEEDED'
-export const SET_CURRENT_SCENARIO = 'SET_CURRENT_SCENARIO'
export function addScenario(scenario) {
return {
@@ -33,11 +32,3 @@ export function openScenarioSucceeded(projectId, portfolioId, scenarioId) {
scenarioId,
}
}
-
-export function setCurrentScenario(portfolioId, scenarioId) {
- return {
- type: SET_CURRENT_SCENARIO,
- portfolioId,
- scenarioId,
- }
-}
diff --git a/opendc-web/opendc-web-ui/src/redux/actions/topologies.js b/opendc-web/opendc-web-ui/src/redux/actions/topologies.js
index dcce3b7d..abfded7e 100644
--- a/opendc-web/opendc-web-ui/src/redux/actions/topologies.js
+++ b/opendc-web/opendc-web-ui/src/redux/actions/topologies.js
@@ -1,9 +1,10 @@
export const ADD_TOPOLOGY = 'ADD_TOPOLOGY'
export const DELETE_TOPOLOGY = 'DELETE_TOPOLOGY'
-export function addTopology(name, duplicateId) {
+export function addTopology(projectId, name, duplicateId) {
return {
type: ADD_TOPOLOGY,
+ projectId,
name,
duplicateId,
}
diff --git a/opendc-web/opendc-web-ui/src/redux/reducers/current-ids.js b/opendc-web/opendc-web-ui/src/redux/reducers/current-ids.js
index 9b46aa60..c0baf567 100644
--- a/opendc-web/opendc-web-ui/src/redux/reducers/current-ids.js
+++ b/opendc-web/opendc-web-ui/src/redux/reducers/current-ids.js
@@ -1,7 +1,4 @@
-import { OPEN_PORTFOLIO_SUCCEEDED, SET_CURRENT_PORTFOLIO } from '../actions/portfolios'
-import { OPEN_PROJECT_SUCCEEDED } from '../actions/projects'
import { SET_CURRENT_TOPOLOGY } from '../actions/topology/building'
-import { OPEN_SCENARIO_SUCCEEDED, SET_CURRENT_SCENARIO } from '../actions/scenarios'
export function currentTopologyId(state = '-1', action) {
switch (action.type) {
@@ -11,44 +8,3 @@ export function currentTopologyId(state = '-1', action) {
return state
}
}
-
-export function currentProjectId(state = '-1', action) {
- switch (action.type) {
- case OPEN_PROJECT_SUCCEEDED:
- return action.id
- case OPEN_PORTFOLIO_SUCCEEDED:
- case OPEN_SCENARIO_SUCCEEDED:
- return action.projectId
- default:
- return state
- }
-}
-
-export function currentPortfolioId(state = '-1', action) {
- switch (action.type) {
- case OPEN_PORTFOLIO_SUCCEEDED:
- case SET_CURRENT_PORTFOLIO:
- case SET_CURRENT_SCENARIO:
- return action.portfolioId
- case OPEN_SCENARIO_SUCCEEDED:
- return action.portfolioId
- case OPEN_PROJECT_SUCCEEDED:
- case SET_CURRENT_TOPOLOGY:
- return '-1'
- default:
- return state
- }
-}
-export function currentScenarioId(state = '-1', action) {
- switch (action.type) {
- case OPEN_SCENARIO_SUCCEEDED:
- case SET_CURRENT_SCENARIO:
- return action.scenarioId
- case OPEN_PORTFOLIO_SUCCEEDED:
- case SET_CURRENT_TOPOLOGY:
- case OPEN_PROJECT_SUCCEEDED:
- return '-1'
- default:
- return state
- }
-}
diff --git a/opendc-web/opendc-web-ui/src/redux/reducers/index.js b/opendc-web/opendc-web-ui/src/redux/reducers/index.js
index b143d417..9f556d18 100644
--- a/opendc-web/opendc-web-ui/src/redux/reducers/index.js
+++ b/opendc-web/opendc-web-ui/src/redux/reducers/index.js
@@ -1,6 +1,6 @@
import { combineReducers } from 'redux'
import { construction } from './construction-mode'
-import { currentPortfolioId, currentProjectId, currentScenarioId, currentTopologyId } from './current-ids'
+import { currentTopologyId } from './current-ids'
import { interactionLevel } from './interaction-level'
import { map } from './map'
import { objects } from './objects'
@@ -11,10 +11,7 @@ const rootReducer = combineReducers({
projects,
construction,
map,
- currentProjectId,
currentTopologyId,
- currentPortfolioId,
- currentScenarioId,
interactionLevel,
})
diff --git a/opendc-web/opendc-web-ui/src/redux/sagas/portfolios.js b/opendc-web/opendc-web-ui/src/redux/sagas/portfolios.js
index 340cb490..48d1ad3e 100644
--- a/opendc-web/opendc-web-ui/src/redux/sagas/portfolios.js
+++ b/opendc-web/opendc-web-ui/src/redux/sagas/portfolios.js
@@ -12,35 +12,37 @@ export function* onOpenPortfolioSucceeded(action) {
const project = yield call(getProject, auth, action.projectId)
yield put(addToStore('project', project))
yield fetchAndStoreAllTopologiesOfProject(project._id)
- yield fetchPortfoliosOfProject()
+ yield fetchPortfoliosOfProject(project)
yield fetchAndStoreAllSchedulers()
yield fetchAndStoreAllTraces()
- yield watchForPortfolioResults()
+ yield watchForPortfolioResults(action.portfolioId)
} catch (error) {
console.error(error)
}
}
-export function* watchForPortfolioResults() {
+export function* watchForPortfolioResults(portfolioId) {
try {
- const currentPortfolioId = yield select((state) => state.currentPortfolioId)
- let unfinishedScenarios = yield getCurrentUnfinishedScenarios()
+ let unfinishedScenarios = yield getCurrentUnfinishedScenarios(portfolioId)
while (unfinishedScenarios.length > 0) {
yield delay(3000)
- yield fetchPortfolioWithScenarios(currentPortfolioId)
- unfinishedScenarios = yield getCurrentUnfinishedScenarios()
+ yield fetchPortfolioWithScenarios(portfolioId)
+ unfinishedScenarios = yield getCurrentUnfinishedScenarios(portfolioId)
}
} catch (error) {
console.error(error)
}
}
-export function* getCurrentUnfinishedScenarios() {
+export function* getCurrentUnfinishedScenarios(portfolioId) {
try {
- const currentPortfolioId = yield select((state) => state.currentPortfolioId)
- const scenarioIds = yield select((state) => state.objects.portfolio[currentPortfolioId].scenarioIds)
+ if (!portfolioId) {
+ return []
+ }
+
+ const scenarioIds = yield select((state) => state.objects.portfolio[portfolioId].scenarioIds)
const scenarioObjects = yield select((state) => state.objects.scenario)
const scenarios = scenarioIds.map((s) => scenarioObjects[s])
return scenarios.filter((s) => !s || s.simulation.state === 'QUEUED' || s.simulation.state === 'RUNNING')
@@ -49,16 +51,13 @@ export function* getCurrentUnfinishedScenarios() {
}
}
-export function* fetchPortfoliosOfProject() {
+export function* fetchPortfoliosOfProject(project) {
try {
- const currentProjectId = yield select((state) => state.currentProjectId)
- const currentProject = yield select((state) => state.objects.project[currentProjectId])
-
yield fetchAndStoreAllSchedulers()
yield fetchAndStoreAllTraces()
- for (let i in currentProject.portfolioIds) {
- yield fetchPortfolioWithScenarios(currentProject.portfolioIds[i])
+ for (const i in project.portfolioIds) {
+ yield fetchPortfolioWithScenarios(project.portfolioIds[i])
}
} catch (error) {
console.error(error)
@@ -83,22 +82,22 @@ export function* fetchPortfolioWithScenarios(portfolioId) {
export function* onAddPortfolio(action) {
try {
- const currentProjectId = yield select((state) => state.currentProjectId)
+ const { projectId } = action
const auth = yield getContext('auth')
const portfolio = yield call(
addPortfolio,
auth,
- currentProjectId,
+ projectId,
Object.assign({}, action.portfolio, {
- projectId: currentProjectId,
+ projectId: projectId,
scenarioIds: [],
})
)
yield put(addToStore('portfolio', portfolio))
- const portfolioIds = yield select((state) => state.objects.project[currentProjectId].portfolioIds)
+ const portfolioIds = yield select((state) => state.objects.project[projectId].portfolioIds)
yield put(
- addPropToStoreObject('project', currentProjectId, {
+ addPropToStoreObject('project', projectId, {
portfolioIds: portfolioIds.concat([portfolio._id]),
})
)
@@ -120,13 +119,14 @@ export function* onUpdatePortfolio(action) {
export function* onDeletePortfolio(action) {
try {
const auth = yield getContext('auth')
+ const portfolio = yield select((state) => state.objects.portfolio[action.id])
+
yield call(deletePortfolio, auth, action.id)
- const currentProjectId = yield select((state) => state.currentProjectId)
- const portfolioIds = yield select((state) => state.objects.project[currentProjectId].portfolioIds)
+ const portfolioIds = yield select((state) => state.objects.project[portfolio.projectId].portfolioIds)
yield put(
- addPropToStoreObject('project', currentProjectId, {
+ addPropToStoreObject('project', portfolio.projectId, {
portfolioIds: portfolioIds.filter((id) => id !== action.id),
})
)
diff --git a/opendc-web/opendc-web-ui/src/redux/sagas/projects.js b/opendc-web/opendc-web-ui/src/redux/sagas/projects.js
index 506df6ed..0689090a 100644
--- a/opendc-web/opendc-web-ui/src/redux/sagas/projects.js
+++ b/opendc-web/opendc-web-ui/src/redux/sagas/projects.js
@@ -13,7 +13,7 @@ export function* onOpenProjectSucceeded(action) {
yield put(addToStore('project', project))
yield fetchAndStoreAllTopologiesOfProject(action.id, true)
- yield fetchPortfoliosOfProject()
+ yield fetchPortfoliosOfProject(project)
yield fetchAndStoreAllSchedulers()
yield fetchAndStoreAllTraces()
} catch (error) {
diff --git a/opendc-web/opendc-web-ui/src/redux/sagas/scenarios.js b/opendc-web/opendc-web-ui/src/redux/sagas/scenarios.js
index bdb7c45d..b2979636 100644
--- a/opendc-web/opendc-web-ui/src/redux/sagas/scenarios.js
+++ b/opendc-web/opendc-web-ui/src/redux/sagas/scenarios.js
@@ -34,7 +34,7 @@ export function* onAddScenario(action) {
scenarioIds: scenarioIds.concat([scenario._id]),
})
)
- yield watchForPortfolioResults()
+ yield watchForPortfolioResults(action.scenario.portfolioId)
} catch (error) {
console.error(error)
}
@@ -53,13 +53,13 @@ export function* onUpdateScenario(action) {
export function* onDeleteScenario(action) {
try {
const auth = yield getContext('auth')
+ const scenario = yield select((state) => state.objects.scenario[action.id])
yield call(deleteScenario, auth, action.id)
- const currentPortfolioId = yield select((state) => state.currentPortfolioId)
- const scenarioIds = yield select((state) => state.objects.portfolio[currentPortfolioId].scenarioIds)
+ const scenarioIds = yield select((state) => state.objects.portfolio[scenario.portfolioId].scenarioIds)
yield put(
- addPropToStoreObject('scenario', currentPortfolioId, {
+ addPropToStoreObject('scenario', scenario.portfolioId, {
scenarioIds: scenarioIds.filter((id) => id !== action.id),
})
)
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),
})
)