sensor list binding

This commit is contained in:
snoop 2017-08-10 17:15:45 +09:00
parent a0dcd38dcf
commit 99dc68d147
8 changed files with 168 additions and 120 deletions

View File

@ -17,21 +17,24 @@ import Sensor from '@overflow/sensor/api/model/Sensor';
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 * as asyncRequestActions from '@overflow/commons/redux/action/asyncRequest';
export function mapStateToProps(state: any): SensorListStateProps { export function mapStateToProps(state: any): SensorListStateProps {
return { return {
sensorList:state.SensorList,
}; };
} }
export function mapDispatchToProps(dispatch: Dispatch<any>): SensorListDispatchProps { export function mapDispatchToProps(dispatch: Dispatch<any>): SensorListDispatchProps {
return { return {
onReadAllByTarget: (target: Target) => { onReadAllByTarget: (target: Target) => {
dispatch(ReadAllByTargetActions.request(target)); dispatch(asyncRequestActions.request('SensorService', 'readAllByTarget', ReadAllByTargetActions.REQUEST, JSON.stringify(target)));
}, },
onReadAllByProbe: (probe: Probe) => { onReadAllByProbe: (probe: Probe) => {
dispatch(ReadAllByProbeActions.request(probe)); dispatch(ReadAllByProbeActions.request(probe));
}, },
onReadAllByDomain: (domain: Domain) => { onReadAllByDomain: (domain: Domain) => {
dispatch(ReadAllByDomainActions.request(domain)); dispatch(asyncRequestActions.request('SensorService', 'readAllByDomain', ReadAllByDomainActions.REQUEST, domain));
}, },
onSelectSensor: (id: number) => { onSelectSensor: (id: number) => {
dispatch(routerPush('/sensor/' + String(id))); dispatch(routerPush('/sensor/' + String(id)));

View File

@ -10,6 +10,7 @@ import Domain from '@overflow/domain/api/model/Domain';
export interface StateProps { export interface StateProps {
probe?: Probe; probe?: Probe;
target?: Target; target?: Target;
sensorList?: Sensor[];
} }
export interface DispatchProps { export interface DispatchProps {
@ -29,64 +30,71 @@ export interface SensorListState {
export class SensorList extends React.Component<SensorListProps, SensorListState> { export class SensorList extends React.Component<SensorListProps, SensorListState> {
private data: any; // private data: any;
constructor(props: SensorListProps, context: SensorListState) { constructor(props: SensorListProps, context: SensorListState) {
super(props, context); super(props, context);
this.state = { this.state = {
selected: null, selected: null,
}; };
let target: Target = {
id:1,
};
this.props.onReadAllByTarget(target);
} }
public componentWillMount(): void { public componentWillMount(): void {
// super.componentWillMount(); // super.componentWillMount();
this.data = [
{ // this.data = [
'id': '111', // {
'metaSensorStatus': { // 'id': '111',
'name': 'NORMAL', // 'metaSensorStatus': {
}, // 'name': 'NORMAL',
'target': { // },
'id': '1', // 'target': {
}, // 'id': '1',
'metaCrawler': { // },
'name': 'WMI', // 'metaCrawler': {
'description': 'WMI description', // 'name': 'WMI',
}, // 'description': 'WMI description',
'crawlerInputItems': 'json value', // },
'description': 'description1111111111', // 'crawlerInputItems': 'json value',
}, // 'description': 'description1111111111',
{ // },
'id': '222', // {
'metaSensorStatus': { // 'id': '222',
'name': 'NORMAL', // 'metaSensorStatus': {
}, // 'name': 'NORMAL',
'target': { // },
'id': '1', // 'target': {
}, // 'id': '1',
'metaCrawler': { // },
'name': 'SNMP', // 'metaCrawler': {
'description': 'SNMP description', // 'name': 'SNMP',
}, // 'description': 'SNMP description',
'crawlerInputItems': 'json value', // },
'description': 'description1111111111', // 'crawlerInputItems': 'json value',
}, // 'description': 'description1111111111',
{ // },
'id': '333', // {
'metaSensorStatus': { // 'id': '333',
'name': 'NORMAL', // 'metaSensorStatus': {
}, // 'name': 'NORMAL',
'target': { // },
'id': '1', // 'target': {
}, // 'id': '1',
'metaCrawler': { // },
'name': 'JMX', // 'metaCrawler': {
'description': 'JMX description', // 'name': 'JMX',
}, // 'description': 'JMX description',
'crawlerInputItems': 'json value', // },
'description': 'description1111111111', // 'crawlerInputItems': 'json value',
}, // 'description': 'description1111111111',
]; // },
// ];
} }
public handleSelect(selectedSensor: Sensor): void { public handleSelect(selectedSensor: Sensor): void {
@ -135,18 +143,18 @@ export class SensorList extends React.Component<SensorListProps, SensorListState
</Table.Header> </Table.Header>
<Table.Body> <Table.Body>
{this.data.map((sensor: any, index: number) => ( {this.props.sensorList ? this.props.sensorList.map((sensor: Sensor, index: number) => (
<Table.Row key={index} onClick={this.handleSelect.bind(this, sensor)}> <Table.Row key={index} onClick={this.handleSelect.bind(this, sensor)}>
<Table.Cell textAlign={'center'}>{index + 1}</Table.Cell> <Table.Cell textAlign={'center'}>{index + 1}</Table.Cell>
<Table.Cell negative={this.checkCellStatus(sensor.metaSensorStatus)} textAlign={'center'}> <Table.Cell negative={this.checkCellStatus(sensor.status)} textAlign={'center'}>
{sensor.metaSensorStatus.name} {sensor.status.name}
</Table.Cell> </Table.Cell>
<Table.Cell><Header size='small'>{sensor.metaCrawler.name}</Header></Table.Cell> <Table.Cell><Header size='small'>{sensor.crawler.name}</Header></Table.Cell>
<Table.Cell>{sensor.description}</Table.Cell> <Table.Cell>{sensor.description}</Table.Cell>
<Table.Cell>to do</Table.Cell> <Table.Cell>to do</Table.Cell>
{/* <Table.Cell collapsing>{this.showStartStopBtn(sensor.metaSensorStatus)}</Table.Cell> */} {/* <Table.Cell collapsing>{this.showStartStopBtn(sensor.metaSensorStatus)}</Table.Cell> */}
</Table.Row> </Table.Row>
))} )) : ''}
</Table.Body> </Table.Body>
</Table> </Table>
<Button content='Add' icon='add' labelPosition='left' floated='right' positive onClick={this.handleAddSensor.bind(this)} /> <Button content='Add' icon='add' labelPosition='left' floated='right' positive onClick={this.handleAddSensor.bind(this)} />
@ -157,7 +165,7 @@ export class SensorList extends React.Component<SensorListProps, SensorListState
return ( return (
<ListContainer <ListContainer
contents={sensorList} contents={sensorList}
data={this.data} {/*data={this.data}*/}
/> />
); );

View File

@ -5,39 +5,39 @@ import Domain from '@overflow/domain/api/model/Domain';
// Action Type // Action Type
export type REQUEST = '@overflow/sensor/read_all_by_domain/REQUEST'; export type REQUEST = '@overflow/sensor/read_all_by_domain/REQUEST';
export type REQUEST_SUCCESS = '@overflow/sensor/read_all_by_domain/REQUEST_SUCCESS'; export type REQUEST_SUCCESS = '@overflow/sensor/read_all_by_domain/REQUEST/SUCCESS';
export type REQUEST_FAILURE = '@overflow/sensor/read_all_by_domain/REQUEST_FAILURE'; export type REQUEST_FAILURE = '@overflow/sensor/read_all_by_domain/REQUEST/FAILURE';
export const REQUEST: REQUEST = '@overflow/sensor/read_all_by_domain/REQUEST'; export const REQUEST: REQUEST = '@overflow/sensor/read_all_by_domain/REQUEST';
export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/sensor/read_all_by_domain/REQUEST_SUCCESS'; export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/sensor/read_all_by_domain/REQUEST/SUCCESS';
export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/sensor/read_all_by_domain/REQUEST_FAILURE'; export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/sensor/read_all_by_domain/REQUEST/FAILURE';
// Action Creater // // Action Creater
export type request = (domain: Domain) => Action<ReadAllByDomainPayload>; // export type request = (domain: Domain) => Action<ReadAllByDomainPayload>;
export type requestSuccess = (sensors: Sensor[]) => Action<Sensor[]>; // export type requestSuccess = (sensors: Sensor[]) => Action<Sensor[]>;
export type requestFailure = (error: Error) => Action; // export type requestFailure = (error: Error) => Action;
export const request: request = (domain: Domain): Action<ReadAllByDomainPayload> => { // export const request: request = (domain: Domain): Action<ReadAllByDomainPayload> => {
return { // return {
type: REQUEST, // type: REQUEST,
payload: { // payload: {
domain: domain, // domain: domain,
}, // },
}; // };
}; // };
export const requestSuccess: requestSuccess = (sensors: Sensor[]): Action<Sensor[]> => { // export const requestSuccess: requestSuccess = (sensors: Sensor[]): Action<Sensor[]> => {
return { // return {
type: REQUEST_SUCCESS, // type: REQUEST_SUCCESS,
payload: sensors, // payload: sensors,
}; // };
}; // };
export const requestFailure: requestFailure = (error: Error): Action => { // export const requestFailure: requestFailure = (error: Error): Action => {
return { // return {
type: REQUEST_FAILURE, // type: REQUEST_FAILURE,
error: error, // error: error,
}; // };
}; // };

View File

@ -5,39 +5,39 @@ import Target from '@overflow/target/api/model/Target';
// Action Type // Action Type
export type REQUEST = '@overflow/sensor/read_all_by_target/REQUEST'; export type REQUEST = '@overflow/sensor/read_all_by_target/REQUEST';
export type REQUEST_SUCCESS = '@overflow/sensor/read_all_by_target/REQUEST_SUCCESS'; export type REQUEST_SUCCESS = '@overflow/sensor/read_all_by_target/REQUEST/SUCCESS';
export type REQUEST_FAILURE = '@overflow/sensor/read_all_by_target/REQUEST_FAILURE'; export type REQUEST_FAILURE = '@overflow/sensor/read_all_by_target/REQUEST/FAILURE';
export const REQUEST: REQUEST = '@overflow/sensor/read_all_by_target/REQUEST'; export const REQUEST: REQUEST = '@overflow/sensor/read_all_by_target/REQUEST';
export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/sensor/read_all_by_target/REQUEST_SUCCESS'; export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/sensor/read_all_by_target/REQUEST/SUCCESS';
export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/sensor/read_all_by_target/REQUEST_FAILURE'; export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/sensor/read_all_by_target/REQUEST/FAILURE';
// Action Creater // Action Creater
export type request = (target: Target) => Action<ReadAllByTargetPayload>; // export type request = (target: Target) => Action<ReadAllByTargetPayload>;
export type requestSuccess = (sensors: Sensor[]) => Action<Sensor[]>; // export type requestSuccess = (sensors: Sensor[]) => Action<Sensor[]>;
export type requestFailure = (error: Error) => Action; // export type requestFailure = (error: Error) => Action;
export const request: request = (target: Target): Action<ReadAllByTargetPayload> => { // export const request: request = (target: Target): Action<ReadAllByTargetPayload> => {
return { // return {
type: REQUEST, // type: REQUEST,
payload: { // payload: {
target: target, // target: target,
}, // },
}; // };
}; // };
export const requestSuccess: requestSuccess = (sensors: Sensor[]): Action<Sensor[]> => { // export const requestSuccess: requestSuccess = (sensors: Sensor[]): Action<Sensor[]> => {
return { // return {
type: REQUEST_SUCCESS, // type: REQUEST_SUCCESS,
payload: sensors, // payload: sensors,
}; // };
}; // };
export const requestFailure: requestFailure = (error: Error): Action => { // export const requestFailure: requestFailure = (error: Error): Action => {
return { // return {
type: REQUEST_FAILURE, // type: REQUEST_FAILURE,
error: error, // error: error,
}; // };
}; // };

View File

@ -0,0 +1,21 @@
import Action from '@overflow/commons/redux/Action';
import { ReducersMapObject } from 'redux';
import Target from '@overflow/target/api/model/Target';
import * as ReadAllByDomainActionTypes from '../action/read_all_by_domain';
import ReadAllByTargetDomain, { defaultState as readAllByDomainDefaultState } from '../state/ReadAllByDomain';
const reducer: ReducersMapObject = {
[ReadAllByDomainActionTypes.REQUEST_SUCCESS]:
(state: ReadAllByTargetDomain = readAllByDomainDefaultState, action: Action<Target>):
ReadAllByTargetDomain => {
return state;
},
[ReadAllByDomainActionTypes.REQUEST_FAILURE]:
(state: ReadAllByTargetDomain = readAllByDomainDefaultState, action: Action<Error>):
ReadAllByTargetDomain => {
return state;
},
};
export default reducer;

View File

@ -4,18 +4,21 @@
import Action from '@overflow/commons/redux/Action'; import Action from '@overflow/commons/redux/Action';
import { ReducersMapObject } from 'redux'; import { ReducersMapObject } from 'redux';
import Target from '@overflow/target/api/model/Target'; import Sensor from '@overflow/sensor/api/model/Sensor';
import * as ReadAllByDomainActionTypes from '../action/read_all_by_domain'; import * as ReadAllByTargetActionTypes from '../action/read_all_by_target';
import ReadAllByTargetState, { defaultState as readAllByTargetDefaultState } from '../state/ReadAllByTarget'; import ReadAllByTargetState, { defaultState as readAllByTargetDefaultState } from '../state/ReadAllByTarget';
const reducer: ReducersMapObject = { const reducer: ReducersMapObject = {
[ReadAllByDomainActionTypes.REQUEST_SUCCESS]: [ReadAllByTargetActionTypes.REQUEST_SUCCESS]:
(state: ReadAllByTargetState = readAllByTargetDefaultState, action: Action<Target>): (state: ReadAllByTargetState = readAllByTargetDefaultState, action: Action<Sensor>): ReadAllByTargetState => {
ReadAllByTargetState => { console.log(action);
return state; return {
...state,
SensorList:<Sensor[]>action.payload,
};
}, },
[ReadAllByDomainActionTypes.REQUEST_FAILURE]: [ReadAllByTargetActionTypes.REQUEST_FAILURE]:
(state: ReadAllByTargetState = readAllByTargetDefaultState, action: Action<Error>): (state: ReadAllByTargetState = readAllByTargetDefaultState, action: Action<Error>):
ReadAllByTargetState => { ReadAllByTargetState => {
return state; return state;

View File

@ -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;

View File

@ -1,12 +1,12 @@
import Sensor from '../../api/model/Sensor'; import Sensor from '../../api/model/Sensor';
export interface State { export interface State {
readonly isGetSensorList: boolean; readonly SensorList: Sensor[];
readonly error?: Error; readonly error?: Error;
} }
export const defaultState: State = { export const defaultState: State = {
isGetSensorList: undefined, SensorList: undefined,
error: undefined, error: undefined,
}; };