From 15ea4947a2911a013b4ba1377088e49bd993a7fa Mon Sep 17 00:00:00 2001 From: insanity Date: Thu, 24 Aug 2017 14:01:43 +0900 Subject: [PATCH 1/2] typed history --- src/ts/@overflow/app/config/index.ts | 2 + src/ts/@overflow/app/views/history/List.tsx | 2 +- .../@overflow/history/react/HistoryList.tsx | 11 ++- .../history/react/components/HistoryList.tsx | 77 ++++++++++++++++--- .../action/read_all_by_probe_and_type.ts | 7 ++ .../reducer/read_all_by_probe_and_type.ts | 25 ++++++ .../redux/state/ReadAllByProbeAndType.ts | 14 ++++ .../meta/api/model/MetaHistoryType.ts | 6 +- 8 files changed, 125 insertions(+), 19 deletions(-) create mode 100644 src/ts/@overflow/history/redux/action/read_all_by_probe_and_type.ts create mode 100644 src/ts/@overflow/history/redux/reducer/read_all_by_probe_and_type.ts create mode 100644 src/ts/@overflow/history/redux/state/ReadAllByProbeAndType.ts diff --git a/src/ts/@overflow/app/config/index.ts b/src/ts/@overflow/app/config/index.ts index 4aea2a2..2c785bc 100644 --- a/src/ts/@overflow/app/config/index.ts +++ b/src/ts/@overflow/app/config/index.ts @@ -38,6 +38,7 @@ import MetaSensorItemTypeReadAllReducer from '@overflow/meta/redux/reducer/senso import DiscoveryInfraTargetRegistAllReducer from '@overflow/discovery/redux/reducer/infra_target_regist_all'; import HistoryReadAllByProbeReducer from '@overflow/history/redux/reducer/read_all_by_probe'; +import HistoryReadAllByProbeAndTypeReducer from '@overflow/history/redux/reducer/read_all_by_probe_and_type'; import AsyncRequest from '@overflow/app/redux/saga/AsyncRequest'; @@ -101,6 +102,7 @@ const reduxConfig: ReduxConfig = { modifyProbeReducer, DiscoveryInfraTargetRegistAllReducer, HistoryReadAllByProbeReducer, + HistoryReadAllByProbeAndTypeReducer, ], sagaWatchers: [ AsyncRequest, diff --git a/src/ts/@overflow/app/views/history/List.tsx b/src/ts/@overflow/app/views/history/List.tsx index 639123c..8ba433d 100644 --- a/src/ts/@overflow/app/views/history/List.tsx +++ b/src/ts/@overflow/app/views/history/List.tsx @@ -11,7 +11,7 @@ class HistoryList extends React.Component, object> { public render(): JSX.Element { return (
- +
); } diff --git a/src/ts/@overflow/history/react/HistoryList.tsx b/src/ts/@overflow/history/react/HistoryList.tsx index b6869c6..b6e2574 100644 --- a/src/ts/@overflow/history/react/HistoryList.tsx +++ b/src/ts/@overflow/history/react/HistoryList.tsx @@ -8,11 +8,13 @@ import { import { push as routerPush } from 'react-router-redux'; import * as asyncRequestActions from '@overflow/commons/redux/action/asyncRequest'; import Probe from '@overflow/probe/api/model/Probe'; +import MetaHistoryType from '@overflow/meta/api/model/MetaHistoryType'; import * as readAllByProbeActions from '../redux/action/read_all_by_probe'; +import * as readAllByProbeAndTypeActions from '../redux/action/read_all_by_probe_and_type'; export function mapStateToProps(state: any, ownProps?: any): HistoryStateProps { return { - probeId: '1', + path: ownProps.params, histories: state.historyPage, }; } @@ -23,9 +25,10 @@ export function mapDispatchToProps(dispatch: Dispatch, ownProps?: any): His dispatch(asyncRequestActions.request('HistoryService', 'readAllByProbe', readAllByProbeActions.REQUEST, JSON.stringify(probe), pageNo, countPerPage)); }, - // onRedirectHome: () => { - // dispatch(routerPush('/')); - // }, + onReadAllByProbeAndType: (probe: Probe, type: MetaHistoryType, pageNo: string, countPerPage: string) => { + dispatch(asyncRequestActions.request('HistoryService', 'readAllByProbeAndType', readAllByProbeAndTypeActions.REQUEST, + JSON.stringify(probe), JSON.stringify(type), pageNo, countPerPage)); + }, }; } diff --git a/src/ts/@overflow/history/react/components/HistoryList.tsx b/src/ts/@overflow/history/react/components/HistoryList.tsx index a38b799..bcffc04 100644 --- a/src/ts/@overflow/history/react/components/HistoryList.tsx +++ b/src/ts/@overflow/history/react/components/HistoryList.tsx @@ -4,20 +4,23 @@ import { ListContainer } from '@overflow/commons/react/component/ListContainer'; import Probe from '@overflow/probe/api/model/Probe'; import History from '@overflow/history/api/model/History'; import Page from '@overflow/commons/api/model/Page'; +import MetaHistoryType from '@overflow/meta/api/model/MetaHistoryType'; export interface StateProps { - probeId: string; histories: Page; + path: any; } export interface DispatchProps { onReadAllByProbe?(probe: Probe, pageNo: string, countPerPage: string): void; + onReadAllByProbeAndType?(probe: Probe, type: MetaHistoryType, pageNo: string, countPerPage: string): void; } export type Props = StateProps & DispatchProps; export interface State { page: number; + isTypedHistory: boolean; } export class HistoryList extends React.Component { @@ -28,14 +31,57 @@ export class HistoryList extends React.Component { super(props, context); this.state = { page: 0, + isTypedHistory: false, }; } public componentWillMount(): void { + if (this.props.path === '/histories') { + this.setState({ + isTypedHistory: false, + }); + this.getAllHistory(0); + } else { + this.setState({ + isTypedHistory: true, + }); + this.getTypedHistory(0); + } + } + + public getAllHistory(pageNo: number): void { let probe: Probe = { id: Number(1), }; - this.props.onReadAllByProbe(probe, String(this.state.page), String(this.countPerPage)); + this.props.onReadAllByProbe(probe, String(pageNo), String(this.countPerPage)); + } + + public getTypedHistory(pageNo: number): void { + let probe: Probe = { + id: Number(1), + }; + let type = this.props.path.split('/')[1]; + console.log(type + '!!!!!!!!!'); + this.props.onReadAllByProbeAndType(probe, this.getMetaType(type), String(pageNo), String(this.countPerPage)); + } + + public getMetaType(typeStr: string): MetaHistoryType { + let metaType: MetaHistoryType = { + }; + if (typeStr === 'member') { + metaType.id = 1; + } else if (typeStr === 'probe') { + metaType.id = 2; + } else if (typeStr === 'discovery') { + metaType.id = 3; + } else if (typeStr === 'target') { + metaType.id = 4; + } else if (typeStr === 'crawler') { + metaType.id = 5; + } else if (typeStr === 'sensor') { + metaType.id = 6; + } + return metaType; } public handlePaging = (pageNo: number) => { @@ -48,7 +94,12 @@ export class HistoryList extends React.Component { let probe: Probe = { id: Number(1), }; - this.props.onReadAllByProbe(probe, String(pageNo), String(this.countPerPage)); + if (this.state.isTypedHistory) { + this.getTypedHistory(pageNo); + } else { + // this.props.onReadAllByProbe(probe, String(pageNo), String(this.countPerPage)); + this.getAllHistory(pageNo); + } } public handlePrevPage = (pn: string) => { @@ -64,32 +115,37 @@ export class HistoryList extends React.Component { let probe: Probe = { id: Number(1), }; - this.props.onReadAllByProbe(probe, String(p), String(this.countPerPage)); + if (this.state.isTypedHistory) { + this.getTypedHistory(p); + } else { + this.getAllHistory(p); + } } public renderPagination = (pageObj: Page): (JSX.Element | JSX.Element[]) => { if (pageObj === undefined) { return null; } + let keyIdx = 0; let totalPage = pageObj.totalPages; let currPage = pageObj.number; let elems = new Array; let prevIndicator = pageObj.first ? - : - + : + ; elems.push(prevIndicator); for (let i = 0; i < totalPage; i++) { if (i === currPage) { - elems.push({i + 1}); + elems.push({i + 1}); } else { - elems.push({i + 1}); + elems.push({i + 1}); } } let nextIndicator = pageObj.last ? - : - + : + ; elems.push(nextIndicator); @@ -100,7 +156,6 @@ export class HistoryList extends React.Component { } public render(): JSX.Element { - let historyList: JSX.Element = ( diff --git a/src/ts/@overflow/history/redux/action/read_all_by_probe_and_type.ts b/src/ts/@overflow/history/redux/action/read_all_by_probe_and_type.ts new file mode 100644 index 0000000..37d9941 --- /dev/null +++ b/src/ts/@overflow/history/redux/action/read_all_by_probe_and_type.ts @@ -0,0 +1,7 @@ +export type REQUEST = '@overflow/history/read_all_by_probe_and_type/REQUEST'; +export type REQUEST_SUCCESS = '@overflow/history/read_all_by_probe_and_type/REQUEST/SUCCESS'; +export type REQUEST_FAILURE = '@overflow/history/read_all_by_probe_and_type/REQUEST/FAILURE'; + +export const REQUEST: REQUEST = '@overflow/history/read_all_by_probe_and_type/REQUEST'; +export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/history/read_all_by_probe_and_type/REQUEST/SUCCESS'; +export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/history/read_all_by_probe_and_type/REQUEST/FAILURE'; diff --git a/src/ts/@overflow/history/redux/reducer/read_all_by_probe_and_type.ts b/src/ts/@overflow/history/redux/reducer/read_all_by_probe_and_type.ts new file mode 100644 index 0000000..9963637 --- /dev/null +++ b/src/ts/@overflow/history/redux/reducer/read_all_by_probe_and_type.ts @@ -0,0 +1,25 @@ +import Action from '@overflow/commons/redux/Action'; +import { ReducersMapObject } from 'redux'; +import Probe from '@overflow/probe/api/model/Probe'; +import History from '../../api/model/History'; +import Page from '@overflow/commons/api/model/Page'; +import * as ReadAllByProbeAndTypeActionTypes from '../action/read_all_by_probe_and_type'; +import ReadAllByProbeAndTypeState, { defaultState as ReadAllByProbeAndTypeDefaultState } from '../state/ReadAllByProbeAndType'; + +const reducer: ReducersMapObject = { + [ReadAllByProbeAndTypeActionTypes.REQUEST_SUCCESS]: + (state: ReadAllByProbeAndTypeState = ReadAllByProbeAndTypeDefaultState, action: Action): + ReadAllByProbeAndTypeState => { + return { + ...state, + historyPage: action.payload, + }; + }, + [ReadAllByProbeAndTypeActionTypes.REQUEST_FAILURE]: + (state: ReadAllByProbeAndTypeState = ReadAllByProbeAndTypeDefaultState, action: Action): + ReadAllByProbeAndTypeState => { + return state; + }, +}; + +export default reducer; diff --git a/src/ts/@overflow/history/redux/state/ReadAllByProbeAndType.ts b/src/ts/@overflow/history/redux/state/ReadAllByProbeAndType.ts new file mode 100644 index 0000000..c24fad9 --- /dev/null +++ b/src/ts/@overflow/history/redux/state/ReadAllByProbeAndType.ts @@ -0,0 +1,14 @@ +import History from '../../api/model/History'; +import Page from '@overflow/commons/api/model/Page'; + +export interface State { + readonly historyPage?: Page; + readonly error?: Error; +} + +export const defaultState: State = { + historyPage: undefined, + error: undefined, +}; + +export default State; diff --git a/src/ts/@overflow/meta/api/model/MetaHistoryType.ts b/src/ts/@overflow/meta/api/model/MetaHistoryType.ts index a950f9b..c7fca4b 100644 --- a/src/ts/@overflow/meta/api/model/MetaHistoryType.ts +++ b/src/ts/@overflow/meta/api/model/MetaHistoryType.ts @@ -1,7 +1,7 @@ export interface MetaHistoryType { - id: number; - name: string; - createDate: Date; + id?: number; + name?: string; + createDate?: Date; } export enum MetaHistoryType_ID { From 442b2c213df5efaffaafa40ff2e9230c3767b599 Mon Sep 17 00:00:00 2001 From: snoop Date: Thu, 24 Aug 2017 14:16:20 +0900 Subject: [PATCH 2/2] target / sensor --- src/ts/@overflow/app/config/index.ts | 6 +++++ .../@overflow/app/views/layout/AppLayout.tsx | 1 + .../app/views/monitoring/sensor/List.tsx | 2 +- .../app/views/monitoring/sensor/Setup.tsx | 2 +- .../meta/react/components/CrawlerSelector.tsx | 18 ------------- .../sensor/react/SensorConfiguration.tsx | 3 ++- src/ts/@overflow/sensor/react/SensorList.tsx | 12 ++++++--- .../react/components/SensorConfiguration.tsx | 6 ++--- .../sensor/react/components/SensorList.tsx | 4 ++- .../sensor/redux/action/read_all_by_infra.ts | 8 ++++++ .../sensor/redux/reducer/read_all_by_infra.ts | 26 +++++++++++++++++++ .../redux/reducer/read_all_by_target.ts | 2 +- .../sensor/redux/state/ReadAllByInfra.ts | 13 ++++++++++ src/ts/@overflow/target/react/TargetList.tsx | 4 +-- 14 files changed, 76 insertions(+), 31 deletions(-) create mode 100644 src/ts/@overflow/sensor/redux/action/read_all_by_infra.ts create mode 100644 src/ts/@overflow/sensor/redux/reducer/read_all_by_infra.ts create mode 100644 src/ts/@overflow/sensor/redux/state/ReadAllByInfra.ts diff --git a/src/ts/@overflow/app/config/index.ts b/src/ts/@overflow/app/config/index.ts index 2c785bc..514f45d 100644 --- a/src/ts/@overflow/app/config/index.ts +++ b/src/ts/@overflow/app/config/index.ts @@ -17,12 +17,14 @@ import noauthDenyReducer from '@overflow/noauthprobe/redux/reducer/deny'; 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'; import sensorReadAllByDomainReducer from '@overflow/sensor/redux/reducer/read_all_by_domain'; import SensorReadReducer from '@overflow/sensor/redux/reducer/read'; import SensorItemReadAllBySensorReducer from '@overflow/sensor/redux/reducer/item_read_all_by_sensor'; +import readAllTargetByInfraReducer from '@overflow/sensor/redux/reducer/read_all_by_infra'; import readMachineReducer from '@overflow/infra/redux/reducer/machine_read'; import readHostReducer from '@overflow/infra/redux/reducer/host_read'; @@ -102,7 +104,11 @@ const reduxConfig: ReduxConfig = { modifyProbeReducer, DiscoveryInfraTargetRegistAllReducer, HistoryReadAllByProbeReducer, +<<<<<<< 15ea4947a2911a013b4ba1377088e49bd993a7fa HistoryReadAllByProbeAndTypeReducer, +======= + readAllTargetByInfraReducer, +>>>>>>> fixed target / sensor ], sagaWatchers: [ AsyncRequest, diff --git a/src/ts/@overflow/app/views/layout/AppLayout.tsx b/src/ts/@overflow/app/views/layout/AppLayout.tsx index 8672470..80c9be2 100644 --- a/src/ts/@overflow/app/views/layout/AppLayout.tsx +++ b/src/ts/@overflow/app/views/layout/AppLayout.tsx @@ -46,6 +46,7 @@ export class AppLayout extends React.Component { + diff --git a/src/ts/@overflow/app/views/monitoring/sensor/List.tsx b/src/ts/@overflow/app/views/monitoring/sensor/List.tsx index db226ee..4e47374 100644 --- a/src/ts/@overflow/app/views/monitoring/sensor/List.tsx +++ b/src/ts/@overflow/app/views/monitoring/sensor/List.tsx @@ -10,7 +10,7 @@ class SensorList extends React.Component, object> { public render(): JSX.Element { return ( - + ); } } diff --git a/src/ts/@overflow/app/views/monitoring/sensor/Setup.tsx b/src/ts/@overflow/app/views/monitoring/sensor/Setup.tsx index 3c312a2..cce3ba6 100644 --- a/src/ts/@overflow/app/views/monitoring/sensor/Setup.tsx +++ b/src/ts/@overflow/app/views/monitoring/sensor/Setup.tsx @@ -10,7 +10,7 @@ class SensorSetup extends React.Component, object> { public render(): JSX.Element { return ( - + ); } } diff --git a/src/ts/@overflow/meta/react/components/CrawlerSelector.tsx b/src/ts/@overflow/meta/react/components/CrawlerSelector.tsx index c81163a..9258e11 100644 --- a/src/ts/@overflow/meta/react/components/CrawlerSelector.tsx +++ b/src/ts/@overflow/meta/react/components/CrawlerSelector.tsx @@ -59,24 +59,6 @@ export class CrawlerSelector extends React.Component): SensorListDispatchP onReadAllByTarget: (target: Target) => { dispatch(asyncRequestActions.request('SensorService', 'readAllByTarget', ReadAllByTargetActions.REQUEST, JSON.stringify(target))); }, + onReadAllByInfra: (infra: Infra) => { + dispatch(asyncRequestActions.request('SensorService', 'readAllByInfra', ReadAllByInfraActions.REQUEST, JSON.stringify(infra))); + }, onReadAllByProbe: (probe: Probe) => { dispatch(ReadAllByProbeActions.request(probe)); }, @@ -39,8 +45,8 @@ export function mapDispatchToProps(dispatch: Dispatch): SensorListDispatchP onSelectSensor: (id: number) => { dispatch(routerPush('/sensor/' + String(id))); }, - onAddSensor: (target: Target) => { - dispatch(routerPush('/sensor/setup')); + onAddSensor: (targetId: string) => { + dispatch(routerPush('/sensor_setup/' + String(targetId))); }, }; } diff --git a/src/ts/@overflow/sensor/react/components/SensorConfiguration.tsx b/src/ts/@overflow/sensor/react/components/SensorConfiguration.tsx index b0554f9..c676984 100644 --- a/src/ts/@overflow/sensor/react/components/SensorConfiguration.tsx +++ b/src/ts/@overflow/sensor/react/components/SensorConfiguration.tsx @@ -8,7 +8,7 @@ import SensorItemTree from '@overflow/meta/react/SensorItemTree'; import CrawlerSelectorContainer from '@overflow/meta/react/CrawlerSelector'; export interface SensorConfigurationStateProps { - + targetId: number; } export interface SensorConfigurationDispatchProps { @@ -38,8 +38,8 @@ export class SensorConfiguration extends React.Component, - , ]; + let steps = [, + , ]; return ( diff --git a/src/ts/@overflow/sensor/react/components/SensorList.tsx b/src/ts/@overflow/sensor/react/components/SensorList.tsx index d9beb85..5425dcb 100644 --- a/src/ts/@overflow/sensor/react/components/SensorList.tsx +++ b/src/ts/@overflow/sensor/react/components/SensorList.tsx @@ -6,6 +6,7 @@ import Probe from '@overflow/probe/api/model/Probe'; import Sensor from '@overflow/sensor/api/model/Sensor'; import Target from '@overflow/target/api/model/Target'; import Domain from '@overflow/domain/api/model/Domain'; +import Infra from '@overflow/infra/api/model/Infra'; export interface StateProps { probe?: Probe; @@ -20,6 +21,7 @@ export interface DispatchProps { onReadAllByDomain?(domain: Domain): void; onSelectSensor?(id: number): void; onAddSensor?(target: Target): void; + onReadAllByInfra?(infra: Infra): void; } export type SensorListProps = StateProps & DispatchProps; @@ -83,7 +85,7 @@ export class SensorList extends React.Component): ReadAllByInfraState => { + console.log(action); + return { + ...state, + SensorList:action.payload, + }; + }, + [ReadAllByInfraActionTypes.REQUEST_FAILURE]: + (state: ReadAllByInfraState = readAllByInfraDefaultState, action: Action): + ReadAllByInfraState => { + return state; + }, +}; + +export default reducer; diff --git a/src/ts/@overflow/sensor/redux/reducer/read_all_by_target.ts b/src/ts/@overflow/sensor/redux/reducer/read_all_by_target.ts index 14b0888..acebd70 100644 --- a/src/ts/@overflow/sensor/redux/reducer/read_all_by_target.ts +++ b/src/ts/@overflow/sensor/redux/reducer/read_all_by_target.ts @@ -11,7 +11,7 @@ import ReadAllByTargetState, { defaultState as readAllByTargetDefaultState } fro const reducer: ReducersMapObject = { [ReadAllByTargetActionTypes.REQUEST_SUCCESS]: - (state: ReadAllByTargetState = readAllByTargetDefaultState, action: Action): ReadAllByTargetState => { + (state: ReadAllByTargetState = readAllByTargetDefaultState, action: Action): ReadAllByTargetState => { console.log(action); return { ...state, diff --git a/src/ts/@overflow/sensor/redux/state/ReadAllByInfra.ts b/src/ts/@overflow/sensor/redux/state/ReadAllByInfra.ts new file mode 100644 index 0000000..bc8898d --- /dev/null +++ b/src/ts/@overflow/sensor/redux/state/ReadAllByInfra.ts @@ -0,0 +1,13 @@ +import Sensor from '../../api/model/Sensor'; + +export interface State { + readonly SensorList: Sensor[]; + readonly error?: Error; +} + +export const defaultState: State = { + SensorList: undefined, + error: undefined, +}; + +export default State; diff --git a/src/ts/@overflow/target/react/TargetList.tsx b/src/ts/@overflow/target/react/TargetList.tsx index b365901..4dbc2f3 100644 --- a/src/ts/@overflow/target/react/TargetList.tsx +++ b/src/ts/@overflow/target/react/TargetList.tsx @@ -26,8 +26,8 @@ export function mapDispatchToProps(dispatch: Dispatch): DispatchProps { onReadAllByDomain: (domain: Domain) => { dispatch(asyncRequestActions.request('InfraService', 'readAllByDomain', targetListActions.REQUEST, JSON.stringify(domain))); }, - onTargetSelection: (id: string) => { - dispatch(routerPush('/target/' + id)); + onTargetSelection: (infraId: string) => { + dispatch(routerPush('/target/' + infraId)); }, }; }