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

73 lines
2.0 KiB
React
Raw Normal View History

2017-05-16 13:34:00 +02:00
import {LOAD_CONFIG_SUCCESS} from './actions'
2018-09-17 18:55:39 +02:00
import {LOAD_ROUTESERVERS_SUCCESS} from 'components/routeservers/actions'
2017-05-16 13:34:00 +02:00
const initialState = {
2018-09-17 22:43:26 +02:00
asn: 0, // Our own ASN (might be abstracted in the future)
routes_columns: {},
routes_columns_order: [],
neighbours_columns: {},
neighbours_columns_order: [],
lookup_columns: {},
lookup_columns_order: [],
prefix_lookup_enabled: false,
2018-08-03 17:04:31 +02:00
content: {},
noexport_load_on_demand: true, // we have to assume this
// otherwise fetch will start.
2018-09-23 17:22:15 +02:00
rpki: {
enabled: false,
},
2018-08-09 23:24:58 +02:00
bgp_communities: {},
2018-09-17 18:55:39 +02:00
blackholes: {}, // Map blackholes to routeservers
2018-09-17 22:43:26 +02:00
asns: {}, // Map ASNs to routeservers (for future use)
2017-05-16 13:34:00 +02:00
};
2018-09-17 18:55:39 +02:00
const _handleRouteserversConfig = function(state, payload) {
let blackholes = {};
2018-09-17 22:33:22 +02:00
let asns = {};
2018-09-17 22:43:26 +02:00
let asn = 0;
2018-09-17 18:55:39 +02:00
for (const rs of payload.routeservers) {
blackholes[rs.id] = rs.blackholes;
2018-09-23 17:22:15 +02:00
asns[rs.id] = rs.asn;
2018-09-17 22:43:26 +02:00
if (!asn) {
asn = rs.asn; // Just go with the first asn as our own
}
2018-09-17 18:55:39 +02:00
}
return Object.assign({}, state, {
2018-09-17 22:43:26 +02:00
asn: asn,
2018-09-17 18:55:39 +02:00
blackholes: blackholes,
2018-09-17 22:33:22 +02:00
asns: asns,
2018-09-17 18:55:39 +02:00
});
}
2017-05-16 13:34:00 +02:00
export default function reducer(state = initialState, action) {
switch(action.type) {
case LOAD_CONFIG_SUCCESS:
return Object.assign({}, state, {
routes_columns: action.payload.routes_columns,
routes_columns_order: action.payload.routes_columns_order,
neighbours_columns: action.payload.neighbours_columns,
neighbours_columns_order: action.payload.neighbours_columns_order,
lookup_columns: action.payload.lookup_columns,
lookup_columns_order: action.payload.lookup_columns_order,
2018-08-03 17:04:31 +02:00
prefix_lookup_enabled: action.payload.prefix_lookup_enabled,
2018-09-23 17:22:15 +02:00
rpki: action.payload.rpki,
2018-08-09 23:24:58 +02:00
bgp_communities: action.payload.bgp_communities,
2018-09-23 17:22:15 +02:00
2018-08-03 17:04:31 +02:00
noexport_load_on_demand: action.payload.noexport.load_on_demand
});
2018-09-17 18:55:39 +02:00
case LOAD_ROUTESERVERS_SUCCESS:
return _handleRouteserversConfig(state, action.payload);
2017-05-16 13:34:00 +02:00
}
return state;
}