sort and paging

This commit is contained in:
insanity 2017-08-28 12:45:06 +09:00
parent d2d35b91ea
commit a03599f16e

View File

@ -30,20 +30,20 @@ export interface DispatchProps {
export type Props = StateProps & DispatchProps;
export interface State {
isTypedHistory: boolean;
}
export class HistoryList extends React.Component<Props, State> {
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<Props, State> {
// 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<Props, State> {
}
}
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<Props, State> {
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<Props, State> {
);
let filter = null;
if (!this.state.isTypedHistory) {
if (!this.isTypedHistory) {
filter = <HistoryFilter probes={this.props.probes}
onProbeChange={this.handleProbeChange}
/>;
@ -221,7 +215,7 @@ export class HistoryList extends React.Component<Props, State> {
private handleProbeChange = (probeId: number) => {
this.selectedProbeId = probeId;
this.getAllHistory(0);
this.getAllHistory();
}
}