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> { private initRpcClient(): Promise<WebSocketRPC> {
const rpcClient = new Promise<WebSocketRPC>((resolve, reject) => { const rpcClient = new Promise<WebSocketRPC>((resolve, reject) => {
let client = new WebSocketRPC(this.config.rpc.url); let client = new WebSocketRPC(this.config.rpc.url);
// client.initialize() client.initialize()
// .then(() => { .then(() => {
// resolve(client);
// })
// .catch((err: any) => {
// reject(err);
// });
resolve(client); resolve(client);
})
.catch((err: any) => {
reject(err);
});
// resolve(client);
}); });
return rpcClient; return rpcClient;

View File

@ -12,6 +12,7 @@ import * as probeReadActions from '../redux/action/read';
export function mapStateToProps(state: any, props: any): ProbeDetailStateProps { export function mapStateToProps(state: any, props: any): ProbeDetailStateProps {
return { return {
id: props.params.id, 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 { export function mapStateToProps(state: any): ProbeListStateProps {
return { return {
probeList: state.probeList,
}; };
} }

View File

@ -12,6 +12,7 @@ import { Discovery } from '@overflow/discovery/react/components/Discovery';
export interface StateProps { export interface StateProps {
id: string; id: string;
probe: Probe;
} }
export interface DispatchProps { export interface DispatchProps {
@ -22,8 +23,6 @@ export interface DispatchProps {
export type Props = StateProps & DispatchProps; export type Props = StateProps & DispatchProps;
export interface State { 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) { constructor(props: Props, context: State) {
super(props, context); super(props, context);
this.state = { this.state = {
probe: null,
// isDiscovery: false,
}; };
} }
public componentWillMount(): void { public componentWillMount(): void {
this.props.onRead(this.props.id); 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 { 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 => { public handleDiscovery = (event: any, data: any): void => {
console.log(event); this.props.onDiscoveryClick(this.props.id);
// this.setState({ isDiscovery: true });
this.props.onDiscoveryClick('11');
} }
// public renderDiscovery(): JSX.Element {
// if (this.state.isDiscovery) {
// return <Discovery />;
// }
// return null;
//
// }
public showStopBtn(): JSX.Element { 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 />; return <Button content='Stop' icon='stop' labelPosition='left' negative />;
} }
} }
public render(): JSX.Element { public render(): JSX.Element {
if (this.props.probe === undefined) {
return null;
}
return ( return (
<Container fluid> <Container fluid>
<Table celled={false} > <Table celled={false} >
@ -101,31 +65,31 @@ export class ProbeDetailInfo extends React.Component<Props, State> {
<Table.Cell collapsing> <Table.Cell collapsing>
<Header size='small'>Name</Header> <Header size='small'>Name</Header>
</Table.Cell> </Table.Cell>
<Table.Cell>{this.state.probe.displayName}</Table.Cell> <Table.Cell>{this.props.probe.displayName}</Table.Cell>
</Table.Row> </Table.Row>
<Table.Row> <Table.Row>
<Table.Cell collapsing> <Table.Cell collapsing>
<Header size='small'>Status</Header> <Header size='small'>Status</Header>
</Table.Cell> </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.Row> <Table.Row>
<Table.Cell collapsing> <Table.Cell collapsing>
<Header size='small'>Created at</Header> <Header size='small'>Created at</Header>
</Table.Cell> </Table.Cell>
<Table.Cell>{this.state.probe.createDate}</Table.Cell> <Table.Cell>{this.props.probe.createDate}</Table.Cell>
</Table.Row> </Table.Row>
<Table.Row> <Table.Row>
<Table.Cell collapsing> <Table.Cell collapsing>
<Header size='small'>Authorized at</Header> <Header size='small'>Authorized at</Header>
</Table.Cell> </Table.Cell>
<Table.Cell>{this.state.probe.authorizeDate}</Table.Cell> <Table.Cell>{this.props.probe.authorizeDate}</Table.Cell>
</Table.Row> </Table.Row>
<Table.Row> <Table.Row>
<Table.Cell collapsing> <Table.Cell collapsing>
<Header size='small'>Authorized by</Header> <Header size='small'>Authorized by</Header>
</Table.Cell> </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.Row> <Table.Row>
<Table.Cell collapsing> <Table.Cell collapsing>
@ -137,7 +101,7 @@ export class ProbeDetailInfo extends React.Component<Props, State> {
<Table.Cell collapsing> <Table.Cell collapsing>
<Header size='small'>Description</Header> <Header size='small'>Description</Header>
</Table.Cell> </Table.Cell>
<Table.Cell>{this.state.probe.description}</Table.Cell> <Table.Cell>{this.props.probe.description}</Table.Cell>
</Table.Row> </Table.Row>
</Table.Body> </Table.Body>
</Table> </Table>

View File

@ -5,6 +5,7 @@ import Probe from '@overflow/probe/api/model/Probe';
import Domain from '@overflow/domain/api/model/Domain'; import Domain from '@overflow/domain/api/model/Domain';
export interface StateProps { export interface StateProps {
probeList?: Probe[];
} }
export interface DispatchProps { export interface DispatchProps {
@ -16,19 +17,15 @@ export type Props = StateProps & DispatchProps;
export interface State { export interface State {
selected: Probe; selected: Probe;
list: Probe[];
} }
export class ProbeList extends React.Component<Props, State> { export class ProbeList extends React.Component<Props, State> {
private data: any;
constructor(props: Props, context: State) { constructor(props: Props, context: State) {
super(props, context); super(props, context);
this.state = { this.state = {
selected: null, selected: null,
list: null,
}; };
} }
@ -37,60 +34,6 @@ export class ProbeList extends React.Component<Props, State> {
id: 1, id: 1,
}; };
this.props.onReadAllByDomain(domain); 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 { public checkCellStatus(status: any): boolean {
@ -109,27 +52,27 @@ export class ProbeList extends React.Component<Props, State> {
} }
public handleSearch = (result: Probe[]): void => { public handleSearch = (result: Probe[]): void => {
this.setState({ // this.setState({
list: result, // list: result,
}); // });
} }
public handleFilter(filterStr: string): void { public handleFilter(filterStr: string): void {
if (filterStr === null) { // if (filterStr === null) {
this.setState({ // this.setState({
list: this.data, // list: this.props.probeList,
}); // });
return; // return;
} // }
let founds = new Array(); // let founds = new Array();
for (let probe of this.data) { // for (let probe of this.props.probeList) {
if (probe.metaProbeStatus.name.indexOf(filterStr) !== -1) { // if (probe.status.name.indexOf(filterStr) !== -1) {
founds.push(probe); // founds.push(probe);
} // }
} // }
this.setState({ // this.setState({
list: founds, // list: founds,
}); // });
} }
public render(): JSX.Element { public render(): JSX.Element {
@ -156,7 +99,7 @@ export class ProbeList extends React.Component<Props, State> {
return ( return (
<ListContainer <ListContainer
contents={probeList} contents={probeList}
data={this.data} data={this.props.probeList}
onSearch={this.handleSearch} onSearch={this.handleSearch}
filter={<ProbeFilter onFilter={this.handleFilter.bind(this)} />} 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[]) { 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 > return <Table.Row error >
<Table.Cell textAlign='center' colSpan='6'>No results found.</Table.Cell> <Table.Cell textAlign='center' colSpan='6'>No results found.</Table.Cell>
</Table.Row>; </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.Row key={index} onClick={this.handleSelect.bind(this, probe)}>
<Table.Cell >{probe.displayName}</Table.Cell> <Table.Cell >{probe.displayName}</Table.Cell>
<Table.Cell>{probe.cidr}</Table.Cell> <Table.Cell>{probe.cidr}</Table.Cell>
@ -180,7 +126,6 @@ export class ProbeList extends React.Component<Props, State> {
</Table.Row> </Table.Row>
)); ));
} }
} }
export class ProbeFilter extends React.Component<any, any> { export class ProbeFilter extends React.Component<any, any> {
@ -210,11 +155,11 @@ export class ProbeFilter extends React.Component<any, any> {
let metaProbeStatus = [ let metaProbeStatus = [
{ {
'id': '1', 'id': '1',
'name': 'STARTED', 'name': 'INITIAL',
}, },
{ {
'id': '2', 'id': '2',
'name': 'STOPPED', 'name': 'NORMAL',
}, },
]; ];
return ( return (

View File

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

View File

@ -9,7 +9,10 @@ const reducer: ReducersMapObject = {
[ReadAllByDomainActionTypes.REQUEST_SUCCESS]: [ReadAllByDomainActionTypes.REQUEST_SUCCESS]:
(state: ReadAllProbeByDomainState = readAllProbeByDomainDefaultState, action: Action<Probe>): (state: ReadAllProbeByDomainState = readAllProbeByDomainDefaultState, action: Action<Probe>):
ReadAllProbeByDomainState => { ReadAllProbeByDomainState => {
return state; return {
...state,
probeList: <Probe[]>action.payload,
};
}, },
[ReadAllByDomainActionTypes.REQUEST_FAILURE]: [ReadAllByDomainActionTypes.REQUEST_FAILURE]:
(state: ReadAllProbeByDomainState = readAllProbeByDomainDefaultState, action: Action<Error>): (state: ReadAllProbeByDomainState = readAllProbeByDomainDefaultState, action: Action<Error>):

View File

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

View File

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