paging ing

This commit is contained in:
insanity 2017-08-24 15:37:47 +09:00
parent f005f0f68b
commit f4bbbdec3c
4 changed files with 25 additions and 18 deletions

View File

@ -20,11 +20,13 @@ export function mapStateToProps(state: any, props: any): StateProps {
export function mapDispatchToProps(dispatch: Dispatch<any>): DispatchProps { export function mapDispatchToProps(dispatch: Dispatch<any>): DispatchProps {
return { return {
onReadAllByProbe: (probe: Probe) => { onReadAllByProbe: (probe: Probe, pageNo: string, countPerPage: string) => {
dispatch(asyncRequestActions.request('InfraService', 'readAllByProbe', targetListActions.REQUEST, JSON.stringify(probe))); dispatch(asyncRequestActions.request('InfraService', 'readAllByProbe', targetListActions.REQUEST,
JSON.stringify(probe), pageNo, countPerPage));
}, },
onReadAllByDomain: (domain: Domain) => { onReadAllByDomain: (domain: Domain, pageNo: string, countPerPage: string) => {
dispatch(asyncRequestActions.request('InfraService', 'readAllByDomain', targetListActions.REQUEST, JSON.stringify(domain))); dispatch(asyncRequestActions.request('InfraService', 'readAllByDomain', targetListActions.REQUEST,
JSON.stringify(domain), pageNo, countPerPage));
}, },
onTargetSelection: (infraId: string) => { onTargetSelection: (infraId: string) => {
dispatch(routerPush('/target/' + infraId)); dispatch(routerPush('/target/' + infraId));

View File

@ -7,17 +7,18 @@ import Domain from '@overflow/domain/api/model/Domain';
import { ListContainer } from '@overflow/commons/react/component/ListContainer'; import { ListContainer } from '@overflow/commons/react/component/ListContainer';
import DiscoveryContainer from '@overflow/discovery/react/Discovery'; import DiscoveryContainer from '@overflow/discovery/react/Discovery';
import Host from '@overflow/discovery/api/model/Host'; import Host from '@overflow/discovery/api/model/Host';
import Page from '@overflow/commons/api/model/Page';
import * as Utils from '@overflow/commons/util/Utils'; import * as Utils from '@overflow/commons/util/Utils';
export interface StateProps { export interface StateProps {
probeId?: string; probeId?: string;
infraList?: Infra[]; infraList?: Page;
} }
export interface DispatchProps { export interface DispatchProps {
onReadAllByProbe?(probe: Probe): void; onReadAllByProbe?(probe: Probe, pageNo: string, countPerPage: string): void;
onReadAllByDomain?(domain: Domain): void; onReadAllByDomain?(domain: Domain, pageNo: string, countPerPage: string): void;
onTargetSelection?(id: string): void; onTargetSelection?(id: string): void;
} }
@ -26,15 +27,18 @@ export type Props = StateProps & DispatchProps;
export interface State { export interface State {
selected: Infra; selected: Infra;
openAddTarget: boolean; openAddTarget: boolean;
page: number;
} }
export class TargetList extends React.Component<Props, State> { export class TargetList extends React.Component<Props, State> {
private countPerPage: number = 10;
constructor(props: Props, context: State) { constructor(props: Props, context: State) {
super(props, context); super(props, context);
this.state = { this.state = {
selected: null, selected: null,
openAddTarget: false, openAddTarget: false,
page: 0,
}; };
} }
@ -48,12 +52,12 @@ export class TargetList extends React.Component<Props, State> {
let domain: Domain = { let domain: Domain = {
id: 1, id: 1,
}; };
this.props.onReadAllByDomain(domain); this.props.onReadAllByDomain(domain, String(0), String(this.countPerPage));
} else { } else {
let probe: Probe = { let probe: Probe = {
id: Number(this.props.probeId), id: Number(this.props.probeId),
}; };
this.props.onReadAllByProbe(probe); this.props.onReadAllByProbe(probe, String(0), String(this.countPerPage));
} }
} }
@ -85,7 +89,7 @@ export class TargetList extends React.Component<Props, State> {
public onRefreshList = () => { public onRefreshList = () => {
console.log('onRefreshList'); console.log('onRefreshList');
this.setState({openAddTarget: false}); this.setState({ openAddTarget: false });
this.getTargetList(); this.getTargetList();
} }
@ -127,7 +131,7 @@ export class TargetList extends React.Component<Props, State> {
</Table.Header> </Table.Header>
<Table.Body> <Table.Body>
{this.props.infraList.map((infra: Infra, index: number) => ( {this.props.infraList.content.map((infra: Infra, index: number) => (
<Table.Row key={index} onClick={this.handleSelect.bind(this, infra)}> <Table.Row key={index} onClick={this.handleSelect.bind(this, infra)}>
<Table.Cell textAlign={'center'}>{index + 1}</Table.Cell> <Table.Cell textAlign={'center'}>{index + 1}</Table.Cell>
<Table.Cell textAlign={'center'}>{infra.infraType.name}</Table.Cell> <Table.Cell textAlign={'center'}>{infra.infraType.name}</Table.Cell>
@ -140,7 +144,7 @@ export class TargetList extends React.Component<Props, State> {
</Table> </Table>
<DiscoveryContainer probeId={1} open={this.state.openAddTarget} <DiscoveryContainer probeId={1} open={this.state.openAddTarget}
onClosePopup={this.onClosePopup.bind(this)} onRefreshList={this.onRefreshList} /> onClosePopup={this.onClosePopup.bind(this)} onRefreshList={this.onRefreshList} />
</Container>; </Container>;
return ( return (

View File

@ -1,21 +1,22 @@
import Action from '@overflow/commons/redux/Action'; import Action from '@overflow/commons/redux/Action';
import { ReducersMapObject } from 'redux'; import { ReducersMapObject } from 'redux';
import Infra from '@overflow/infra/api/model/Infra';
import * as ReadAllByProbeActionTypes from '../action/read_all_by_probe'; import * as ReadAllByProbeActionTypes from '../action/read_all_by_probe';
import ReadAllByProbeState, { defaultState as ReadAllByProbeDefaultState } from '../state/ReadAllByProbe'; import ReadAllByProbeState, { defaultState as ReadAllByProbeDefaultState } from '../state/ReadAllByProbe';
import Page from '@overflow/commons/api/model/Page';
const reducer: ReducersMapObject = { const reducer: ReducersMapObject = {
[ReadAllByProbeActionTypes.REQUEST_SUCCESS]: [ReadAllByProbeActionTypes.REQUEST_SUCCESS]:
(state: ReadAllByProbeState = ReadAllByProbeDefaultState, action: Action<Infra>): (state: ReadAllByProbeState = ReadAllByProbeDefaultState, action: Action<Page>):
ReadAllByProbeState => { ReadAllByProbeState => {
return { return {
...state, ...state,
infraList: <Infra[]>action.payload, infraList: <Page>action.payload,
}; };
}, },
[ReadAllByProbeActionTypes.REQUEST_FAILURE]: [ReadAllByProbeActionTypes.REQUEST_FAILURE]:
(state: ReadAllByProbeState = ReadAllByProbeDefaultState, action: Action<Infra>): (state: ReadAllByProbeState = ReadAllByProbeDefaultState, action: Action<Error>):
ReadAllByProbeState => { ReadAllByProbeState => {
return state; return state;
}, },

View File

@ -1,7 +1,7 @@
import Infra from '@overflow/infra/api/model/Infra'; import Page from '@overflow/commons/api/model/Page';
export interface State { export interface State {
readonly infraList?: Infra[]; readonly infraList?: Page;
readonly error?: Error; readonly error?: Error;
} }