summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/redux/reducers/construction-mode.js
blob: d0aac5ae8f49a4e1425296a63a7aca073e1f4564 (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
import { combineReducers } from 'redux'
import { GO_DOWN_ONE_INTERACTION_LEVEL } from '../actions/interaction-level'
import {
    CANCEL_NEW_ROOM_CONSTRUCTION_SUCCEEDED,
    FINISH_NEW_ROOM_CONSTRUCTION,
    FINISH_ROOM_EDIT,
    START_NEW_ROOM_CONSTRUCTION_SUCCEEDED,
    START_ROOM_EDIT,
} from '../actions/topology/building'
import { DELETE_ROOM, START_RACK_CONSTRUCTION, STOP_RACK_CONSTRUCTION } from '../actions/topology/room'

export function currentRoomInConstruction(state = '-1', action) {
    switch (action.type) {
        case START_NEW_ROOM_CONSTRUCTION_SUCCEEDED:
            return action.roomId
        case START_ROOM_EDIT:
            return action.roomId
        case CANCEL_NEW_ROOM_CONSTRUCTION_SUCCEEDED:
        case FINISH_NEW_ROOM_CONSTRUCTION:
        case FINISH_ROOM_EDIT:
        case DELETE_ROOM:
            return '-1'
        default:
            return state
    }
}

export function inRackConstructionMode(state = false, action) {
    switch (action.type) {
        case START_RACK_CONSTRUCTION:
            return true
        case STOP_RACK_CONSTRUCTION:
        case GO_DOWN_ONE_INTERACTION_LEVEL:
            return false
        default:
            return state
    }
}

export const construction = combineReducers({
    currentRoomInConstruction,
    inRackConstructionMode,
})