summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/redux/sagas/projects.js
blob: 506df6edf1dccc9b5a4be4c04a4122b7e3a1bfc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { call, put, getContext } from 'redux-saga/effects'
import { addToStore } from '../actions/objects'
import { addProjectSucceeded, deleteProjectSucceeded, fetchProjectsSucceeded } from '../actions/projects'
import { addProject, deleteProject, getProject, getProjects } from '../../api/projects'
import { fetchAndStoreAllTopologiesOfProject } from './topology'
import { fetchAndStoreAllSchedulers, fetchAndStoreAllTraces } from './objects'
import { fetchPortfoliosOfProject } from './portfolios'

export function* onOpenProjectSucceeded(action) {
    try {
        const auth = yield getContext('auth')
        const project = yield call(getProject, auth, action.id)
        yield put(addToStore('project', project))

        yield fetchAndStoreAllTopologiesOfProject(action.id, true)
        yield fetchPortfoliosOfProject()
        yield fetchAndStoreAllSchedulers()
        yield fetchAndStoreAllTraces()
    } catch (error) {
        console.error(error)
    }
}

export function* onProjectAdd(action) {
    try {
        const auth = yield getContext('auth')
        const project = yield call(addProject, auth, { name: action.name })
        yield put(addToStore('project', project))
        yield put(addProjectSucceeded(project))
    } catch (error) {
        console.error(error)
    }
}

export function* onProjectDelete(action) {
    try {
        const auth = yield getContext('auth')
        yield call(deleteProject, auth, action.id)
        yield put(deleteProjectSucceeded(action.id))
    } catch (error) {
        console.error(error)
    }
}

export function* onFetchProjects(action) {
    try {
        const auth = yield getContext('auth')
        const projects = yield call(getProjects, auth)
        yield put(fetchProjectsSucceeded(projects))
    } catch (error) {
        console.error(error)
    }
}