From bd1748ab7df788b0545fcc67cdd7969d39c04733 Mon Sep 17 00:00:00 2001 From: insanity Date: Fri, 11 Aug 2017 12:23:22 +0900 Subject: [PATCH] target --- src/ts/@overflow/app/config/index.ts | 3 + .../app/views/infrastructure/target/List.tsx | 2 +- src/ts/@overflow/probe/react/ProbeDetail.tsx | 1 + src/ts/@overflow/probe/react/ProbeHost.tsx | 8 +- .../probe/react/components/ProbeHost.tsx | 47 ++--------- .../probe/redux/reducer/readAllByDomain.ts | 10 +-- src/ts/@overflow/target/react/TargetList.tsx | 9 +- .../target/react/components/TargetList.tsx | 82 ++++++++----------- .../target/redux/action/read_all_by_probe.ts | 42 +--------- .../target/redux/reducer/readAllByProbe.ts | 24 ++++++ .../target/redux/reducer/read_by_probe.ts | 0 .../target/redux/state/ReadAllByProbe.ts | 13 +++ .../target/redux/state/ReadByProbe.ts | 0 13 files changed, 103 insertions(+), 138 deletions(-) create mode 100644 src/ts/@overflow/target/redux/reducer/readAllByProbe.ts delete mode 100644 src/ts/@overflow/target/redux/reducer/read_by_probe.ts create mode 100644 src/ts/@overflow/target/redux/state/ReadAllByProbe.ts delete mode 100644 src/ts/@overflow/target/redux/state/ReadByProbe.ts diff --git a/src/ts/@overflow/app/config/index.ts b/src/ts/@overflow/app/config/index.ts index 24cb44a..dda9a62 100644 --- a/src/ts/@overflow/app/config/index.ts +++ b/src/ts/@overflow/app/config/index.ts @@ -6,11 +6,13 @@ import signUpReducer from '@overflow/member/redux/reducer/signUp'; import readAllProbeReducer from '@overflow/probe/redux/reducer/readAllByDomain'; import readProbeReducer from '@overflow/probe/redux/reducer/read'; +import readAllTargetByProbeReducer from '@overflow/target/redux/reducer/readAllByProbe'; import readAllByTargetReducer from '@overflow/sensor/redux/reducer/read_all_by_target'; import SensorReadReducer from '@overflow/sensor/redux/reducer/read'; import SensorItemReadAllBySensorReducer from '@overflow/sensor/redux/reducer/item_read_all_by_sensor'; + import AsyncRequest from '@overflow/app/redux/saga/AsyncRequest'; // Container Configuration @@ -52,6 +54,7 @@ const reduxConfig: ReduxConfig = { SensorReadReducer, signUpReducer, SensorItemReadAllBySensorReducer, + readAllTargetByProbeReducer, ], sagaWatchers: [ AsyncRequest, diff --git a/src/ts/@overflow/app/views/infrastructure/target/List.tsx b/src/ts/@overflow/app/views/infrastructure/target/List.tsx index 0c24580..113d6fc 100644 --- a/src/ts/@overflow/app/views/infrastructure/target/List.tsx +++ b/src/ts/@overflow/app/views/infrastructure/target/List.tsx @@ -10,7 +10,7 @@ class TargetList extends React.Component, object> { public render(): JSX.Element { return ( - + ); } } diff --git a/src/ts/@overflow/probe/react/ProbeDetail.tsx b/src/ts/@overflow/probe/react/ProbeDetail.tsx index 91a67c0..e47d287 100644 --- a/src/ts/@overflow/probe/react/ProbeDetail.tsx +++ b/src/ts/@overflow/probe/react/ProbeDetail.tsx @@ -28,3 +28,4 @@ export function mapDispatchToProps(dispatch: Dispatch): ProbeDetailDispatch } export default connect(mapStateToProps, mapDispatchToProps)(ProbeDetailInfo); + diff --git a/src/ts/@overflow/probe/react/ProbeHost.tsx b/src/ts/@overflow/probe/react/ProbeHost.tsx index 845704e..6434a1e 100644 --- a/src/ts/@overflow/probe/react/ProbeHost.tsx +++ b/src/ts/@overflow/probe/react/ProbeHost.tsx @@ -5,16 +5,22 @@ import { DispatchProps as ProbeDetailDispatchProps, } from './components/ProbeHost'; import { push as routerPush } from 'react-router-redux'; - +import Probe from '@overflow/probe/api/model/Probe'; +import * as probeReadActions from '../redux/action/read'; +import * as asyncRequestActions from '@overflow/commons/redux/action/asyncRequest'; export function mapStateToProps(state: any, props: any): ProbeDetailStateProps { return { id: props.params.id, + probe: state.probe, }; } export function mapDispatchToProps(dispatch: Dispatch): ProbeDetailDispatchProps { return { + onRead: (id: string) => { + dispatch(asyncRequestActions.request('ProbeService', 'read', probeReadActions.REQUEST, id)); + }, }; } diff --git a/src/ts/@overflow/probe/react/components/ProbeHost.tsx b/src/ts/@overflow/probe/react/components/ProbeHost.tsx index 0c87238..b145615 100644 --- a/src/ts/@overflow/probe/react/components/ProbeHost.tsx +++ b/src/ts/@overflow/probe/react/components/ProbeHost.tsx @@ -12,15 +12,16 @@ import InfraHost from '@overflow/infra/api/model/InfraHost'; export interface StateProps { id: string; + probe: Probe; } export interface DispatchProps { + onRead?(id: string): void; } export type Props = StateProps & DispatchProps; export interface State { - host: InfraHost; } @@ -34,39 +35,7 @@ export class ProbeHost extends React.Component { } public componentWillMount(): void { - - // todo. getting probe by probeId - let p: any = { - 'id': '11', - 'status': { - 'name': 'STARTED', - }, - 'domain': { - 'name': 'insanity\'s domain', - }, - 'host': { - 'id': 111, - 'os': { - 'machine': { - 'meta': 'machine meta', - }, - 'meta': 'os meta', - 'vendor': { - 'name': 'vendor name', - 'infraType': { - 'name': 'vendor type name', - }, - }, - }, - 'ip': 3232235881, - 'mac': 8796753988883, - 'createDate': null, - }, - }; - - this.setState({ - host: p.host, - }); + this.props.onRead(this.props.id); } @@ -79,31 +48,31 @@ export class ProbeHost extends React.Component {
IP
- {this.state.host.ip} + {this.props.probe.host.ip}
MAC
- {this.state.host.mac} + {this.props.probe.host.mac}
OS meta
- {this.state.host.os.meta} + {this.props.probe.host.os.meta}
OS vendor name
- {this.state.host.os.vendor.name} + {this.props.probe.host.os.vendor.name}
OS vendor type
- {this.state.host.os.vendor.infraType.name} + {this.props.probe.host.os.vendor.infraType.name}
diff --git a/src/ts/@overflow/probe/redux/reducer/readAllByDomain.ts b/src/ts/@overflow/probe/redux/reducer/readAllByDomain.ts index 5cfa0e0..12c26eb 100644 --- a/src/ts/@overflow/probe/redux/reducer/readAllByDomain.ts +++ b/src/ts/@overflow/probe/redux/reducer/readAllByDomain.ts @@ -3,20 +3,20 @@ import { ReducersMapObject } from 'redux'; import Probe from '@overflow/probe/api/model/Probe'; import * as ReadAllByDomainActionTypes from '../action/read_all_by_domain'; -import ReadAllProbeByDomainState, { defaultState as readAllProbeByDomainDefaultState } from '../state/ReadAllByDomain'; +import ReadAllByDomainState, { defaultState as ReadAllByDomainDefaultState } from '../state/ReadAllByDomain'; const reducer: ReducersMapObject = { [ReadAllByDomainActionTypes.REQUEST_SUCCESS]: - (state: ReadAllProbeByDomainState = readAllProbeByDomainDefaultState, action: Action): - ReadAllProbeByDomainState => { + (state: ReadAllByDomainState = ReadAllByDomainDefaultState, action: Action): + ReadAllByDomainState => { return { ...state, probeList: action.payload, }; }, [ReadAllByDomainActionTypes.REQUEST_FAILURE]: - (state: ReadAllProbeByDomainState = readAllProbeByDomainDefaultState, action: Action): - ReadAllProbeByDomainState => { + (state: ReadAllByDomainState = ReadAllByDomainDefaultState, action: Action): + ReadAllByDomainState => { return state; }, }; diff --git a/src/ts/@overflow/target/react/TargetList.tsx b/src/ts/@overflow/target/react/TargetList.tsx index e143fb8..1a4cc87 100644 --- a/src/ts/@overflow/target/react/TargetList.tsx +++ b/src/ts/@overflow/target/react/TargetList.tsx @@ -8,18 +8,19 @@ import { import Probe from '@overflow/probe/api/model/Probe'; import * as targetListActions from '../redux/action/read_all_by_probe'; import { push as routerPush } from 'react-router-redux'; +import * as asyncRequestActions from '@overflow/commons/redux/action/asyncRequest'; - -export function mapStateToProps(state: any): StateProps { +export function mapStateToProps(state: any, props: any): StateProps { return { - + probeId: props.params.id, + targetList: state.targetList, }; } export function mapDispatchToProps(dispatch: Dispatch): DispatchProps { return { onReadAllByProbe: (probe: Probe) => { - dispatch(targetListActions.request(probe)); + dispatch(asyncRequestActions.request('InfraService', 'readAllByProbe', targetListActions.REQUEST, JSON.stringify(probe))); }, onTargetSelection: (id: string) => { dispatch(routerPush('/target/' + id)); diff --git a/src/ts/@overflow/target/react/components/TargetList.tsx b/src/ts/@overflow/target/react/components/TargetList.tsx index db74f64..02e4ea5 100644 --- a/src/ts/@overflow/target/react/components/TargetList.tsx +++ b/src/ts/@overflow/target/react/components/TargetList.tsx @@ -7,7 +7,8 @@ import { ListContainer } from '@overflow/commons/react/component/ListContainer'; import { Discovery } from '../../../discovery/react/components/Discovery'; export interface StateProps { - + probeId: string; + targetList: Target[]; } export interface DispatchProps { @@ -20,47 +21,23 @@ export type Props = StateProps & DispatchProps; export interface State { selected: Target; openAddTarget: boolean; - list: Target[]; } export class TargetList extends React.Component { - private data: any; constructor(props: Props, context: State) { super(props, context); this.state = { selected: null, openAddTarget: false, - list: null, }; } public componentWillMount(): void { - this.data = [ - { - 'id': '1', - 'createDate': '2017-01-01', - 'displayName': 'Oracle', - 'description': '', - 'sensorCount': 'todo.', - }, - { - 'id': '2', - 'createDate': '2017-01-01', - 'displayName': 'MySQL', - 'description': '', - 'sensorCount': 'todo.', - }, - { - 'id': '3', - 'createDate': '2017-01-01', - 'displayName': '192.168.1.105', - 'description': '', - 'sensorCount': 'todo.', - }, - ]; - - this.setState({ list: this.data }); + const probe: Probe = { + id: 1, + }; + this.props.onReadAllByProbe(probe); } public handleSelect(selectedTarget: any): void { @@ -80,30 +57,33 @@ export class TargetList extends React.Component { } public handleSearch(result: Target[]): void { - this.setState({ - list: result, - }); + // this.setState({ + // list: result, + // }); } public handleFilter(filterStr: string): void { - if (filterStr === null) { - this.setState({ - list: this.data, - }); - return; - } - let founds = new Array(); - for (let probe of this.data) { - if (probe.metaProbeStatus.name.indexOf(filterStr) !== -1) { - founds.push(probe); - } - } - this.setState({ - list: founds, - }); + // if (filterStr === null) { + // this.setState({ + // list: this.data, + // }); + // return; + // } + // let founds = new Array(); + // for (let probe of this.data) { + // if (probe.metaProbeStatus.name.indexOf(filterStr) !== -1) { + // founds.push(probe); + // } + // } + // this.setState({ + // list: founds, + // }); } public render(): JSX.Element { + if(this.props.targetList === undefined) { + return null; + } let targetList = {/*search bar */} @@ -113,6 +93,7 @@ export class TargetList extends React.Component { No + Type Name Sensor Count Created at @@ -120,11 +101,12 @@ export class TargetList extends React.Component { - {this.state.list.map((target: any, index: number) => ( + {this.props.targetList.map((target: any, index: number) => ( {index + 1} - {target.displayName} - {target.sensorCount} + {target.infraType.name} + {target.target.displayName} + TODO {target.createDate} ))} diff --git a/src/ts/@overflow/target/redux/action/read_all_by_probe.ts b/src/ts/@overflow/target/redux/action/read_all_by_probe.ts index 9ca5b4a..dadd0ef 100644 --- a/src/ts/@overflow/target/redux/action/read_all_by_probe.ts +++ b/src/ts/@overflow/target/redux/action/read_all_by_probe.ts @@ -1,43 +1,9 @@ -import Action from '@overflow/commons/redux/Action'; -import Target from '../../api/model/Target'; -import Probe from '@overflow/probe/api/model/Probe'; -import ReadAllByProbePayload from '../payload/ReadAllByProbePayload'; - // Action Type export type REQUEST = '@overflow/target/read_all_by_probe/REQUEST'; -export type REQUEST_SUCCESS = '@overflow/target/read_all_by_probe/REQUEST_SUCCESS'; -export type REQUEST_FAILURE = '@overflow/target/read_all_by_probe/REQUEST_FAILURE'; +export type REQUEST_SUCCESS = '@overflow/target/read_all_by_probe/REQUEST/SUCCESS'; +export type REQUEST_FAILURE = '@overflow/target/read_all_by_probe/REQUEST/FAILURE'; export const REQUEST: REQUEST = '@overflow/target/read_all_by_probe/REQUEST'; -export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/target/read_all_by_probe/REQUEST_SUCCESS'; -export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/target/read_all_by_probe/REQUEST_FAILURE'; +export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/target/read_all_by_probe/REQUEST/SUCCESS'; +export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/target/read_all_by_probe/REQUEST/FAILURE'; -// Action Creater -export type request = (probe: Probe) => Action; -export type requestSuccess = (targets: Target[]) => Action; -export type requestFailure = (error: Error) => Action; - - - -export const request: request = (probe: Probe): Action => { - return { - type: REQUEST, - payload: { - probe: probe, - }, - }; -}; - -export const requestSuccess: requestSuccess = (targets: Target[]): Action => { - return { - type: REQUEST_SUCCESS, - payload: targets, - }; -}; - -export const requestFailure: requestFailure = (error: Error): Action => { - return { - type: REQUEST_FAILURE, - error: error, - }; -}; diff --git a/src/ts/@overflow/target/redux/reducer/readAllByProbe.ts b/src/ts/@overflow/target/redux/reducer/readAllByProbe.ts new file mode 100644 index 0000000..76c3d96 --- /dev/null +++ b/src/ts/@overflow/target/redux/reducer/readAllByProbe.ts @@ -0,0 +1,24 @@ +import Action from '@overflow/commons/redux/Action'; +import { ReducersMapObject } from 'redux'; +import Target from '@overflow/target/api/model/Target'; + +import * as ReadAllByProbeActionTypes from '../action/read_all_by_probe'; +import ReadAllByProbeState, { defaultState as ReadAllByProbeDefaultState } from '../state/ReadAllByProbe'; + +const reducer: ReducersMapObject = { + [ReadAllByProbeActionTypes.REQUEST_SUCCESS]: + (state: ReadAllByProbeState = ReadAllByProbeDefaultState, action: Action): + ReadAllByProbeState => { + return { + ...state, + targetList: action.payload, + }; + }, + [ReadAllByProbeActionTypes.REQUEST_FAILURE]: + (state: ReadAllByProbeState = ReadAllByProbeDefaultState, action: Action): + ReadAllByProbeState => { + return state; + }, +}; + +export default reducer; diff --git a/src/ts/@overflow/target/redux/reducer/read_by_probe.ts b/src/ts/@overflow/target/redux/reducer/read_by_probe.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/ts/@overflow/target/redux/state/ReadAllByProbe.ts b/src/ts/@overflow/target/redux/state/ReadAllByProbe.ts new file mode 100644 index 0000000..34481f1 --- /dev/null +++ b/src/ts/@overflow/target/redux/state/ReadAllByProbe.ts @@ -0,0 +1,13 @@ +import Target from '../../api/model/Target'; + +export interface State { + readonly targetList?: Target[]; + readonly error?: Error; +} + +export const defaultState: State = { + targetList: undefined, + error: undefined, +}; + +export default State; diff --git a/src/ts/@overflow/target/redux/state/ReadByProbe.ts b/src/ts/@overflow/target/redux/state/ReadByProbe.ts deleted file mode 100644 index e69de29..0000000