This commit is contained in:
insanity 2017-08-10 18:21:21 +09:00
parent 99dc68d147
commit 52bafd4510
9 changed files with 68 additions and 144 deletions

View File

@ -106,14 +106,14 @@ class OFApplication {
private initRpcClient(): Promise<WebSocketRPC> {
const rpcClient = new Promise<WebSocketRPC>((resolve, reject) => {
let client = new WebSocketRPC(this.config.rpc.url);
// client.initialize()
// .then(() => {
// resolve(client);
// })
// .catch((err: any) => {
// reject(err);
// });
resolve(client);
client.initialize()
.then(() => {
resolve(client);
})
.catch((err: any) => {
reject(err);
});
// resolve(client);
});
return rpcClient;

View File

@ -12,6 +12,7 @@ import * as probeReadActions from '../redux/action/read';
export function mapStateToProps(state: any, props: any): ProbeDetailStateProps {
return {
id: props.params.id,
probe: state.probe,
};
}

View File

@ -12,6 +12,7 @@ import * as asyncRequestActions from '@overflow/commons/redux/action/asyncReques
export function mapStateToProps(state: any): ProbeListStateProps {
return {
probeList: state.probeList,
};
}

View File

@ -12,6 +12,7 @@ import { Discovery } from '@overflow/discovery/react/components/Discovery';
export interface StateProps {
id: string;
probe: Probe;
}
export interface DispatchProps {
@ -22,8 +23,6 @@ export interface DispatchProps {
export type Props = StateProps & DispatchProps;
export interface State {
probe: any; // todo. fix to Probe
// isDiscovery: boolean;
}
@ -32,40 +31,11 @@ export class ProbeDetailInfo extends React.Component<Props, State> {
constructor(props: Props, context: State) {
super(props, context);
this.state = {
probe: null,
// isDiscovery: false,
};
}
public componentWillMount(): void {
this.props.onRead(this.props.id);
// todo. getting probe by probeId
let p = {
'id': '11',
'status': {
'name': 'INITIAL',
},
'domain': {
'name': 'insanity\'s domain',
},
'cidr': '192.168.1.0/24',
'displayName': '192.168.1.105\'s probe',
'targetCount': '20',
'sensorCount': '30',
'probeKey': '1AGBLKDFJ2452ASDGFL2KWJLKSDJ',
'description': 'description1111111111',
'createDate': '2017-01-01',
'authorizeDate': '2017-01-01',
'restartDate': '2017-01-01',
'authorizeMember': {
'name': 'insanity',
},
};
this.setState({
probe: p,
// isDiscovery: false,
});
}
public handleStartStop(event: any, data: any): void {
@ -73,26 +43,20 @@ export class ProbeDetailInfo extends React.Component<Props, State> {
}
public handleDiscovery = (event: any, data: any): void => {
console.log(event);
// this.setState({ isDiscovery: true });
this.props.onDiscoveryClick('11');
this.props.onDiscoveryClick(this.props.id);
}
// public renderDiscovery(): JSX.Element {
// if (this.state.isDiscovery) {
// return <Discovery />;
// }
// return null;
//
// }
public showStopBtn(): JSX.Element {
if (this.state.probe.status.name === 'NORMAL') {
if (this.props.probe.status.name === 'NORMAL') {
return <Button content='Stop' icon='stop' labelPosition='left' negative />;
}
}
public render(): JSX.Element {
if (this.props.probe === undefined) {
return null;
}
return (
<Container fluid>
<Table celled={false} >
@ -101,31 +65,31 @@ export class ProbeDetailInfo extends React.Component<Props, State> {
<Table.Cell collapsing>
<Header size='small'>Name</Header>
</Table.Cell>
<Table.Cell>{this.state.probe.displayName}</Table.Cell>
<Table.Cell>{this.props.probe.displayName}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell collapsing>
<Header size='small'>Status</Header>
</Table.Cell>
<Table.Cell>{this.state.probe.status.name}</Table.Cell>
<Table.Cell>{this.props.probe.status.name}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell collapsing>
<Header size='small'>Created at</Header>
</Table.Cell>
<Table.Cell>{this.state.probe.createDate}</Table.Cell>
<Table.Cell>{this.props.probe.createDate}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell collapsing>
<Header size='small'>Authorized at</Header>
</Table.Cell>
<Table.Cell>{this.state.probe.authorizeDate}</Table.Cell>
<Table.Cell>{this.props.probe.authorizeDate}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell collapsing>
<Header size='small'>Authorized by</Header>
</Table.Cell>
<Table.Cell>{this.state.probe.authorizeMember.name}</Table.Cell>
<Table.Cell>{this.props.probe.authorizeMember.name}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell collapsing>
@ -137,7 +101,7 @@ export class ProbeDetailInfo extends React.Component<Props, State> {
<Table.Cell collapsing>
<Header size='small'>Description</Header>
</Table.Cell>
<Table.Cell>{this.state.probe.description}</Table.Cell>
<Table.Cell>{this.props.probe.description}</Table.Cell>
</Table.Row>
</Table.Body>
</Table>

View File

@ -5,6 +5,7 @@ import Probe from '@overflow/probe/api/model/Probe';
import Domain from '@overflow/domain/api/model/Domain';
export interface StateProps {
probeList?: Probe[];
}
export interface DispatchProps {
@ -16,19 +17,15 @@ export type Props = StateProps & DispatchProps;
export interface State {
selected: Probe;
list: Probe[];
}
export class ProbeList extends React.Component<Props, State> {
private data: any;
constructor(props: Props, context: State) {
super(props, context);
this.state = {
selected: null,
list: null,
};
}
@ -37,60 +34,6 @@ export class ProbeList extends React.Component<Props, State> {
id: 1,
};
this.props.onReadAllByDomain(domain);
this.data = [
{
'id': 1,
'status': {
'name': 'NORMAL',
},
'domain': {
'name': 'insanity\'s domain',
},
'cidr': '192.168.1.0/24',
'displayName': '192.168.1.105\'s probe',
// 'infraHost': {
// 'ip': '192.168.1.105',
// 'mac': 'ab:cd:ef:gh:ij',
// },
'targetCount': 20,
'sensorCount': 30,
'probeKey': '1AGBLKDFJ2452ASDGFL2KWJLKSDJ',
'description': 'description1111111111',
},
{
'id': 1,
'status': {
'name': 'INITIAL',
},
'domain': {
'name': 'insanity\'s domain',
},
'displayName': '192.168.1.105\'s probe',
'cidr': '192.168.1.0/24',
'targetCount': 30,
'sensorCount': 40,
'probeKey': '1AGBLKDFJ2452ASDGFL2KWJLKSDJ',
'description': 'description1111111111',
},
{
'id': 1,
'status': {
'name': 'NORMAL',
},
'domain': {
'name': 'insanity\'s domain',
},
'cidr': '192.168.1.0/24',
'displayName': '192.168.1.105\'s probe',
'targetCount': 50,
'sensorCount': 60,
'probeKey': '1AGBLKDFJ2452ASDGFL2KWJLKSDJ',
'description': 'description1111111111',
},
];
this.setState({
list: this.data,
});
}
public checkCellStatus(status: any): boolean {
@ -109,27 +52,27 @@ export class ProbeList extends React.Component<Props, State> {
}
public handleSearch = (result: Probe[]): void => {
this.setState({
list: result,
});
// this.setState({
// list: result,
// });
}
public handleFilter(filterStr: string): void {
if (filterStr === null) {
this.setState({
list: this.data,
});
return;
}
let founds = new Array();
for (let probe of this.data) {
if (probe.metaProbeStatus.name.indexOf(filterStr) !== -1) {
founds.push(probe);
}
}
this.setState({
list: founds,
});
// if (filterStr === null) {
// this.setState({
// list: this.props.probeList,
// });
// return;
// }
// let founds = new Array();
// for (let probe of this.props.probeList) {
// if (probe.status.name.indexOf(filterStr) !== -1) {
// founds.push(probe);
// }
// }
// this.setState({
// list: founds,
// });
}
public render(): JSX.Element {
@ -156,7 +99,7 @@ export class ProbeList extends React.Component<Props, State> {
return (
<ListContainer
contents={probeList}
data={this.data}
data={this.props.probeList}
onSearch={this.handleSearch}
filter={<ProbeFilter onFilter={this.handleFilter.bind(this)} />}
/>
@ -164,12 +107,15 @@ export class ProbeList extends React.Component<Props, State> {
}
private renderRows(): (JSX.Element | JSX.Element[]) {
if (this.state.list.length === 0) {
if (this.props.probeList === undefined) {
return null;
}
if (this.props.probeList.length === 0) {
return <Table.Row error >
<Table.Cell textAlign='center' colSpan='6'>No results found.</Table.Cell>
</Table.Row>;
}
return this.state.list.map((probe: any, index: number) => (
return this.props.probeList.map((probe: Probe, index: number) => (
<Table.Row key={index} onClick={this.handleSelect.bind(this, probe)}>
<Table.Cell >{probe.displayName}</Table.Cell>
<Table.Cell>{probe.cidr}</Table.Cell>
@ -180,7 +126,6 @@ export class ProbeList extends React.Component<Props, State> {
</Table.Row>
));
}
}
export class ProbeFilter extends React.Component<any, any> {
@ -210,11 +155,11 @@ export class ProbeFilter extends React.Component<any, any> {
let metaProbeStatus = [
{
'id': '1',
'name': 'STARTED',
'name': 'INITIAL',
},
{
'id': '2',
'name': 'STOPPED',
'name': 'NORMAL',
},
];
return (

View File

@ -9,7 +9,10 @@ const reducer: ReducersMapObject = {
[ReadActionTypes.REQUEST_SUCCESS]:
(state: ReadState = readDefaultState, action: Action<Probe>):
ReadState => {
return state;
return {
...state,
probe: <Probe>action.payload,
};
},
[ReadActionTypes.REQUEST_FAILURE]:
(state: ReadState = readDefaultState, action: Action<Error>):

View File

@ -8,12 +8,15 @@ import ReadAllProbeByDomainState, { defaultState as readAllProbeByDomainDefaultS
const reducer: ReducersMapObject = {
[ReadAllByDomainActionTypes.REQUEST_SUCCESS]:
(state: ReadAllProbeByDomainState = readAllProbeByDomainDefaultState, action: Action<Probe>):
ReadAllProbeByDomainState => {
return state;
ReadAllProbeByDomainState => {
return {
...state,
probeList: <Probe[]>action.payload,
};
},
[ReadAllByDomainActionTypes.REQUEST_FAILURE]:
(state: ReadAllProbeByDomainState = readAllProbeByDomainDefaultState, action: Action<Error>):
ReadAllProbeByDomainState => {
ReadAllProbeByDomainState => {
return state;
},
};

View File

@ -1,8 +1,13 @@
import Probe from '../../api/model/Probe';
export interface State {
readonly probe?: Probe;
readonly error?: Error;
}
export const defaultState: State = {
probe: undefined,
error: undefined,
};

View File

@ -1,10 +1,12 @@
import Probe from '../../api/model/Probe';
export interface State {
readonly temp?: any;
readonly probeList?: Probe[];
readonly error?: Error;
}
export const defaultState: State = {
temp: null,
probeList: undefined,
error: undefined,
};