paging history
This commit is contained in:
parent
5c5cf2fa13
commit
d4ea194612
|
@ -13,14 +13,15 @@ import * as readAllByProbeActions from '../redux/action/read_all_by_probe';
|
||||||
export function mapStateToProps(state: any, ownProps?: any): HistoryStateProps {
|
export function mapStateToProps(state: any, ownProps?: any): HistoryStateProps {
|
||||||
return {
|
return {
|
||||||
probeId: '1',
|
probeId: '1',
|
||||||
histories: state.historyList,
|
histories: state.historyPage,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mapDispatchToProps(dispatch: Dispatch<any>, ownProps?: any): HistoryDispatchProps {
|
export function mapDispatchToProps(dispatch: Dispatch<any>, ownProps?: any): HistoryDispatchProps {
|
||||||
return {
|
return {
|
||||||
onReadAllByProbe: (probe: Probe) => {
|
onReadAllByProbe: (probe: Probe, pageNo: string, countPerPage: string) => {
|
||||||
dispatch(asyncRequestActions.request('HistoryService', 'readAllByProbe', readAllByProbeActions.REQUEST, JSON.stringify(probe)));
|
dispatch(asyncRequestActions.request('HistoryService', 'readAllByProbe', readAllByProbeActions.REQUEST,
|
||||||
|
JSON.stringify(probe), pageNo, countPerPage));
|
||||||
},
|
},
|
||||||
// onRedirectHome: () => {
|
// onRedirectHome: () => {
|
||||||
// dispatch(routerPush('/'));
|
// dispatch(routerPush('/'));
|
||||||
|
|
|
@ -6,17 +6,17 @@ import History from '@overflow/history/api/model/History';
|
||||||
|
|
||||||
export interface StateProps {
|
export interface StateProps {
|
||||||
probeId: string;
|
probeId: string;
|
||||||
histories: History[];
|
histories: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DispatchProps {
|
export interface DispatchProps {
|
||||||
onReadAllByProbe?(probe: Probe): void;
|
onReadAllByProbe?(probe: Probe, pageNo: string, countPerPage: string): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Props = StateProps & DispatchProps;
|
export type Props = StateProps & DispatchProps;
|
||||||
|
|
||||||
export interface State {
|
export interface State {
|
||||||
|
page: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class HistoryList extends React.Component<Props, State> {
|
export class HistoryList extends React.Component<Props, State> {
|
||||||
|
@ -25,6 +25,7 @@ export class HistoryList 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 = {
|
||||||
|
page: 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +33,39 @@ export class HistoryList extends React.Component<Props, State> {
|
||||||
let probe: Probe = {
|
let probe: Probe = {
|
||||||
id: Number(1),
|
id: Number(1),
|
||||||
};
|
};
|
||||||
this.props.onReadAllByProbe(probe);
|
this.props.onReadAllByProbe(probe, String(this.state.page), '10');
|
||||||
|
}
|
||||||
|
|
||||||
|
public handlePaging = (pageNo: number) => {
|
||||||
|
if(pageNo === this.state.page) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.setState({
|
||||||
|
page: pageNo,
|
||||||
|
});
|
||||||
|
let probe: Probe = {
|
||||||
|
id: Number(1),
|
||||||
|
};
|
||||||
|
this.props.onReadAllByProbe(probe, String(pageNo), '10');
|
||||||
|
}
|
||||||
|
|
||||||
|
public renderPagination = (pageObj: any): (JSX.Element | JSX.Element[]) => {
|
||||||
|
if (pageObj === undefined) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
let totalPage = pageObj.totalPages;
|
||||||
|
let currPage = pageObj.number;
|
||||||
|
let elems = new Array;
|
||||||
|
for (let i = 0; i < totalPage; i++) {
|
||||||
|
if (i === currPage) {
|
||||||
|
elems.push(<Menu.Item key={i} active as='a' onClick={this.handlePaging.bind(this, i)}>{i + 1}</Menu.Item>);
|
||||||
|
} else {
|
||||||
|
elems.push(<Menu.Item key={i} as='a' onClick={this.handlePaging.bind(this, i)}>{i + 1}</Menu.Item>);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return <Menu floated='right' pagination>
|
||||||
|
{elems}
|
||||||
|
</Menu>;
|
||||||
}
|
}
|
||||||
|
|
||||||
public render(): JSX.Element {
|
public render(): JSX.Element {
|
||||||
|
@ -51,7 +84,7 @@ export class HistoryList extends React.Component<Props, State> {
|
||||||
</Table.Header>
|
</Table.Header>
|
||||||
|
|
||||||
<Table.Body>
|
<Table.Body>
|
||||||
{this.props.histories ? this.props.histories.map((history: History, index: number) => (
|
{this.props.histories && this.props.histories.content ? this.props.histories.content.map((history: History, index: number) => (
|
||||||
<Table.Row key={index} >
|
<Table.Row key={index} >
|
||||||
<Table.Cell textAlign={'center'}>{index + 1}</Table.Cell>
|
<Table.Cell textAlign={'center'}>{index + 1}</Table.Cell>
|
||||||
<Table.Cell textAlign={'center'}>
|
<Table.Cell textAlign={'center'}>
|
||||||
|
@ -72,18 +105,7 @@ export class HistoryList extends React.Component<Props, State> {
|
||||||
<Table.Footer>
|
<Table.Footer>
|
||||||
<Table.Row>
|
<Table.Row>
|
||||||
<Table.HeaderCell colSpan='3'>
|
<Table.HeaderCell colSpan='3'>
|
||||||
<Menu floated='right' pagination>
|
{this.renderPagination(this.props.histories)}
|
||||||
<Menu.Item as='a' icon>
|
|
||||||
<Icon name='left chevron' />
|
|
||||||
</Menu.Item>
|
|
||||||
<Menu.Item as='a'>1</Menu.Item>
|
|
||||||
<Menu.Item as='a'>2</Menu.Item>
|
|
||||||
<Menu.Item as='a'>3</Menu.Item>
|
|
||||||
<Menu.Item as='a'>4</Menu.Item>
|
|
||||||
<Menu.Item as='a' icon>
|
|
||||||
<Icon name='right chevron' />
|
|
||||||
</Menu.Item>
|
|
||||||
</Menu>
|
|
||||||
</Table.HeaderCell>
|
</Table.HeaderCell>
|
||||||
</Table.Row>
|
</Table.Row>
|
||||||
</Table.Footer>
|
</Table.Footer>
|
||||||
|
|
|
@ -8,11 +8,11 @@ import ReadAllByProbeState, { defaultState as ReadAllByProbeDefaultState } from
|
||||||
|
|
||||||
const reducer: ReducersMapObject = {
|
const reducer: ReducersMapObject = {
|
||||||
[ReadAllByProbeActionTypes.REQUEST_SUCCESS]:
|
[ReadAllByProbeActionTypes.REQUEST_SUCCESS]:
|
||||||
(state: ReadAllByProbeState = ReadAllByProbeDefaultState, action: Action<History[]>):
|
(state: ReadAllByProbeState = ReadAllByProbeDefaultState, action: Action<object>):
|
||||||
ReadAllByProbeState => {
|
ReadAllByProbeState => {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
historyList: <History[]>action.payload,
|
historyPage: action.payload,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
[ReadAllByProbeActionTypes.REQUEST_FAILURE]:
|
[ReadAllByProbeActionTypes.REQUEST_FAILURE]:
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import History from '../../api/model/History';
|
import History from '../../api/model/History';
|
||||||
|
|
||||||
export interface State {
|
export interface State {
|
||||||
readonly historyList?: History[];
|
readonly historyPage?: object;
|
||||||
readonly error?: Error;
|
readonly error?: Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultState: State = {
|
export const defaultState: State = {
|
||||||
historyList: undefined,
|
historyPage: undefined,
|
||||||
error: undefined,
|
error: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user