summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/redux/reducers/current-ids.js
blob: 9b46aa60929bb614df1cd2d85afc22928da277c2 (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
54
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) {
        case SET_CURRENT_TOPOLOGY:
            return action.topologyId
        default:
            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
    }
}