1
0
mirror of https://github.com/alice-lg/alice-lg.git synced 2024-05-11 05:55:03 +00:00

133 lines
3.0 KiB
React
Raw Normal View History

2017-05-16 13:34:00 +02:00
// Routeserver Reducer
import {LOAD_ROUTESERVERS_REQUEST,
LOAD_ROUTESERVERS_SUCCESS,
2018-08-05 18:39:11 +02:00
2017-05-16 13:34:00 +02:00
LOAD_ROUTESERVER_STATUS_SUCCESS,
2018-08-05 18:39:11 +02:00
LOAD_ROUTESERVER_STATUS_ERROR,
2017-05-16 13:34:00 +02:00
LOAD_ROUTESERVER_PROTOCOL_REQUEST,
LOAD_ROUTESERVER_PROTOCOL_SUCCESS,
SET_PROTOCOLS_FILTER_VALUE,
SET_PROTOCOLS_FILTER,
2017-05-23 16:08:43 +02:00
SET_ROUTES_FILTER_VALUE}
2017-05-16 13:34:00 +02:00
from './actions'
2017-05-23 16:08:43 +02:00
import {LOAD_REJECT_REASONS_SUCCESS,
LOAD_NOEXPORT_REASONS_SUCCESS}
from './large-communities/actions'
2017-05-16 13:34:00 +02:00
const initialState = {
2018-08-05 18:39:11 +02:00
2017-05-16 13:34:00 +02:00
all: [],
2018-08-05 18:39:11 +02:00
2017-05-16 13:34:00 +02:00
details: {},
protocols: {},
2018-08-05 18:54:19 +02:00
statusErrors: {},
2017-05-16 13:34:00 +02:00
reject_reasons: {},
reject_id: 0,
2017-05-23 16:08:43 +02:00
reject_asn: 0,
noexport_reasons: {},
noexport_id: 0,
noexport_asn: 0,
2017-05-16 13:34:00 +02:00
protocolsFilterValue: "",
protocolsFilter: "",
2017-05-16 13:34:00 +02:00
isLoading: false,
protocolsAreLoading: false
};
export default function reducer(state = initialState, action) {
switch(action.type) {
case LOAD_ROUTESERVERS_REQUEST:
return Object.assign({}, state, {
isLoading: true
});
case LOAD_ROUTESERVERS_SUCCESS:
return Object.assign({}, state, {
all: action.payload.routeservers,
isLoading: false
});
case LOAD_ROUTESERVER_PROTOCOL_REQUEST:
return Object.assign({}, state, {
protocolsAreLoading: true
})
case LOAD_ROUTESERVER_PROTOCOL_SUCCESS:
var protocols = Object.assign({}, state.protocols, {
[action.payload.routeserverId]: action.payload.protocol
});
return Object.assign({}, state, {
protocols: protocols,
protocolsAreLoading: false
});
2017-05-23 16:08:43 +02:00
case LOAD_NOEXPORT_REASONS_SUCCESS:
2017-05-16 13:34:00 +02:00
case LOAD_REJECT_REASONS_SUCCESS:
return Object.assign({}, state, action.payload);
2017-05-23 16:08:43 +02:00
2017-05-16 13:34:00 +02:00
case LOAD_ROUTESERVER_STATUS_SUCCESS:
var details = Object.assign({}, state.details, {
[action.payload.routeserverId]: action.payload.status
});
2018-08-05 18:54:19 +02:00
var errors = Object.assign({}, state.statusErrors, {
[action.payload.routeserverId]: null,
});
2017-05-16 13:34:00 +02:00
return Object.assign({}, state, {
2018-08-05 18:54:19 +02:00
details: details,
statusErrors: errors
2017-05-16 13:34:00 +02:00
});
2018-08-05 18:39:11 +02:00
case LOAD_ROUTESERVER_STATUS_ERROR:
2018-08-05 18:54:19 +02:00
var info = {
code: 42,
tag: "UNKNOWN_ERROR",
message: "Unknown error"
};
if (action.payload.error &&
action.payload.error.response &&
action.payload.error.response.data &&
action.payload.error.response.data.code) {
info = action.payload.error.response.data;
}
2018-08-05 18:39:11 +02:00
2018-08-05 18:54:19 +02:00
var errors = Object.assign({}, state.statusErrors, {
[action.payload.routeserverId]: info
});
return Object.assign({}, state, {
statusErrors: errors
});
2018-08-05 18:39:11 +02:00
return state;
2017-05-16 13:34:00 +02:00
case SET_PROTOCOLS_FILTER_VALUE:
return Object.assign({}, state, {
protocolsFilterValue: action.payload.value
});
case SET_PROTOCOLS_FILTER:
return Object.assign({}, state, {
protocolsFilter: action.payload.value
});
2017-05-16 13:34:00 +02:00
case SET_ROUTES_FILTER_VALUE:
return Object.assign({}, state, action.payload);
}
return state;
}