diff --git a/src/ts/@overflow/history/api/model/_ b/src/ts/@overflow/history/api/model/_ deleted file mode 100644 index e69de29..0000000 diff --git a/src/ts/@overflow/history/react/HistoryList.tsx b/src/ts/@overflow/history/react/HistoryList.tsx index 7ce0599..b6869c6 100644 --- a/src/ts/@overflow/history/react/HistoryList.tsx +++ b/src/ts/@overflow/history/react/HistoryList.tsx @@ -13,14 +13,15 @@ import * as readAllByProbeActions from '../redux/action/read_all_by_probe'; export function mapStateToProps(state: any, ownProps?: any): HistoryStateProps { return { probeId: '1', - histories: state.historyList, + histories: state.historyPage, }; } export function mapDispatchToProps(dispatch: Dispatch, ownProps?: any): HistoryDispatchProps { return { - onReadAllByProbe: (probe: Probe) => { - dispatch(asyncRequestActions.request('HistoryService', 'readAllByProbe', readAllByProbeActions.REQUEST, JSON.stringify(probe))); + onReadAllByProbe: (probe: Probe, pageNo: string, countPerPage: string) => { + dispatch(asyncRequestActions.request('HistoryService', 'readAllByProbe', readAllByProbeActions.REQUEST, + JSON.stringify(probe), pageNo, countPerPage)); }, // onRedirectHome: () => { // dispatch(routerPush('/')); diff --git a/src/ts/@overflow/history/react/components/HistoryList.tsx b/src/ts/@overflow/history/react/components/HistoryList.tsx index b1f2591..dbc5df5 100644 --- a/src/ts/@overflow/history/react/components/HistoryList.tsx +++ b/src/ts/@overflow/history/react/components/HistoryList.tsx @@ -6,17 +6,17 @@ import History from '@overflow/history/api/model/History'; export interface StateProps { probeId: string; - histories: History[]; + histories: any; } export interface DispatchProps { - onReadAllByProbe?(probe: Probe): void; + onReadAllByProbe?(probe: Probe, pageNo: string, countPerPage: string): void; } export type Props = StateProps & DispatchProps; export interface State { - + page: number; } export class HistoryList extends React.Component { @@ -25,6 +25,7 @@ export class HistoryList extends React.Component { constructor(props: Props, context: State) { super(props, context); this.state = { + page: 0, }; } @@ -32,7 +33,39 @@ export class HistoryList extends React.Component { let probe: Probe = { 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({i + 1}); + } else { + elems.push({i + 1}); + } + } + return + {elems} + ; } public render(): JSX.Element { @@ -51,7 +84,7 @@ export class HistoryList extends React.Component { - {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) => ( {index + 1} @@ -72,18 +105,7 @@ export class HistoryList extends React.Component { - - - - - 1 - 2 - 3 - 4 - - - - + {this.renderPagination(this.props.histories)} diff --git a/src/ts/@overflow/history/redux/reducer/read_all_by_probe.ts b/src/ts/@overflow/history/redux/reducer/read_all_by_probe.ts index 1c3a214..b4a45f6 100644 --- a/src/ts/@overflow/history/redux/reducer/read_all_by_probe.ts +++ b/src/ts/@overflow/history/redux/reducer/read_all_by_probe.ts @@ -8,11 +8,11 @@ import ReadAllByProbeState, { defaultState as ReadAllByProbeDefaultState } from const reducer: ReducersMapObject = { [ReadAllByProbeActionTypes.REQUEST_SUCCESS]: - (state: ReadAllByProbeState = ReadAllByProbeDefaultState, action: Action): + (state: ReadAllByProbeState = ReadAllByProbeDefaultState, action: Action): ReadAllByProbeState => { return { ...state, - historyList: action.payload, + historyPage: action.payload, }; }, [ReadAllByProbeActionTypes.REQUEST_FAILURE]: diff --git a/src/ts/@overflow/history/redux/state/ReadAllByProbe.ts b/src/ts/@overflow/history/redux/state/ReadAllByProbe.ts index da909bb..87a2f80 100644 --- a/src/ts/@overflow/history/redux/state/ReadAllByProbe.ts +++ b/src/ts/@overflow/history/redux/state/ReadAllByProbe.ts @@ -1,12 +1,12 @@ import History from '../../api/model/History'; export interface State { - readonly historyList?: History[]; + readonly historyPage?: object; readonly error?: Error; } export const defaultState: State = { - historyList: undefined, + historyPage: undefined, error: undefined, };