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

View File

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

View File

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

View File

@ -5,39 +5,39 @@ import Target from '@overflow/target/api/model/Target';
// Action Type
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_FAILURE = '@overflow/sensor/read_all_by_target/REQUEST_FAILURE';
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 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_FAILURE: REQUEST_FAILURE = '@overflow/sensor/read_all_by_target/REQUEST_FAILURE';
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';
// Action Creater
export type request = (target: Target) => Action<ReadAllByTargetPayload>;
export type requestSuccess = (sensors: Sensor[]) => Action<Sensor[]>;
export type requestFailure = (error: Error) => Action;
// export type request = (target: Target) => Action<ReadAllByTargetPayload>;
// export type requestSuccess = (sensors: Sensor[]) => Action<Sensor[]>;
// export type requestFailure = (error: Error) => Action;
export const request: request = (target: Target): Action<ReadAllByTargetPayload> => {
return {
type: REQUEST,
payload: {
target: target,
},
};
};
// export const request: request = (target: Target): Action<ReadAllByTargetPayload> => {
// return {
// type: REQUEST,
// payload: {
// target: target,
// },
// };
// };
export const requestSuccess: requestSuccess = (sensors: Sensor[]): Action<Sensor[]> => {
return {
type: REQUEST_SUCCESS,
payload: sensors,
};
};
// export const requestSuccess: requestSuccess = (sensors: Sensor[]): Action<Sensor[]> => {
// return {
// type: REQUEST_SUCCESS,
// payload: sensors,
// };
// };
export const requestFailure: requestFailure = (error: Error): Action => {
return {
type: REQUEST_FAILURE,
error: error,
};
};
// export const requestFailure: requestFailure = (error: Error): Action => {
// return {
// type: REQUEST_FAILURE,
// 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 { 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';
const reducer: ReducersMapObject = {
[ReadAllByDomainActionTypes.REQUEST_SUCCESS]:
(state: ReadAllByTargetState = readAllByTargetDefaultState, action: Action<Target>):
ReadAllByTargetState => {
return state;
[ReadAllByTargetActionTypes.REQUEST_SUCCESS]:
(state: ReadAllByTargetState = readAllByTargetDefaultState, action: Action<Sensor>): ReadAllByTargetState => {
console.log(action);
return {
...state,
SensorList:<Sensor[]>action.payload,
};
},
[ReadAllByDomainActionTypes.REQUEST_FAILURE]:
[ReadAllByTargetActionTypes.REQUEST_FAILURE]:
(state: ReadAllByTargetState = readAllByTargetDefaultState, action: Action<Error>):
ReadAllByTargetState => {
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';
export interface State {
readonly isGetSensorList: boolean;
readonly SensorList: Sensor[];
readonly error?: Error;
}
export const defaultState: State = {
isGetSensorList: undefined,
SensorList: undefined,
error: undefined,
};