From a03599f16e7673e89e62e22111fdcbe4aa331b1b Mon Sep 17 00:00:00 2001 From: insanity Date: Mon, 28 Aug 2017 12:45:06 +0900 Subject: [PATCH] sort and paging --- .../history/react/components/HistoryList.tsx | 72 +++++++++---------- 1 file changed, 33 insertions(+), 39 deletions(-) diff --git a/src/ts/@overflow/history/react/components/HistoryList.tsx b/src/ts/@overflow/history/react/components/HistoryList.tsx index f346685..a9edbcd 100644 --- a/src/ts/@overflow/history/react/components/HistoryList.tsx +++ b/src/ts/@overflow/history/react/components/HistoryList.tsx @@ -30,20 +30,20 @@ export interface DispatchProps { export type Props = StateProps & DispatchProps; export interface State { - isTypedHistory: boolean; } export class HistoryList extends React.Component { - private countPerPage: number = 10; private selectedProbeId: number = 0; - private selectedTypeId: number = 0; + private isTypedHistory: boolean = false; + + private countPerPage: number = 10; + private sortCol: string = 'id'; + private sortDirection: string = 'descending'; + private pageNo: number = 0; constructor(props: Props, context: State) { super(props, context); - this.state = { - isTypedHistory: false, - }; } public componentWillMount(): void { @@ -54,24 +54,20 @@ export class HistoryList extends React.Component { // this.props.onReadAllMetaHistoryType(); if (this.props.path === '/histories') { - this.setState({ - isTypedHistory: false, - }); - this.getAllHistory(0); + this.isTypedHistory = false; + this.getAllHistory(); } else { - this.setState({ - isTypedHistory: true, - }); - this.getTypedHistory(0); + this.isTypedHistory = true; + this.getTypedHistory(); } } - public getAllHistory(pageNo: number): void { + public getAllHistory(): void { const pageParams: PageParams = { - pageNo: String(pageNo), - countPerPage: String(10), - sortCol: 'id', - sortDirection: 'descending', + pageNo: String(this.pageNo), + countPerPage: String(this.countPerPage), + sortCol: this.sortCol, + sortDirection: this.sortDirection, }; if (this.selectedProbeId === 0) { @@ -87,16 +83,16 @@ export class HistoryList extends React.Component { } } - public getTypedHistory(pageNo: number): void { + public getTypedHistory(): void { let url = this.props.path.split('/'); let probe: Probe = { id: url[2], }; const pageParams: PageParams = { - pageNo: String(pageNo), - countPerPage: String(10), - sortCol: 'id', - sortDirection: 'descending', + pageNo: String(this.pageNo), + countPerPage: String(this.countPerPage), + sortCol: this.sortCol, + sortDirection: this.sortDirection, }; this.props.onReadAllByProbeAndType(probe, this.getMetaType(url[1]), pageParams); } @@ -124,25 +120,23 @@ export class HistoryList extends React.Component { let probe: Probe = { id: Number(1), }; - if (this.state.isTypedHistory) { - this.getTypedHistory(pageNo); + this.pageNo = pageNo; + if (this.isTypedHistory) { + this.getTypedHistory(); } else { - this.getAllHistory(pageNo); + this.getAllHistory(); } } private handleSort = (col: string, direction: string): void => { console.log(col + ' || direction:' + direction); - const pageParams: PageParams = { - pageNo: String(0), - countPerPage: String(10), - sortCol: col, - sortDirection: direction, - }; - let domain: Domain = { - id: 1, - }; - this.props.onReadAllByDomain(domain, pageParams); + this.sortCol = col; + this.sortDirection = direction; + if (this.isTypedHistory) { + this.getTypedHistory(); + } else { + this.getAllHistory(); + } } public render(): JSX.Element { @@ -205,7 +199,7 @@ export class HistoryList extends React.Component { ); let filter = null; - if (!this.state.isTypedHistory) { + if (!this.isTypedHistory) { filter = ; @@ -221,7 +215,7 @@ export class HistoryList extends React.Component { private handleProbeChange = (probeId: number) => { this.selectedProbeId = probeId; - this.getAllHistory(0); + this.getAllHistory(); } }