From 6a38cd64ea7bd3dd7e172dff4d4d3d92d3bb1442 Mon Sep 17 00:00:00 2001 From: snoop Date: Mon, 14 Aug 2017 17:56:27 +0900 Subject: [PATCH] target list from domain --- src/ts/@overflow/app/config/index.ts | 2 ++ .../infra/react/components/InfraDetail.tsx | 4 +-- src/ts/@overflow/target/react/TargetList.tsx | 4 +++ .../target/react/components/TargetList.tsx | 33 +++++++++++++------ .../target/redux/action/read_all_by_domain.ts | 9 +++++ .../redux/payload/ReadAllByDomainPayload.ts | 7 ++++ .../redux/reducer/read_all_by_domain.ts | 24 ++++++++++++++ .../target/redux/state/ReadAllByDomain.ts | 13 ++++++++ 8 files changed, 84 insertions(+), 12 deletions(-) create mode 100644 src/ts/@overflow/target/redux/action/read_all_by_domain.ts create mode 100644 src/ts/@overflow/target/redux/payload/ReadAllByDomainPayload.ts create mode 100644 src/ts/@overflow/target/redux/reducer/read_all_by_domain.ts create mode 100644 src/ts/@overflow/target/redux/state/ReadAllByDomain.ts diff --git a/src/ts/@overflow/app/config/index.ts b/src/ts/@overflow/app/config/index.ts index ec63898..e9e491e 100644 --- a/src/ts/@overflow/app/config/index.ts +++ b/src/ts/@overflow/app/config/index.ts @@ -10,6 +10,7 @@ import readProbeReducer from '@overflow/probe/redux/reducer/read'; import readNoAuthProbeReducer from '@overflow/noauthprobe/redux/reducer/read_all_by_domain'; import readAllTargetByProbeReducer from '@overflow/target/redux/reducer/readAllByProbe'; +import readAllTargetByDomainReducer from '@overflow/target/redux/reducer/read_all_by_domain'; import readTargetReducer from '@overflow/target/redux/reducer/read'; import sensorReadAllByTargetReducer from '@overflow/sensor/redux/reducer/read_all_by_target'; @@ -66,6 +67,7 @@ const reduxConfig: ReduxConfig = { signUpReducer, SensorItemReadAllBySensorReducer, readAllTargetByProbeReducer, + readAllTargetByDomainReducer, readTargetReducer, readNoAuthProbeReducer, readMachineReducer, diff --git a/src/ts/@overflow/infra/react/components/InfraDetail.tsx b/src/ts/@overflow/infra/react/components/InfraDetail.tsx index 07b6289..d9bbbce 100644 --- a/src/ts/@overflow/infra/react/components/InfraDetail.tsx +++ b/src/ts/@overflow/infra/react/components/InfraDetail.tsx @@ -153,11 +153,11 @@ export class InfraDetail extends React.Component { NewTableDatas = [{ header: 'IP', - contents: infraChild.ip, + contents: Utils.int2ip(infraChild.ip), }, { header: 'MAC', - contents: infraChild.mac, + contents: Utils.intToMac(infraChild.mac), }, ]; diff --git a/src/ts/@overflow/target/react/TargetList.tsx b/src/ts/@overflow/target/react/TargetList.tsx index ea38d5b..b365901 100644 --- a/src/ts/@overflow/target/react/TargetList.tsx +++ b/src/ts/@overflow/target/react/TargetList.tsx @@ -6,6 +6,7 @@ import { } from './components/TargetList'; import Probe from '@overflow/probe/api/model/Probe'; +import Domain from '@overflow/domain/api/model/Domain'; 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'; @@ -22,6 +23,9 @@ export function mapDispatchToProps(dispatch: Dispatch): DispatchProps { onReadAllByProbe: (probe: Probe) => { dispatch(asyncRequestActions.request('InfraService', 'readAllByProbe', targetListActions.REQUEST, JSON.stringify(probe))); }, + onReadAllByDomain: (domain: Domain) => { + dispatch(asyncRequestActions.request('InfraService', 'readAllByDomain', targetListActions.REQUEST, JSON.stringify(domain))); + }, 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 936e659..826ed44 100644 --- a/src/ts/@overflow/target/react/components/TargetList.tsx +++ b/src/ts/@overflow/target/react/components/TargetList.tsx @@ -3,17 +3,19 @@ import { Table, Button, Modal, Input, Header, Container, InputOnChangeData, Butt import { TargetDetail } from './TargetDetail'; import Infra from '@overflow/infra/api/model/Infra'; import Probe from '@overflow/probe/api/model/Probe'; +import Domain from '@overflow/domain/api/model/Domain'; import { ListContainer } from '@overflow/commons/react/component/ListContainer'; import { Discovery } from '../../../discovery/react/components/Discovery'; export interface StateProps { - probeId: string; - infraList: Infra[]; + probeId?: string; + infraList?: Infra[]; } export interface DispatchProps { - onReadAllByProbe(probe: Probe): void; - onTargetSelection(id: string): void; + onReadAllByProbe?(probe: Probe): void; + onReadAllByDomain?(domain: Domain): void; + onTargetSelection?(id: string): void; } export type Props = StateProps & DispatchProps; @@ -34,10 +36,21 @@ export class TargetList extends React.Component { } public componentWillMount(): void { - let probe: Probe = { - id: Number(1), - }; - this.props.onReadAllByProbe(probe); + + if (this.props.probeId === undefined) { + // FIXME: get domain + let domain: Domain = { + id: 1, + }; + this.props.onReadAllByDomain(domain); + } else { + let probe: Probe = { + id: Number(this.props.probeId), + }; + this.props.onReadAllByProbe(probe); + } + + } public handleSelect(selectedTarget: any): void { @@ -81,7 +94,7 @@ export class TargetList extends React.Component { } public render(): JSX.Element { - if(this.props.infraList === undefined) { + if (this.props.infraList === undefined) { return null; } let targetList = @@ -103,7 +116,7 @@ export class TargetList extends React.Component { {this.props.infraList.map((infra: Infra, index: number) => ( {index + 1} - {infra.infraType.name} + {infra.infraType.name} {infra.target.displayName} TODO {infra.target.createDate} diff --git a/src/ts/@overflow/target/redux/action/read_all_by_domain.ts b/src/ts/@overflow/target/redux/action/read_all_by_domain.ts new file mode 100644 index 0000000..338c3a5 --- /dev/null +++ b/src/ts/@overflow/target/redux/action/read_all_by_domain.ts @@ -0,0 +1,9 @@ +// Action Type +export type REQUEST = '@overflow/target/read_all_by_domain/REQUEST'; +export type REQUEST_SUCCESS = '@overflow/target/read_all_by_domain/REQUEST/SUCCESS'; +export type REQUEST_FAILURE = '@overflow/target/read_all_by_domain/REQUEST/FAILURE'; + +export const REQUEST: REQUEST = '@overflow/target/read_all_by_domain/REQUEST'; +export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/target/read_all_by_domain/REQUEST/SUCCESS'; +export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/target/read_all_by_domain/REQUEST/FAILURE'; + diff --git a/src/ts/@overflow/target/redux/payload/ReadAllByDomainPayload.ts b/src/ts/@overflow/target/redux/payload/ReadAllByDomainPayload.ts new file mode 100644 index 0000000..8b7d1e6 --- /dev/null +++ b/src/ts/@overflow/target/redux/payload/ReadAllByDomainPayload.ts @@ -0,0 +1,7 @@ +import Domain from '@overflow/domain/api/model/Domain'; + +interface ReadAllByDomainPayload { + probe: Domain; +} + +export default ReadAllByDomainPayload; diff --git a/src/ts/@overflow/target/redux/reducer/read_all_by_domain.ts b/src/ts/@overflow/target/redux/reducer/read_all_by_domain.ts new file mode 100644 index 0000000..14ca6c6 --- /dev/null +++ b/src/ts/@overflow/target/redux/reducer/read_all_by_domain.ts @@ -0,0 +1,24 @@ +import Action from '@overflow/commons/redux/Action'; +import { ReducersMapObject } from 'redux'; +import Infra from '@overflow/infra/api/model/Infra'; + +import * as ReadAllByDomainActionTypes from '../action/read_all_by_domain'; +import ReadAllByDomainState, { defaultState as ReadAllByDomainDefaultState } from '../state/ReadAllByDomain'; + +const reducer: ReducersMapObject = { + [ReadAllByDomainActionTypes.REQUEST_SUCCESS]: + (state: ReadAllByDomainState = ReadAllByDomainDefaultState, action: Action): + ReadAllByDomainState => { + return { + ...state, + infraList: action.payload, + }; + }, + [ReadAllByDomainActionTypes.REQUEST_FAILURE]: + (state: ReadAllByDomainState = ReadAllByDomainDefaultState, action: Action): + ReadAllByDomainState => { + return state; + }, +}; + +export default reducer; diff --git a/src/ts/@overflow/target/redux/state/ReadAllByDomain.ts b/src/ts/@overflow/target/redux/state/ReadAllByDomain.ts new file mode 100644 index 0000000..7785b1e --- /dev/null +++ b/src/ts/@overflow/target/redux/state/ReadAllByDomain.ts @@ -0,0 +1,13 @@ +import Infra from '@overflow/infra/api/model/Infra'; + +export interface State { + readonly infraList?: Infra[]; + readonly error?: Error; +} + +export const defaultState: State = { + infraList: undefined, + error: undefined, +}; + +export default State;