added discovery ing
This commit is contained in:
parent
042e846b1c
commit
aeb077e709
|
@ -1,5 +1,6 @@
|
|||
import Action from '@overflow/commons/redux/Action';
|
||||
import { ReducersMapObject } from 'redux';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import Host from '../../api/model/Host';
|
||||
import Port from '../../api/model/Port';
|
||||
|
@ -10,34 +11,70 @@ import {
|
|||
HostState, hostDefaultState,
|
||||
PortState, portDefaultState,
|
||||
ServiceState, serviceDefaultState,
|
||||
DiscoveryIngState, DiscoveryIngDefaultState,
|
||||
} from '../state/Ing';
|
||||
|
||||
const reducer: ReducersMapObject = {
|
||||
[IngActionTypes.RECEIVE_HOST]: (state: HostState = hostDefaultState,
|
||||
action: Action<Host>): HostState => {
|
||||
[IngActionTypes.RECEIVE_HOST]: (state: DiscoveryIngState = DiscoveryIngDefaultState,
|
||||
action: Action<Host>): DiscoveryIngState => {
|
||||
|
||||
let hostList: Host[] = null;
|
||||
if(state.hostList === null || state.hostList === undefined) {
|
||||
hostList = new Array();
|
||||
hostList.push(action.payload);
|
||||
} else {
|
||||
hostList = _.clone(state.hostList);
|
||||
hostList.push(action.payload);
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
// discoveryData: action.payload,
|
||||
hostList: hostList,
|
||||
};
|
||||
},
|
||||
[IngActionTypes.RECEIVE_PORT]: (state: PortState = portDefaultState,
|
||||
action: Action<Port>): PortState => {
|
||||
[IngActionTypes.RECEIVE_PORT]: (state: DiscoveryIngState = DiscoveryIngDefaultState,
|
||||
action: Action<Port>): DiscoveryIngState => {
|
||||
|
||||
let hostList: Host[] = null;
|
||||
if(state.hostList === null || state.hostList === undefined) {
|
||||
hostList = new Array();
|
||||
let port: Port = action.payload;
|
||||
let host: Host = _.clone(port.host);
|
||||
host.ports = new Array();
|
||||
port.host = host;
|
||||
host.ports.push(port);
|
||||
hostList.push(port.host);
|
||||
|
||||
} else {
|
||||
hostList = _.clone(state.hostList);
|
||||
let port: Port = action.payload;
|
||||
// let host: Host = _.clone(port.host);
|
||||
|
||||
for(let h of hostList) {
|
||||
if(h.ip === port.host.ip) {
|
||||
port.host = h;
|
||||
if(h.ports === null || h.ports === undefined) {
|
||||
h.ports = new Array();
|
||||
}
|
||||
h.ports.push(port);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
// discoveryData: action.payload,
|
||||
hostList: hostList,
|
||||
};
|
||||
},
|
||||
[IngActionTypes.RECEIVE_SERVICE]: (state: ServiceState = serviceDefaultState,
|
||||
action: Action<Service>): ServiceState => {
|
||||
[IngActionTypes.RECEIVE_SERVICE]: (state: DiscoveryIngState = DiscoveryIngDefaultState,
|
||||
action: Action<Service>): DiscoveryIngState => {
|
||||
|
||||
|
||||
|
||||
return {
|
||||
...state,
|
||||
// discoveryData: action.payload,
|
||||
// service: action.payload,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
|
|
@ -3,6 +3,17 @@ import Host from '../../api/model/Host';
|
|||
import Port from '../../api/model/Port';
|
||||
import Service from '../../api/model/Service';
|
||||
|
||||
export interface DiscoveryIngState {
|
||||
readonly hostList: Host[];
|
||||
readonly error?: Error;
|
||||
}
|
||||
|
||||
export const DiscoveryIngDefaultState: DiscoveryIngState = {
|
||||
hostList: undefined,
|
||||
error: undefined,
|
||||
};
|
||||
|
||||
|
||||
export interface HostState {
|
||||
readonly host: Host;
|
||||
readonly error?: Error;
|
||||
|
|
Loading…
Reference in New Issue
Block a user