From 3fc7439a6048c8f4001181644385046353686bf9 Mon Sep 17 00:00:00 2001 From: geek Date: Fri, 11 Aug 2017 15:09:00 +0900 Subject: [PATCH] noauthProbe --- src/ts/@overflow/app/config/index.ts | 4 + .../noauthprobe/react/NoauthProbeList.tsx | 16 +- .../react/components/NoauthProbeList.tsx | 180 ++++++++++-------- .../redux/action/read_all_by_domain.ts | 48 +---- .../redux/reducer/read_all_by_domain.ts | 24 +++ .../redux/state/ReadAllByDomain.ts | 13 ++ 6 files changed, 155 insertions(+), 130 deletions(-) diff --git a/src/ts/@overflow/app/config/index.ts b/src/ts/@overflow/app/config/index.ts index 22b9edb..c9b1154 100644 --- a/src/ts/@overflow/app/config/index.ts +++ b/src/ts/@overflow/app/config/index.ts @@ -6,6 +6,9 @@ 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 readNoAuthProbeReducer from '@overflow/noauthprobe/redux/reducer/read_all_by_domain'; + import readAllTargetByProbeReducer from '@overflow/target/redux/reducer/readAllByProbe'; import readTargetReducer from '@overflow/target/redux/reducer/read'; @@ -57,6 +60,7 @@ const reduxConfig: ReduxConfig = { SensorItemReadAllBySensorReducer, readAllTargetByProbeReducer, readTargetReducer, + readNoAuthProbeReducer, ], sagaWatchers: [ AsyncRequest, diff --git a/src/ts/@overflow/noauthprobe/react/NoauthProbeList.tsx b/src/ts/@overflow/noauthprobe/react/NoauthProbeList.tsx index 46ca802..c094cc8 100644 --- a/src/ts/@overflow/noauthprobe/react/NoauthProbeList.tsx +++ b/src/ts/@overflow/noauthprobe/react/NoauthProbeList.tsx @@ -1,20 +1,24 @@ import { connect, Dispatch } from 'react-redux'; import { NoauthProbeList, - StateProps as ProbeListStateProps, - DispatchProps as ProbeListDispatchProps, + StateProps as NoAuthProbeListStateProps, + DispatchProps as NoAuthProbeListDispatchProps, } from './components/NoauthProbeList'; import Domain from '@overflow/domain/api/model/Domain'; +import * as asyncRequestActions from '@overflow/commons/redux/action/asyncRequest'; +import * as noauthListActions from '../redux/action/read_all_by_domain'; - -export function mapStateToProps(state: any): ProbeListStateProps { +export function mapStateToProps(state: any): NoAuthProbeListStateProps { return { - + noauthList: state.noauthList, }; } -export function mapDispatchToProps(dispatch: Dispatch): ProbeListDispatchProps { +export function mapDispatchToProps(dispatch: Dispatch): NoAuthProbeListDispatchProps { return { + onReadAllByDomain: (domain: Domain) => { + dispatch(asyncRequestActions.request('NoAuthProbeService', 'readAllByDomain', noauthListActions.REQUEST, JSON.stringify(domain))); + }, }; } diff --git a/src/ts/@overflow/noauthprobe/react/components/NoauthProbeList.tsx b/src/ts/@overflow/noauthprobe/react/components/NoauthProbeList.tsx index b8c93c9..5e9f54c 100644 --- a/src/ts/@overflow/noauthprobe/react/components/NoauthProbeList.tsx +++ b/src/ts/@overflow/noauthprobe/react/components/NoauthProbeList.tsx @@ -11,9 +11,11 @@ import Domain from '@overflow/domain/api/model/Domain'; import { ListContainer } from '@overflow/commons/react/component/ListContainer'; export interface StateProps { + noauthList?: NoAuthProbe[]; } export interface DispatchProps { + onReadAllByDomain?(domain: Domain):void; } export type Props = StateProps & DispatchProps; @@ -23,10 +25,10 @@ export interface State { list: NoAuthProbe[]; } -export class NoauthProbeList extends React.Component { +export class NoauthProbeList extends React.Component { private data: any; - private selectedIds: Array; + private selectedIds: NoAuthProbe[]; constructor(props: Props, context: State) { super(props, context); @@ -38,68 +40,16 @@ export class NoauthProbeList extends React.Component { } public componentWillMount(): void { - this.data = [ - { - 'id': '11', - 'MetaNoAuthProbeStatus': { - 'name': 'PROCESS', - }, - 'hostName': 'insanity windows', - 'macAddress': '14:fe:b5:9d:54:7e', - 'ipAddress': '192.168.1.105', - 'tempProbeKey': '45374d4egsdfw332', - 'apiKey': '45374d4egsdfw332', - 'domain': { - - }, - 'probe': { - - }, - }, - { - 'id': '22', - 'MetaNoAuthProbeStatus': { - 'name': 'PROCESS', - }, - 'hostName': 'insanity ubuntu', - 'macAddress': '14:fe:b5:9d:54:7e', - 'ipAddress': '192.168.1.105', - 'tempProbeKey': '45374d4egsdfw332', - 'apiKey': '45374d4egsdfw332', - 'domain': { - - }, - 'probe': { - - }, - }, - { - 'id': '33', - 'MetaNoAuthProbeStatus': { - 'name': 'PROCESS', - }, - 'hostName': 'insanity ubuntu', - 'macAddress': '14:fe:b5:9d:54:7e', - 'ipAddress': '192.168.1.105', - 'tempProbeKey': '45374d4egsdfw332', - 'apiKey': '45374d4egsdfw332', - 'domain': { - - }, - 'probe': { - - }, - }, - ]; - this.setState({ - list: this.data, - }); + let domain: Domain = { + id:1, + }; + this.props.onReadAllByDomain(domain); } - public handleSelect(id: string): void { - let idx = this.selectedIds.indexOf(id); + public handleSelect(probe: NoAuthProbe): void { + let idx = this.selectedIds.indexOf(probe); if (idx === -1) { - this.selectedIds.push(id); + this.selectedIds.push(probe); } else { this.selectedIds.splice(idx, 1); } @@ -114,10 +64,10 @@ export class NoauthProbeList extends React.Component { }); } - public checkExist(id: string): boolean { - if (this.state.selected.indexOf(id) === -1) { - return false; - } + public checkExist(probe: NoAuthProbe): boolean { + // if (this.state.selected.indexOf(id) === -1) { + // return false; + // } return true; } @@ -129,8 +79,8 @@ export class NoauthProbeList extends React.Component { alert(this.state.selected); } - public handleRowActive(id: string): boolean { - if (this.state.selected.indexOf(id) === -1) { + public handleRowActive(probe: NoAuthProbe): boolean { + if (this.state.selected.indexOf(probe) === -1) { return false; } return true; @@ -153,19 +103,7 @@ export class NoauthProbeList extends React.Component { - {this.state.list.map((probe: any, index: number) => ( - - - - - {index + 1} - {probe.ipAddress} - {probe.macAddress} - {probe.hostName} - - {probe.apiKey} - - ))} + {this.renderRows()} @@ -174,13 +112,91 @@ export class NoauthProbeList extends React.Component { return ( ); } + + private renderRows(): (JSX.Element | JSX.Element[]) { + if (this.props.noauthList === undefined) { + return null; + } + + if (this.props.noauthList.length === 0) { + return + No results found. + ; + } + + return this.props.noauthList.map((probe: NoAuthProbe, index: number) => ( + + + + + {index + 1} + {probe.ipAddress} + {probe.macAddress} + {probe.hostName} + + {probe.apiKey} + + )); + } } - +// this.data = [ +// { +// 'id': '11', +// 'MetaNoAuthProbeStatus': { +// 'name': 'PROCESS', +// }, +// 'hostName': 'insanity windows', +// 'macAddress': '14:fe:b5:9d:54:7e', +// 'ipAddress': '192.168.1.105', +// 'tempProbeKey': '45374d4egsdfw332', +// 'apiKey': '45374d4egsdfw332', +// 'domain': { +// +// }, +// 'probe': { +// +// }, +// }, +// { +// 'id': '22', +// 'MetaNoAuthProbeStatus': { +// 'name': 'PROCESS', +// }, +// 'hostName': 'insanity ubuntu', +// 'macAddress': '14:fe:b5:9d:54:7e', +// 'ipAddress': '192.168.1.105', +// 'tempProbeKey': '45374d4egsdfw332', +// 'apiKey': '45374d4egsdfw332', +// 'domain': { +// +// }, +// 'probe': { +// +// }, +// }, +// { +// 'id': '33', +// 'MetaNoAuthProbeStatus': { +// 'name': 'PROCESS', +// }, +// 'hostName': 'insanity ubuntu', +// 'macAddress': '14:fe:b5:9d:54:7e', +// 'ipAddress': '192.168.1.105', +// 'tempProbeKey': '45374d4egsdfw332', +// 'apiKey': '45374d4egsdfw332', +// 'domain': { +// +// }, +// 'probe': { +// +// }, +// }, +// ]; diff --git a/src/ts/@overflow/noauthprobe/redux/action/read_all_by_domain.ts b/src/ts/@overflow/noauthprobe/redux/action/read_all_by_domain.ts index 7262a5b..3a1690a 100644 --- a/src/ts/@overflow/noauthprobe/redux/action/read_all_by_domain.ts +++ b/src/ts/@overflow/noauthprobe/redux/action/read_all_by_domain.ts @@ -1,44 +1,8 @@ -import Action from '@overflow/commons/redux/Action'; -import NoAuthProbe from '../../api/model/NoAuthProbe'; -import Domain from '@overflow/domain/api/model/Domain'; +export type REQUEST = '@overflow/noauth/read_all_by_domain/REQUEST'; +export type REQUEST_SUCCESS = '@overflow/noauth/read_all_by_domain/REQUEST/SUCCESS'; +export type REQUEST_FAILURE = '@overflow/noauth/read_all_by_domain/REQUEST/FAILURE'; -import ReadAllByDomainPayload from '../payload/ReadAllByDomainPayload'; +export const REQUEST: REQUEST = '@overflow/noauth/read_all_by_domain/REQUEST'; +export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/noauth/read_all_by_domain/REQUEST/SUCCESS'; +export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/noauth/read_all_by_domain/REQUEST/FAILURE'; -// Action Type -export type REQUEST = '@overflow/noAuthProbe/read_all_by_domain/REQUEST'; -export type REQUEST_SUCCESS = '@overflow/noAuthProbe/read_all_by_domain/REQUEST_SUCCESS'; -export type REQUEST_FAILURE = '@overflow/noAuthProbe/read_all_by_domain/REQUEST_FAILURE'; - -export const REQUEST: REQUEST = '@overflow/noAuthProbe/read_all_by_domain/REQUEST'; -export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/noAuthProbe/read_all_by_domain/REQUEST_SUCCESS'; -export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/noAuthProbe/read_all_by_domain/REQUEST_FAILURE'; - -// Action Creater -export type request = (domain: Domain) => Action; -export type requestSuccess = (noAuthProbeList: NoAuthProbe[]) => Action; -export type requestFailure = (error: Error) => Action; - - - -export const request: request = (domain: Domain): Action => { - return { - type: REQUEST, - payload: { - domain:domain, - }, - }; -}; - -export const requestSuccess: requestSuccess = (noAuthProbeList: NoAuthProbe[]): Action => { - return { - type: REQUEST_SUCCESS, - payload: noAuthProbeList, - }; -}; - -export const requestFailure: requestFailure = (error: Error): Action => { - return { - type: REQUEST_FAILURE, - error: error, - }; -}; diff --git a/src/ts/@overflow/noauthprobe/redux/reducer/read_all_by_domain.ts b/src/ts/@overflow/noauthprobe/redux/reducer/read_all_by_domain.ts index 5c15c15..19bd961 100644 --- a/src/ts/@overflow/noauthprobe/redux/reducer/read_all_by_domain.ts +++ b/src/ts/@overflow/noauthprobe/redux/reducer/read_all_by_domain.ts @@ -1,3 +1,27 @@ /** * Created by geek on 17. 7. 3. */ +import Action from '@overflow/commons/redux/Action'; +import { ReducersMapObject } from 'redux'; +import NoAuthProbe from '@overflow/noauthprobe/api/model/NoAuthProbe'; + +import * as ReadAllByDomainActionTypes from '../action/read_all_by_domain'; +import ReadAllNoAuthProbeByDomainState, { defaultState as readAllNoAuthProbeByDomainDefaultState } from '../state/ReadAllByDomain'; + +const reducer: ReducersMapObject = { + [ReadAllByDomainActionTypes.REQUEST_SUCCESS]: + (state: ReadAllNoAuthProbeByDomainState = readAllNoAuthProbeByDomainDefaultState, action: Action): + ReadAllNoAuthProbeByDomainState => { + return { + ...state, + noauthList: action.payload, + }; + }, + [ReadAllByDomainActionTypes.REQUEST_FAILURE]: + (state: ReadAllNoAuthProbeByDomainState = readAllNoAuthProbeByDomainDefaultState, action: Action): + ReadAllNoAuthProbeByDomainState => { + return state; + }, +}; + +export default reducer; diff --git a/src/ts/@overflow/noauthprobe/redux/state/ReadAllByDomain.ts b/src/ts/@overflow/noauthprobe/redux/state/ReadAllByDomain.ts index e69de29..288a6ed 100644 --- a/src/ts/@overflow/noauthprobe/redux/state/ReadAllByDomain.ts +++ b/src/ts/@overflow/noauthprobe/redux/state/ReadAllByDomain.ts @@ -0,0 +1,13 @@ +import NoAuthProbe from '../../api/model/NoAuthProbe'; + +export interface State { + readonly noauthList?: NoAuthProbe[]; + readonly error?: Error; +} + +export const defaultState: State = { + noauthList: undefined, + error: undefined, +}; + +export default State;