diff --git a/src/ts/@overflow/target/react/TargetList.tsx b/src/ts/@overflow/target/react/TargetList.tsx index c1f3faa..dddb15e 100644 --- a/src/ts/@overflow/target/react/TargetList.tsx +++ b/src/ts/@overflow/target/react/TargetList.tsx @@ -10,6 +10,8 @@ import Domain from '@overflow/domain/api/model/Domain'; import * as targetListActions from '../redux/action/read_all_by_probe'; import { push as routerPush } from 'react-router-redux'; import * as asyncRequestActions from '@overflow/commons/redux/action/asyncRequest'; +import PageParams from '@overflow/commons/api/model/PageParams'; + export function mapStateToProps(state: any, props: any): StateProps { return { @@ -20,13 +22,13 @@ export function mapStateToProps(state: any, props: any): StateProps { export function mapDispatchToProps(dispatch: Dispatch): DispatchProps { return { - onReadAllByProbe: (probe: Probe, pageNo: string, countPerPage: string) => { + onReadAllByProbe: (probe: Probe, pageParams: PageParams) => { dispatch(asyncRequestActions.request('InfraService', 'readAllByProbe', targetListActions.REQUEST, - JSON.stringify(probe), pageNo, countPerPage)); + JSON.stringify(probe), JSON.stringify(pageParams))); }, - onReadAllByDomain: (domain: Domain, pageNo: string, countPerPage: string) => { + onReadAllByDomain: (domain: Domain, pageParams: PageParams) => { dispatch(asyncRequestActions.request('InfraService', 'readAllByDomain', targetListActions.REQUEST, - JSON.stringify(domain), pageNo, countPerPage)); + JSON.stringify(domain), JSON.stringify(pageParams))); }, onTargetSelection: (infraId: string) => { dispatch(routerPush('/target/' + infraId)); diff --git a/src/ts/@overflow/target/react/components/TargetList.tsx b/src/ts/@overflow/target/react/components/TargetList.tsx index 0f934e9..043a184 100644 --- a/src/ts/@overflow/target/react/components/TargetList.tsx +++ b/src/ts/@overflow/target/react/components/TargetList.tsx @@ -10,15 +10,19 @@ import Host from '@overflow/discovery/api/model/Host'; import Page from '@overflow/commons/api/model/Page'; import { Pager } from '@overflow/commons/react/component/Pager'; import * as Utils from '@overflow/commons/util/Utils'; +import PageParams from '@overflow/commons/api/model/PageParams'; +import { SortTableHeaderRow } from '@overflow/commons/react/component/SortTableHeaderRow'; + export interface StateProps { probeId?: string; infraList?: Page; } + export interface DispatchProps { - onReadAllByProbe?(probe: Probe, pageNo: string, countPerPage: string): void; - onReadAllByDomain?(domain: Domain, pageNo: string, countPerPage: string): void; + onReadAllByProbe?(probe: Probe, pageParams: PageParams): void; + onReadAllByDomain?(domain: Domain, pageParams: PageParams): void; onTargetSelection?(id: string): void; } @@ -32,6 +36,10 @@ export interface State { export class TargetList extends React.Component { 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 = { @@ -41,21 +49,28 @@ export class TargetList extends React.Component { } public componentWillMount(): void { - this.getTargetList(0); + this.getTargetList(); } - public getTargetList(pageNo: number): void { + public getTargetList(): void { + const pageParams: PageParams = { + pageNo: String(this.pageNo), + countPerPage: String(this.countPerPage), + sortCol: this.sortCol, + sortDirection: this.sortDirection, + }; + if (this.props.probeId === undefined) { // FIXME: get domain let domain: Domain = { id: 1, }; - this.props.onReadAllByDomain(domain, String(pageNo), String(this.countPerPage)); + this.props.onReadAllByDomain(domain, pageParams); } else { let probe: Probe = { id: Number(this.props.probeId), }; - this.props.onReadAllByProbe(probe, String(pageNo), String(this.countPerPage)); + this.props.onReadAllByProbe(probe, pageParams); } } @@ -88,11 +103,12 @@ export class TargetList extends React.Component { public onRefreshList = () => { console.log('onRefreshList'); this.setState({ openAddTarget: false }); - this.getTargetList(0); + this.getTargetList(); } public handlePaging = (pageNo: number) => { - this.getTargetList(pageNo); + this.pageNo = pageNo; + this.getTargetList(); } public handleFilter(filterStr: string): void { @@ -114,6 +130,13 @@ export class TargetList extends React.Component { } public render(): JSX.Element { + let colsmap: Map = new Map(); + colsmap.set('No.', 'id'); + colsmap.set('Type', 'infraType.name'); + colsmap.set('Name', 'target.displayName'); + colsmap.set('Sensor Count', 'sensorCount'); + colsmap.set('Created at', 'createDate'); + if (this.props.infraList === undefined) { return null; } @@ -121,15 +144,16 @@ export class TargetList extends React.Component {