target infra paging sorting
This commit is contained in:
parent
1e387df380
commit
7f5b47ba67
|
@ -10,6 +10,8 @@ import Domain from '@overflow/domain/api/model/Domain';
|
||||||
import * as targetListActions from '../redux/action/read_all_by_probe';
|
import * as targetListActions from '../redux/action/read_all_by_probe';
|
||||||
import { push as routerPush } from 'react-router-redux';
|
import { push as routerPush } from 'react-router-redux';
|
||||||
import * as asyncRequestActions from '@overflow/commons/redux/action/asyncRequest';
|
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 {
|
export function mapStateToProps(state: any, props: any): StateProps {
|
||||||
return {
|
return {
|
||||||
|
@ -20,13 +22,13 @@ export function mapStateToProps(state: any, props: any): StateProps {
|
||||||
|
|
||||||
export function mapDispatchToProps(dispatch: Dispatch<any>): DispatchProps {
|
export function mapDispatchToProps(dispatch: Dispatch<any>): DispatchProps {
|
||||||
return {
|
return {
|
||||||
onReadAllByProbe: (probe: Probe, pageNo: string, countPerPage: string) => {
|
onReadAllByProbe: (probe: Probe, pageParams: PageParams) => {
|
||||||
dispatch(asyncRequestActions.request('InfraService', 'readAllByProbe', targetListActions.REQUEST,
|
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,
|
dispatch(asyncRequestActions.request('InfraService', 'readAllByDomain', targetListActions.REQUEST,
|
||||||
JSON.stringify(domain), pageNo, countPerPage));
|
JSON.stringify(domain), JSON.stringify(pageParams)));
|
||||||
},
|
},
|
||||||
onTargetSelection: (infraId: string) => {
|
onTargetSelection: (infraId: string) => {
|
||||||
dispatch(routerPush('/target/' + infraId));
|
dispatch(routerPush('/target/' + infraId));
|
||||||
|
|
|
@ -10,15 +10,19 @@ import Host from '@overflow/discovery/api/model/Host';
|
||||||
import Page from '@overflow/commons/api/model/Page';
|
import Page from '@overflow/commons/api/model/Page';
|
||||||
import { Pager } from '@overflow/commons/react/component/Pager';
|
import { Pager } from '@overflow/commons/react/component/Pager';
|
||||||
import * as Utils from '@overflow/commons/util/Utils';
|
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 {
|
export interface StateProps {
|
||||||
probeId?: string;
|
probeId?: string;
|
||||||
infraList?: Page;
|
infraList?: Page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export interface DispatchProps {
|
export interface DispatchProps {
|
||||||
onReadAllByProbe?(probe: Probe, pageNo: string, countPerPage: string): void;
|
onReadAllByProbe?(probe: Probe, pageParams: PageParams): void;
|
||||||
onReadAllByDomain?(domain: Domain, pageNo: string, countPerPage: string): void;
|
onReadAllByDomain?(domain: Domain, pageParams: PageParams): void;
|
||||||
onTargetSelection?(id: string): void;
|
onTargetSelection?(id: string): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +36,10 @@ export interface State {
|
||||||
export class TargetList extends React.Component<Props, State> {
|
export class TargetList extends React.Component<Props, State> {
|
||||||
|
|
||||||
private countPerPage: number = 10;
|
private countPerPage: number = 10;
|
||||||
|
private sortCol: string = 'id';
|
||||||
|
private sortDirection: string = 'descending';
|
||||||
|
private pageNo: number = 0;
|
||||||
|
|
||||||
constructor(props: Props, context: State) {
|
constructor(props: Props, context: State) {
|
||||||
super(props, context);
|
super(props, context);
|
||||||
this.state = {
|
this.state = {
|
||||||
|
@ -41,21 +49,28 @@ export class TargetList extends React.Component<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentWillMount(): void {
|
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) {
|
if (this.props.probeId === undefined) {
|
||||||
// FIXME: get domain
|
// FIXME: get domain
|
||||||
let domain: Domain = {
|
let domain: Domain = {
|
||||||
id: 1,
|
id: 1,
|
||||||
};
|
};
|
||||||
this.props.onReadAllByDomain(domain, String(pageNo), String(this.countPerPage));
|
this.props.onReadAllByDomain(domain, pageParams);
|
||||||
} else {
|
} else {
|
||||||
let probe: Probe = {
|
let probe: Probe = {
|
||||||
id: Number(this.props.probeId),
|
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<Props, State> {
|
||||||
public onRefreshList = () => {
|
public onRefreshList = () => {
|
||||||
console.log('onRefreshList');
|
console.log('onRefreshList');
|
||||||
this.setState({ openAddTarget: false });
|
this.setState({ openAddTarget: false });
|
||||||
this.getTargetList(0);
|
this.getTargetList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public handlePaging = (pageNo: number) => {
|
public handlePaging = (pageNo: number) => {
|
||||||
this.getTargetList(pageNo);
|
this.pageNo = pageNo;
|
||||||
|
this.getTargetList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public handleFilter(filterStr: string): void {
|
public handleFilter(filterStr: string): void {
|
||||||
|
@ -114,6 +130,13 @@ export class TargetList extends React.Component<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public render(): JSX.Element {
|
public render(): JSX.Element {
|
||||||
|
let colsmap: Map<string, string> = 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) {
|
if (this.props.infraList === undefined) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -121,15 +144,16 @@ export class TargetList extends React.Component<Props, State> {
|
||||||
<Container fluid>
|
<Container fluid>
|
||||||
<Button content='Discovery' icon='search' labelPosition='left' floated='right' positive onClick={this.handleAddTarget.bind(this)} />
|
<Button content='Discovery' icon='search' labelPosition='left' floated='right' positive onClick={this.handleAddTarget.bind(this)} />
|
||||||
<br /><br />
|
<br /><br />
|
||||||
<Table celled selectable striped>
|
<Table celled selectable striped sortable>
|
||||||
<Table.Header>
|
<Table.Header>
|
||||||
<Table.Row>
|
<SortTableHeaderRow columnMap={colsmap} onHeaderColumnClick={this.handleSort} />
|
||||||
|
{/* <Table.Row>
|
||||||
<Table.HeaderCell textAlign={'center'}>No</Table.HeaderCell>
|
<Table.HeaderCell textAlign={'center'}>No</Table.HeaderCell>
|
||||||
<Table.HeaderCell textAlign={'center'}>Type</Table.HeaderCell>
|
<Table.HeaderCell textAlign={'center'}>Type</Table.HeaderCell>
|
||||||
<Table.HeaderCell textAlign={'center'}>Name</Table.HeaderCell>
|
<Table.HeaderCell textAlign={'center'}>Name</Table.HeaderCell>
|
||||||
<Table.HeaderCell textAlign={'center'} collapsing>Sensor Count</Table.HeaderCell>
|
<Table.HeaderCell textAlign={'center'} collapsing>Sensor Count</Table.HeaderCell>
|
||||||
<Table.HeaderCell textAlign={'center'}>Created at</Table.HeaderCell>
|
<Table.HeaderCell textAlign={'center'}>Created at</Table.HeaderCell>
|
||||||
</Table.Row>
|
</Table.Row> */}
|
||||||
</Table.Header>
|
</Table.Header>
|
||||||
|
|
||||||
<Table.Body>
|
<Table.Body>
|
||||||
|
@ -172,5 +196,12 @@ export class TargetList extends React.Component<Props, State> {
|
||||||
|
|
||||||
this.props.onTargetSelection(String(infra.id));
|
this.props.onTargetSelection(String(infra.id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private handleSort = (col: string, direction: string): void => {
|
||||||
|
console.log(col + ' || direction:' + direction);
|
||||||
|
this.sortCol = col;
|
||||||
|
this.sortDirection = direction;
|
||||||
|
this.getTargetList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,18 +4,19 @@ import Infra from '@overflow/infra/api/model/Infra';
|
||||||
|
|
||||||
import * as ReadAllByDomainActionTypes from '../action/read_all_by_domain';
|
import * as ReadAllByDomainActionTypes from '../action/read_all_by_domain';
|
||||||
import ReadAllByDomainState, { defaultState as ReadAllByDomainDefaultState } from '../state/ReadAllByDomain';
|
import ReadAllByDomainState, { defaultState as ReadAllByDomainDefaultState } from '../state/ReadAllByDomain';
|
||||||
|
import Page from '@overflow/commons/api/model/Page';
|
||||||
|
|
||||||
const reducer: ReducersMapObject = {
|
const reducer: ReducersMapObject = {
|
||||||
[ReadAllByDomainActionTypes.REQUEST_SUCCESS]:
|
[ReadAllByDomainActionTypes.REQUEST_SUCCESS]:
|
||||||
(state: ReadAllByDomainState = ReadAllByDomainDefaultState, action: Action<Infra>):
|
(state: ReadAllByDomainState = ReadAllByDomainDefaultState, action: Action<Page>):
|
||||||
ReadAllByDomainState => {
|
ReadAllByDomainState => {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
infraList: <Infra[]>action.payload,
|
infraList: <Page>action.payload,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
[ReadAllByDomainActionTypes.REQUEST_FAILURE]:
|
[ReadAllByDomainActionTypes.REQUEST_FAILURE]:
|
||||||
(state: ReadAllByDomainState = ReadAllByDomainDefaultState, action: Action<Infra>):
|
(state: ReadAllByDomainState = ReadAllByDomainDefaultState, action: Action<Error>):
|
||||||
ReadAllByDomainState => {
|
ReadAllByDomainState => {
|
||||||
return state;
|
return state;
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import Infra from '@overflow/infra/api/model/Infra';
|
import Page from '@overflow/commons/api/model/Page';
|
||||||
|
|
||||||
export interface State {
|
export interface State {
|
||||||
readonly infraList?: Infra[];
|
readonly infraList?: Page;
|
||||||
readonly error?: Error;
|
readonly error?: Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user