summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/redux/sagas/scenarios.js
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-web/opendc-web-ui/src/redux/sagas/scenarios.js')
-rw-r--r--opendc-web/opendc-web-ui/src/redux/sagas/scenarios.js69
1 files changed, 0 insertions, 69 deletions
diff --git a/opendc-web/opendc-web-ui/src/redux/sagas/scenarios.js b/opendc-web/opendc-web-ui/src/redux/sagas/scenarios.js
deleted file mode 100644
index 10ab3547..00000000
--- a/opendc-web/opendc-web-ui/src/redux/sagas/scenarios.js
+++ /dev/null
@@ -1,69 +0,0 @@
-import { call, put, select, getContext } from 'redux-saga/effects'
-import { addPropToStoreObject, addToStore } from '../actions/objects'
-import { fetchProject } from '../../api/projects'
-import { fetchAndStoreAllTopologiesOfProject } from './topology'
-import { addScenario, deleteScenario, updateScenario } from '../../api/scenarios'
-import { fetchPortfolioWithScenarios, watchForPortfolioResults } from './portfolios'
-
-export function* onOpenScenarioSucceeded(action) {
- try {
- const auth = yield getContext('auth')
- const queryClient = yield getContext('queryClient')
- const project = yield call(() =>
- queryClient.fetchQuery(`projects/${action.projectId}`, () => fetchProject(auth, action.projectId))
- )
- yield put(addToStore('project', project))
- yield fetchAndStoreAllTopologiesOfProject(project._id)
- yield fetchPortfolioWithScenarios(action.portfolioId)
-
- // TODO Fetch scenario-specific metrics
- } catch (error) {
- console.error(error)
- }
-}
-
-export function* onAddScenario(action) {
- try {
- const auth = yield getContext('auth')
- const scenario = yield call(addScenario, auth, action.scenario.portfolioId, action.scenario)
- yield put(addToStore('scenario', scenario))
-
- const scenarioIds = yield select((state) => state.objects.portfolio[action.scenario.portfolioId].scenarioIds)
- yield put(
- addPropToStoreObject('portfolio', action.scenario.portfolioId, {
- scenarioIds: scenarioIds.concat([scenario._id]),
- })
- )
- yield watchForPortfolioResults(action.scenario.portfolioId)
- } catch (error) {
- console.error(error)
- }
-}
-
-export function* onUpdateScenario(action) {
- try {
- const auth = yield getContext('auth')
- const scenario = yield call(updateScenario, auth, action.scenario._id, action.scenario)
- yield put(addToStore('scenario', scenario))
- } catch (error) {
- console.error(error)
- }
-}
-
-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 scenarioIds = yield select((state) => state.objects.portfolio[scenario.portfolioId].scenarioIds)
-
- yield put(
- addPropToStoreObject('scenario', scenario.portfolioId, {
- scenarioIds: scenarioIds.filter((id) => id !== action.id),
- })
- )
- } catch (error) {
- console.error(error)
- }
-}