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