summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/redux/sagas/portfolios.js
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-07-07 16:27:49 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-07-07 16:28:25 +0200
commite5e5d2c65e583493870bc0b62fb185c5e757c13f (patch)
treedc9bc25517ce36e155932212f598bf2375519d34 /opendc-web/opendc-web-ui/src/redux/sagas/portfolios.js
parentaa788a3ad18badfac8beaabdaffc88b9e52f9306 (diff)
ui: Migrate project APIs to React Query
This change updates the OpenDC frontend to use React Query for fetching and mutating project data. Previously, this state was tracked and synchronized via Redux. Migrating to React Query greatly simplifies the state synchronization logic necessary in the frontend.
Diffstat (limited to 'opendc-web/opendc-web-ui/src/redux/sagas/portfolios.js')
-rw-r--r--opendc-web/opendc-web-ui/src/redux/sagas/portfolios.js29
1 files changed, 7 insertions, 22 deletions
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 48d1ad3e..c32fcdc0 100644
--- a/opendc-web/opendc-web-ui/src/redux/sagas/portfolios.js
+++ b/opendc-web/opendc-web-ui/src/redux/sagas/portfolios.js
@@ -1,7 +1,7 @@
import { call, put, select, delay, getContext } from 'redux-saga/effects'
-import { addPropToStoreObject, addToStore } from '../actions/objects'
+import { addToStore } from '../actions/objects'
import { addPortfolio, deletePortfolio, getPortfolio, updatePortfolio } from '../../api/portfolios'
-import { getProject } from '../../api/projects'
+import { fetchProject } from '../../api/projects'
import { fetchAndStoreAllSchedulers, fetchAndStoreAllTraces } from './objects'
import { fetchAndStoreAllTopologiesOfProject } from './topology'
import { getScenario } from '../../api/scenarios'
@@ -9,9 +9,11 @@ import { getScenario } from '../../api/scenarios'
export function* onOpenPortfolioSucceeded(action) {
try {
const auth = yield getContext('auth')
- const project = yield call(getProject, auth, action.projectId)
- yield put(addToStore('project', project))
- yield fetchAndStoreAllTopologiesOfProject(project._id)
+ const queryClient = yield getContext('queryClient')
+ const project = yield call(() =>
+ queryClient.fetchQuery(`projects/${action.projectId}`, () => fetchProject(auth, action.projectId))
+ )
+ yield fetchAndStoreAllTopologiesOfProject(action.projectId)
yield fetchPortfoliosOfProject(project)
yield fetchAndStoreAllSchedulers()
yield fetchAndStoreAllTraces()
@@ -94,13 +96,6 @@ export function* onAddPortfolio(action) {
})
)
yield put(addToStore('portfolio', portfolio))
-
- const portfolioIds = yield select((state) => state.objects.project[projectId].portfolioIds)
- yield put(
- addPropToStoreObject('project', projectId, {
- portfolioIds: portfolioIds.concat([portfolio._id]),
- })
- )
} catch (error) {
console.error(error)
}
@@ -119,17 +114,7 @@ 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 portfolioIds = yield select((state) => state.objects.project[portfolio.projectId].portfolioIds)
-
- yield put(
- addPropToStoreObject('project', portfolio.projectId, {
- portfolioIds: portfolioIds.filter((id) => id !== action.id),
- })
- )
} catch (error) {
console.error(error)
}