diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-07-07 15:07:11 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-07-07 15:07:11 +0200 |
| commit | aa788a3ad18badfac8beaabdaffc88b9e52f9306 (patch) | |
| tree | 2046d0a401ca0853d5e85de9d6360edcb79f7ebd /opendc-web | |
| parent | 1ce8bf170cda2afab334cd330325cd4fbb97dab4 (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')
17 files changed, 80 insertions, 199 deletions
diff --git a/opendc-web/opendc-web-ui/src/components/app/sidebars/project/PortfolioListComponent.js b/opendc-web/opendc-web-ui/src/components/app/sidebars/project/PortfolioListComponent.js index ce271819..b948b747 100644 --- a/opendc-web/opendc-web-ui/src/components/app/sidebars/project/PortfolioListComponent.js +++ b/opendc-web/opendc-web-ui/src/components/app/sidebars/project/PortfolioListComponent.js @@ -61,7 +61,7 @@ function PortfolioListComponent({ PortfolioListComponent.propTypes = { portfolios: PropTypes.arrayOf(Portfolio), - currentProjectId: PropTypes.string.isRequired, + currentProjectId: PropTypes.string, currentPortfolioId: PropTypes.string, onNewPortfolio: PropTypes.func.isRequired, onChoosePortfolio: PropTypes.func.isRequired, diff --git a/opendc-web/opendc-web-ui/src/components/app/sidebars/project/ScenarioListComponent.js b/opendc-web/opendc-web-ui/src/components/app/sidebars/project/ScenarioListComponent.js index f990dfcb..e81d2b78 100644 --- a/opendc-web/opendc-web-ui/src/components/app/sidebars/project/ScenarioListComponent.js +++ b/opendc-web/opendc-web-ui/src/components/app/sidebars/project/ScenarioListComponent.js @@ -1,48 +1,19 @@ import PropTypes from 'prop-types' import React from 'react' import { Scenario } from '../../../../shapes' -import Link from 'next/link' import { Button, Col, Row } from 'reactstrap' -import classNames from 'classnames' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import { faPlus, faPlay, faTrash } from '@fortawesome/free-solid-svg-icons' +import { faPlus, faTrash } from '@fortawesome/free-solid-svg-icons' -function ScenarioListComponent({ - scenarios, - portfolioId, - currentProjectId, - currentScenarioId, - onNewScenario, - onChooseScenario, - onDeleteScenario, -}) { +function ScenarioListComponent({ scenarios, portfolioId, onNewScenario, onDeleteScenario }) { return ( <> {scenarios.map((scenario, idx) => ( <Row key={scenario._id} className="mb-1"> - <Col - xs="7" - className={classNames('pl-5 align-self-center', { - 'font-weight-bold': scenario._id === currentScenarioId, - })} - > + <Col xs="7" className="pl-5 align-self-center"> {scenario.name} </Col> <Col xs="5" className="text-right"> - <Link - passHref - href={`/projects/${currentProjectId}/portfolios/${scenario.portfolioId}/scenarios/${scenario._id}`} - > - <Button - color="primary" - outline - disabled - className="mr-1" - onClick={() => onChooseScenario(scenario.portfolioId, scenario._id)} - > - <FontAwesomeIcon icon={faPlay} /> - </Button> - </Link> <Button color="danger" outline @@ -67,10 +38,7 @@ function ScenarioListComponent({ ScenarioListComponent.propTypes = { scenarios: PropTypes.arrayOf(Scenario), portfolioId: PropTypes.string, - currentProjectId: PropTypes.string.isRequired, - currentScenarioId: PropTypes.string, onNewScenario: PropTypes.func.isRequired, - onChooseScenario: PropTypes.func.isRequired, onDeleteScenario: PropTypes.func.isRequired, } diff --git a/opendc-web/opendc-web-ui/src/containers/app/results/PortfolioResultsContainer.js b/opendc-web/opendc-web-ui/src/containers/app/results/PortfolioResultsContainer.js index e60abe18..ce7d5514 100644 --- a/opendc-web/opendc-web-ui/src/containers/app/results/PortfolioResultsContainer.js +++ b/opendc-web/opendc-web-ui/src/containers/app/results/PortfolioResultsContainer.js @@ -1,13 +1,16 @@ import React from 'react' import { useSelector } from 'react-redux' import PortfolioResultsComponent from '../../../components/app/results/PortfolioResultsComponent' +import { useRouter } from 'next/router' const PortfolioResultsContainer = (props) => { + const router = useRouter() + const { portfolio: currentPortfolioId } = router.query const { scenarios, portfolio } = useSelector((state) => { if ( - state.currentPortfolioId === '-1' || - !state.objects.portfolio[state.currentPortfolioId] || - state.objects.portfolio[state.currentPortfolioId].scenarioIds + !currentPortfolioId || + !state.objects.portfolio[currentPortfolioId] || + state.objects.portfolio[currentPortfolioId].scenarioIds .map((scenarioId) => state.objects.scenario[scenarioId]) .some((s) => s === undefined) ) { @@ -18,8 +21,8 @@ const PortfolioResultsContainer = (props) => { } return { - portfolio: state.objects.portfolio[state.currentPortfolioId], - scenarios: state.objects.portfolio[state.currentPortfolioId].scenarioIds.map( + portfolio: state.objects.portfolio[currentPortfolioId], + scenarios: state.objects.portfolio[currentPortfolioId].scenarioIds.map( (scenarioId) => state.objects.scenario[scenarioId] ), } diff --git a/opendc-web/opendc-web-ui/src/containers/app/sidebars/project/PortfolioListContainer.js b/opendc-web/opendc-web-ui/src/containers/app/sidebars/project/PortfolioListContainer.js index 28d7f0d1..b5bade98 100644 --- a/opendc-web/opendc-web-ui/src/containers/app/sidebars/project/PortfolioListContainer.js +++ b/opendc-web/opendc-web-ui/src/containers/app/sidebars/project/PortfolioListContainer.js @@ -2,7 +2,7 @@ import React, { useState } from 'react' import { useDispatch } from 'react-redux' import { useRouter } from 'next/router' import PortfolioListComponent from '../../../../components/app/sidebars/project/PortfolioListComponent' -import { addPortfolio, deletePortfolio, setCurrentPortfolio } from '../../../../redux/actions/portfolios' +import { addPortfolio, deletePortfolio } from '../../../../redux/actions/portfolios' import { getState } from '../../../../util/state-utils' import { setCurrentTopology } from '../../../../redux/actions/topology/building' import NewPortfolioModalComponent from '../../../../components/modals/custom-components/NewPortfolioModalComponent' @@ -17,22 +17,22 @@ const PortfolioListContainer = () => { const [isVisible, setVisible] = useState(false) const actions = { onNewPortfolio: () => setVisible(true), - onChoosePortfolio: (portfolioId) => { - dispatch(setCurrentPortfolio(portfolioId)) + onChoosePortfolio: async (portfolioId) => { + await router.push(`/projects/${currentProjectId}/portfolios/${portfolioId}`) }, onDeletePortfolio: async (id) => { if (id) { const state = await getState(dispatch) dispatch(deletePortfolio(id)) - dispatch(setCurrentTopology(state.objects.project[state.currentProjectId].topologyIds[0])) - router.push(`/projects/${state.currentProjectId}`) + dispatch(setCurrentTopology(state.objects.project[currentProjectId].topologyIds[0])) + await router.push(`/projects/${currentProjectId}`) } }, } const callback = (name, targets) => { if (name) { dispatch( - addPortfolio({ + addPortfolio(currentProjectId, { name, targets, }) diff --git a/opendc-web/opendc-web-ui/src/containers/app/sidebars/project/ScenarioListContainer.js b/opendc-web/opendc-web-ui/src/containers/app/sidebars/project/ScenarioListContainer.js index 10743401..0eb61026 100644 --- a/opendc-web/opendc-web-ui/src/containers/app/sidebars/project/ScenarioListContainer.js +++ b/opendc-web/opendc-web-ui/src/containers/app/sidebars/project/ScenarioListContainer.js @@ -2,18 +2,16 @@ import PropTypes from 'prop-types' import React, { useState } from 'react' import { useDispatch } from 'react-redux' import ScenarioListComponent from '../../../../components/app/sidebars/project/ScenarioListComponent' -import { addScenario, deleteScenario, setCurrentScenario } from '../../../../redux/actions/scenarios' -import { setCurrentPortfolio } from '../../../../redux/actions/portfolios' +import { addScenario, deleteScenario } from '../../../../redux/actions/scenarios' import NewScenarioModalComponent from '../../../../components/modals/custom-components/NewScenarioModalComponent' import { useProjectTopologies } from '../../../../data/topology' -import { useActiveScenario, useScenarios } from '../../../../data/project' +import { useScenarios } from '../../../../data/project' import { useSchedulers, useTraces } from '../../../../data/experiments' import { useRouter } from 'next/router' const ScenarioListContainer = ({ portfolioId }) => { const router = useRouter() const { project: currentProjectId } = router.query - const currentScenarioId = useActiveScenario()?._id const scenarios = useScenarios(portfolioId) const topologies = useProjectTopologies() const traces = useTraces() @@ -23,12 +21,9 @@ const ScenarioListContainer = ({ portfolioId }) => { const [isVisible, setVisible] = useState(false) const onNewScenario = (currentPortfolioId) => { - dispatch(setCurrentPortfolio(currentPortfolioId)) setVisible(true) } - const onChooseScenario = (portfolioId, scenarioId) => { - dispatch(setCurrentScenario(portfolioId, scenarioId)) - } + const onChooseScenario = (portfolioId, scenarioId) => {} const onDeleteScenario = (id) => { if (id) { dispatch(deleteScenario(id)) @@ -54,11 +49,8 @@ const ScenarioListContainer = ({ portfolioId }) => { <> <ScenarioListComponent portfolioId={portfolioId} - currentProjectId={currentProjectId} - currentScenarioId={currentScenarioId} scenarios={scenarios} onNewScenario={onNewScenario} - onChooseScenario={onChooseScenario} onDeleteScenario={onDeleteScenario} /> <NewScenarioModalComponent diff --git a/opendc-web/opendc-web-ui/src/containers/app/sidebars/project/TopologyListContainer.js b/opendc-web/opendc-web-ui/src/containers/app/sidebars/project/TopologyListContainer.js index 648c4500..69367b5f 100644 --- a/opendc-web/opendc-web-ui/src/containers/app/sidebars/project/TopologyListContainer.js +++ b/opendc-web/opendc-web-ui/src/containers/app/sidebars/project/TopologyListContainer.js @@ -3,7 +3,6 @@ import { useDispatch } from 'react-redux' import TopologyListComponent from '../../../../components/app/sidebars/project/TopologyListComponent' import { setCurrentTopology } from '../../../../redux/actions/topology/building' import { useRouter } from 'next/router' -import { getState } from '../../../../util/state-utils' import { addTopology, deleteTopology } from '../../../../redux/actions/topologies' import NewTopologyModalComponent from '../../../../components/modals/custom-components/NewTopologyModalComponent' import { useActiveTopology, useProjectTopologies } from '../../../../data/topology' @@ -11,32 +10,31 @@ import { useActiveTopology, useProjectTopologies } from '../../../../data/topolo const TopologyListContainer = () => { const dispatch = useDispatch() const router = useRouter() + const { project: currentProjectId } = router.query const topologies = useProjectTopologies() const currentTopologyId = useActiveTopology()?._id const [isVisible, setVisible] = useState(false) const onChooseTopology = async (id) => { dispatch(setCurrentTopology(id)) - const state = await getState(dispatch) - await router.push(`/projects/${state.currentProjectId}/topologies/${id}`) + await router.push(`/projects/${currentProjectId}/topologies/${id}`) } const onDeleteTopology = async (id) => { if (id) { - const state = await getState(dispatch) dispatch(deleteTopology(id)) - dispatch(setCurrentTopology(state.objects.project[state.currentProjectId].topologyIds[0])) - await router.push(`/projects/${state.currentProjectId}`) + dispatch(setCurrentTopology(state.objects.project[currentProjectId].topologyIds[0])) + await router.push(`/projects/${currentProjectId}`) } } const onCreateTopology = (name) => { if (name) { - dispatch(addTopology(name, undefined)) + dispatch(addTopology(currentProjectId, name, undefined)) } setVisible(false) } const onDuplicateTopology = (name, id) => { if (name) { - dispatch(addTopology(name, id)) + dispatch(addTopology(currentProjectId, name, id)) } setVisible(false) } diff --git a/opendc-web/opendc-web-ui/src/data/project.js b/opendc-web/opendc-web-ui/src/data/project.js index d4c95370..30b36efa 100644 --- a/opendc-web/opendc-web-ui/src/data/project.js +++ b/opendc-web/opendc-web-ui/src/data/project.js @@ -21,6 +21,7 @@ */ import { useSelector } from 'react-redux' +import { useRouter } from 'next/router' /** * Return the available projects. @@ -40,23 +41,9 @@ export function useProject(projectId) { * Return the current active project. */ export function useActiveProject() { - return useSelector((state) => - state.currentProjectId !== '-1' ? state.objects.project[state.currentProjectId] : undefined - ) -} - -/** - * Return the active portfolio. - */ -export function useActivePortfolio() { - return useSelector((state) => state.objects.portfolio[state.currentPortfolioId]) -} - -/** - * Return the active scenario. - */ -export function useActiveScenario() { - return useSelector((state) => state.objects.scenario[state.currentScenarioId]) + const router = useRouter() + const { project: projectId } = router.query + return useSelector((state) => state.objects.project[projectId]) } /** diff --git a/opendc-web/opendc-web-ui/src/data/topology.js b/opendc-web/opendc-web-ui/src/data/topology.js index d3ffb3e1..f6ce1672 100644 --- a/opendc-web/opendc-web-ui/src/data/topology.js +++ b/opendc-web/opendc-web-ui/src/data/topology.js @@ -21,6 +21,7 @@ */ import { useSelector } from 'react-redux' +import { useRouter } from 'next/router' /** * Return the current active topology. @@ -33,8 +34,10 @@ export function useActiveTopology() { * Return the topologies for the active project. */ export function useProjectTopologies() { - return useSelector(({ currentProjectId, objects }) => { - if (currentProjectId === '-1' || !objects.project[currentProjectId]) { + const router = useRouter() + const { project: currentProjectId } = router.query + return useSelector(({ objects }) => { + if (!currentProjectId || !objects.project[currentProjectId]) { return [] } 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), }) ) |
