discovery result - create target

This commit is contained in:
snoop 2017-08-22 19:21:59 +09:00
parent b2fb18cd26
commit 11c538ff8b
11 changed files with 116 additions and 22 deletions

View File

@ -0,0 +1,11 @@
interface DiscoveryStartInfo {
startIp: string;
endIP: string;
excludeIp: string;
startPort: string;
endPort: string;
selectedServices: Array<number | string>;
}
export default DiscoveryStartInfo;

View File

@ -6,9 +6,9 @@ import {
} from './components/Discovery'; } from './components/Discovery';
export function mapStateToProps(state: any): DiscoveryStateProps { export function mapStateToProps(state: any, props: any): DiscoveryStateProps {
return { return {
probeId: props.probeId,
}; };
} }

View File

@ -6,15 +6,25 @@ import {
} from './components/DiscoveryTree'; } from './components/DiscoveryTree';
export function mapStateToProps(state: any): DiscoveryTreeStateProps {
return {
import Host from '@overflow/discovery/api/model/Host';
import Probe from '@overflow/probe/api/model/Probe';
import * as InfraTargetRegistAllActionTypes from '../redux/action/infra_target_regist_all';
import * as asyncRequestActions from '@overflow/commons/redux/action/asyncRequest';
export function mapStateToProps(state: any, props: any): DiscoveryTreeStateProps {
return {
probeId: props.probeId,
}; };
} }
export function mapDispatchToProps(dispatch: Dispatch<any>): DiscoveryTreeDispatchProps { export function mapDispatchToProps(dispatch: Dispatch<any>): DiscoveryTreeDispatchProps {
return { return {
onCreateTarget: (hosts: Host[], probe: Probe) => {
dispatch(asyncRequestActions.request('TargetDiscoveryService', 'saveAllTarget',
InfraTargetRegistAllActionTypes.REQUEST, JSON.stringify(hosts), JSON.stringify(probe)));
},
}; };
} }

View File

@ -10,7 +10,10 @@ import { DiscoveryProbe } from './DiscoveryProbe';
import DiscoveryTableContainer from '../DiscoveryTable'; import DiscoveryTableContainer from '../DiscoveryTable';
import DiscoveryTreeContainer from '../DiscoveryTree'; import DiscoveryTreeContainer from '../DiscoveryTree';
import Probe from '@overflow/probe/api/model/Probe';
export interface StateProps { export interface StateProps {
probeId?: Number;
} }
export interface DispatchProps { export interface DispatchProps {
@ -87,7 +90,7 @@ export class Discovery extends React.Component<Props, State> {
<Modal.Header>Discovery</Modal.Header> <Modal.Header>Discovery</Modal.Header>
<Modal.Content > <Modal.Content >
{/*<Checkbox label='IP' />*/} {/*<Checkbox label='IP' />*/}
<DiscoveryTreeContainer /> <DiscoveryTreeContainer probeId={this.props.probeId}/>
</Modal.Content> </Modal.Content>
<Modal.Actions> <Modal.Actions>
<Button onClick={this.handleCancel}> Cancel </Button> <Button onClick={this.handleCancel}> Cancel </Button>

View File

@ -13,6 +13,8 @@ import {
import * as _ from 'lodash'; import * as _ from 'lodash';
import DiscoveryStartInfo from '../../api/model/DiscoveryStartInfo';
export interface StateProps { export interface StateProps {
} }
@ -113,10 +115,11 @@ export class DiscoveryTable extends React.Component<Props, State> {
} }
public discoveryStartHandler(event: React.SyntheticEvent<HTMLButtonElement>, data: ButtonProps): void { public discoveryStartHandler(event: React.SyntheticEvent<HTMLButtonElement>, data: ButtonProps): void {
// Array<number | string>
let discoveryStartInfo: any = { let convert: any = this.selectedServices;
let discoveryStartInfo: DiscoveryStartInfo = {
...this.state, ...this.state,
services: this.selectedServices, services: convert,
}; };
@ -153,7 +156,7 @@ export class DiscoveryTable extends React.Component<Props, State> {
<Table.Cell> <Table.Cell>
<Dropdown placeholder='Service' fluid multiple selection options={this.serviceTemp} <Dropdown placeholder='Service' fluid multiple selection options={this.serviceTemp}
onChange={(event: React.SyntheticEvent<HTMLElement>, data: DropdownProps) => { onChange={(event: React.SyntheticEvent<HTMLElement>, data: DropdownProps) => {
this.selectedServices = data.value; this.selectedServices = data.value;
}} /> }} />
</Table.Cell> </Table.Cell>
</Table.Row> </Table.Row>

View File

@ -18,13 +18,17 @@ import {
import Host from '@overflow/discovery/api/model/Host'; import Host from '@overflow/discovery/api/model/Host';
import Port from '@overflow/discovery/api/model/Port'; import Port from '@overflow/discovery/api/model/Port';
import Service from '@overflow/discovery/api/model/Service'; import Service from '@overflow/discovery/api/model/Service';
import Probe from '@overflow/probe/api/model/Probe';
import * as Utils from '@overflow/commons/util/Utils'; import * as Utils from '@overflow/commons/util/Utils';
export interface DiscoveryTreeStateProps { export interface DiscoveryTreeStateProps {
probeId: number;
} }
export interface DiscoveryTreeDispatchProps { export interface DiscoveryTreeDispatchProps {
onCreateTarget?(hosts: Host[], probe: Probe): void;
} }
export type DiscoveryTreeProps = DiscoveryTreeStateProps & DiscoveryTreeDispatchProps; export type DiscoveryTreeProps = DiscoveryTreeStateProps & DiscoveryTreeDispatchProps;
@ -44,6 +48,7 @@ export class DiscoveryTree extends React.Component<DiscoveryTreeProps, Discovery
private selectedHostState: Map<string, boolean>; private selectedHostState: Map<string, boolean>;
private selectedPortState: Map<string, boolean>; private selectedPortState: Map<string, boolean>;
private selectedServiceState: Map<string, boolean>; private selectedServiceState: Map<string, boolean>;
private discoveryHosts: Array<Host>;
constructor(props: any, context: any) { constructor(props: any, context: any) {
super(props, context); super(props, context);
@ -59,7 +64,7 @@ export class DiscoveryTree extends React.Component<DiscoveryTreeProps, Discovery
this.selectedHostState = new Map; this.selectedHostState = new Map;
this.selectedPortState = new Map; this.selectedPortState = new Map;
this.selectedServiceState = new Map; this.selectedServiceState = new Map;
this.discoveryHosts = hostListJson;
// fs.readFile('../../../../../dh.json', this.handlJSONFile); // fs.readFile('../../../../../dh.json', this.handlJSONFile);
} }
@ -83,10 +88,14 @@ export class DiscoveryTree extends React.Component<DiscoveryTreeProps, Discovery
state[stateKey] = newCheckState; state[stateKey] = newCheckState;
this.setState(state); this.setState(state);
if (checkProps.checked) { // if (checkProps.checked) {
selectedMap[key] = selectedObj; // selectedMap[key] = selectedObj;
} else { // } else {
delete selectedMap[key]; // delete selectedMap[key];
// }
if(stateKey !== 'checkPortState') {
let checkObj: any = selectedObj;
checkObj.target = checkProps.checked;
} }
// if(selectedObj instanceof Host) { // if(selectedObj instanceof Host) {
@ -98,7 +107,7 @@ export class DiscoveryTree extends React.Component<DiscoveryTreeProps, Discovery
let elems: JSX.Element[] = new Array(); let elems: JSX.Element[] = new Array();
let hostList: Host[] = hostListJson; let hostList: Host[] = this.discoveryHosts;
let host: Host; let host: Host;
for (let index: number = 0; index < hostList.length; ++index) { for (let index: number = 0; index < hostList.length; ++index) {
host = hostList[index]; host = hostList[index];
@ -145,7 +154,7 @@ export class DiscoveryTree extends React.Component<DiscoveryTreeProps, Discovery
<List.Header> <Checkbox label={port.portNumber + ' ' + port.portType} checked={this.state.checkHostState[key]} onChange={ <List.Header> <Checkbox label={port.portNumber + ' ' + port.portType} checked={this.state.checkHostState[key]} onChange={
(event: React.FormEvent<HTMLInputElement>, checkProps: CheckboxProps) => { (event: React.FormEvent<HTMLInputElement>, checkProps: CheckboxProps) => {
{ {
this.onCheck(checkProps, this.state.checkHostState, key, 'checkHostState', this.selectedPortState, port); this.onCheck(checkProps, this.state.checkPortState, key, 'checkPortState', this.selectedPortState, port);
} }
}} /></List.Header> }} /></List.Header>
<List.Description style={{ marginLeft: '26px' }}>Port</List.Description> <List.Description style={{ marginLeft: '26px' }}>Port</List.Description>
@ -174,7 +183,7 @@ export class DiscoveryTree extends React.Component<DiscoveryTreeProps, Discovery
checked={this.state.checkHostState[key]} onChange={ checked={this.state.checkHostState[key]} onChange={
(event: React.FormEvent<HTMLInputElement>, checkProps: CheckboxProps) => { (event: React.FormEvent<HTMLInputElement>, checkProps: CheckboxProps) => {
{ {
this.onCheck(checkProps, this.state.checkHostState, key, 'checkHostState', this.selectedServiceState, service); this.onCheck(checkProps, this.state.checkServiceState, key, 'checkServiceState', this.selectedServiceState, service);
} }
}} /></List.Header> }} /></List.Header>
<List.Description style={{ marginLeft: '26px' }}>Service</List.Description> <List.Description style={{ marginLeft: '26px' }}>Service</List.Description>
@ -195,9 +204,10 @@ export class DiscoveryTree extends React.Component<DiscoveryTreeProps, Discovery
{this.renderDiscovery()} {this.renderDiscovery()}
</List> </List>
<Button primary floated='right' onClick={() => { <Button primary floated='right' onClick={() => {
console.log(this.selectedHostState); this.props.onCreateTarget(this.discoveryHosts, {id: this.props.probeId});
{/*console.log(this.selectedHostState);
console.log(this.selectedPortState); console.log(this.selectedPortState);
console.log(this.selectedServiceState); console.log(this.selectedServiceState);*/}
}}>Test</Button><br /><br /> }}>Test</Button><br /><br />
</Container> </Container>
); );

View File

@ -0,0 +1,10 @@
// Action Type
export type REQUEST = '@overflow/discovery/infra_target_regist_all/REQUEST';
export type REQUEST_SUCCESS = '@overflow/discovery/infra_target_regist_all/REQUEST/SUCCESS';
export type REQUEST_FAILURE = '@overflow/discovery/infra_target_regist_all/REQUEST/FAILURE';
export const REQUEST: REQUEST = '@overflow/discovery/infra_target_regist_all/REQUEST';
export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/discovery/infra_target_regist_all/REQUEST/SUCCESS';
export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/discovery/infra_target_regist_all/REQUEST/FAILURE';

View File

@ -0,0 +1,10 @@
import Host from '@overflow/discovery/api/model/Host';
import Probe from '@overflow/probe/api/model/Probe';
interface InfraTargetRegistAllPayload {
hosts: Host[];
probe: Probe;
}
export default InfraTargetRegistAllPayload;

View File

@ -0,0 +1,25 @@
import Action from '@overflow/commons/redux/Action';
import { ReducersMapObject } from 'redux';
import * as InfraTargetRegistAllActionTypes from '../action/infra_target_regist_all';
import InfraTargetRegistAllState, { defaultState as infraTargetRegistAllDefaultState } from '../state/InfraTargetRegistAll';
const reducer: ReducersMapObject = {
[InfraTargetRegistAllActionTypes.REQUEST_SUCCESS]: (state: InfraTargetRegistAllState = infraTargetRegistAllDefaultState,
action: Action<void>): InfraTargetRegistAllState => {
return {
...state,
isSuccess: true,
};
},
[InfraTargetRegistAllActionTypes.REQUEST_FAILURE]: (state: InfraTargetRegistAllState = infraTargetRegistAllDefaultState,
action: Action<Error>): InfraTargetRegistAllState => {
return {
...state,
error: action.error,
};
},
};
export default reducer;

View File

@ -0,0 +1,12 @@
export interface State {
readonly isSuccess: boolean;
readonly error?: Error;
}
export const defaultState: State = {
isSuccess: undefined,
error: undefined,
};
export default State;

View File

@ -5,7 +5,7 @@ import Infra from '@overflow/infra/api/model/Infra';
import Probe from '@overflow/probe/api/model/Probe'; import Probe from '@overflow/probe/api/model/Probe';
import Domain from '@overflow/domain/api/model/Domain'; import Domain from '@overflow/domain/api/model/Domain';
import { ListContainer } from '@overflow/commons/react/component/ListContainer'; import { ListContainer } from '@overflow/commons/react/component/ListContainer';
import { Discovery } from '../../../discovery/react/components/Discovery'; import DiscoveryContainer from '../../../discovery/react/Discovery';
import * as Utils from '@overflow/commons/util/Utils'; import * as Utils from '@overflow/commons/util/Utils';
@ -133,7 +133,7 @@ export class TargetList extends React.Component<Props, State> {
{/*Adding a Target*/} {/*Adding a Target*/}
{/*</Modal.Header>*/} {/*</Modal.Header>*/}
<Modal.Content> <Modal.Content>
<Discovery /> <DiscoveryContainer probeId={Number(this.props.probeId)}/>
</Modal.Content> </Modal.Content>
<Modal.Actions> <Modal.Actions>
<Button onClick={() => this.setState({ openAddTarget: false })}>Cancel</Button> <Button onClick={() => this.setState({ openAddTarget: false })}>Cancel</Button>