|
@@ -40,6 +40,13 @@ const Footer = styled.div<any>`
|
|
|
`;
|
|
`;
|
|
|
|
|
|
|
|
type DictItem = { value: string; label: string };
|
|
type DictItem = { value: string; label: string };
|
|
|
|
|
+export type ApiPaginationProps = {
|
|
|
|
|
+ currentPage: number;
|
|
|
|
|
+ hasNextPage: boolean;
|
|
|
|
|
+ itemsPerPage: number;
|
|
|
|
|
+ onPageChange: (page: number) => void;
|
|
|
|
|
+ onItemsPerPageChange: (event: React.ChangeEvent<HTMLSelectElement>) => void;
|
|
|
|
|
+};
|
|
|
type Props = {
|
|
type Props = {
|
|
|
items: any[];
|
|
items: any[];
|
|
|
dropdownActions?: DropdownAction[];
|
|
dropdownActions?: DropdownAction[];
|
|
@@ -67,6 +74,7 @@ type Props = {
|
|
|
listHeaderComponent?: React.ReactNode;
|
|
listHeaderComponent?: React.ReactNode;
|
|
|
itemsPerPageOptions?: number[];
|
|
itemsPerPageOptions?: number[];
|
|
|
initialItemsPerPage?: number;
|
|
initialItemsPerPage?: number;
|
|
|
|
|
+ apiPagination?: ApiPaginationProps;
|
|
|
};
|
|
};
|
|
|
type State = {
|
|
type State = {
|
|
|
items: any[];
|
|
items: any[];
|
|
@@ -137,6 +145,9 @@ class FilterList extends React.Component<Props, State> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
get paginatedItems() {
|
|
get paginatedItems() {
|
|
|
|
|
+ if (this.props.apiPagination) {
|
|
|
|
|
+ return this.state.items;
|
|
|
|
|
+ }
|
|
|
let paginatedItems = this.state.items;
|
|
let paginatedItems = this.state.items;
|
|
|
if (paginatedItems.length > this.state.itemsPerPage) {
|
|
if (paginatedItems.length > this.state.itemsPerPage) {
|
|
|
paginatedItems = this.state.items.filter(
|
|
paginatedItems = this.state.items.filter(
|
|
@@ -259,12 +270,20 @@ class FilterList extends React.Component<Props, State> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
handlePageClick = (page: number) => {
|
|
handlePageClick = (page: number) => {
|
|
|
- this.setPageAndItemsPerPage(page);
|
|
|
|
|
|
|
+ if (this.props.apiPagination) {
|
|
|
|
|
+ this.props.apiPagination.onPageChange(page);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.setPageAndItemsPerPage(page);
|
|
|
|
|
+ }
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
handleItemsPerPageChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
|
|
handleItemsPerPageChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
|
|
|
- const itemsPerPage = parseInt(event.target.value, 10);
|
|
|
|
|
- this.setPageAndItemsPerPage(1, itemsPerPage);
|
|
|
|
|
|
|
+ if (this.props.apiPagination) {
|
|
|
|
|
+ this.props.apiPagination.onItemsPerPageChange(event);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const itemsPerPage = parseInt(event.target.value, 10);
|
|
|
|
|
+ this.setPageAndItemsPerPage(1, itemsPerPage);
|
|
|
|
|
+ }
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
getFooterText() {
|
|
getFooterText() {
|
|
@@ -278,6 +297,27 @@ class FilterList extends React.Component<Props, State> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
renderPagination() {
|
|
renderPagination() {
|
|
|
|
|
+ const { apiPagination } = this.props;
|
|
|
|
|
+
|
|
|
|
|
+ if (apiPagination) {
|
|
|
|
|
+ const { currentPage, hasNextPage, itemsPerPage } = apiPagination;
|
|
|
|
|
+ const apiItemsCount = hasNextPage
|
|
|
|
|
+ ? (currentPage + 1) * itemsPerPage
|
|
|
|
|
+ : currentPage * itemsPerPage;
|
|
|
|
|
+ return (
|
|
|
|
|
+ <NumberedPagination
|
|
|
|
|
+ itemsCount={apiItemsCount}
|
|
|
|
|
+ currentPage={currentPage}
|
|
|
|
|
+ itemsPerPage={itemsPerPage}
|
|
|
|
|
+ hasNextPage={hasNextPage}
|
|
|
|
|
+ style={{ margin: "0 5px" }}
|
|
|
|
|
+ onPageChange={this.handlePageClick}
|
|
|
|
|
+ onItemsPerPageChange={this.handleItemsPerPageChange}
|
|
|
|
|
+ itemsPerPageOptions={this.props.itemsPerPageOptions || [25, 50, 100]}
|
|
|
|
|
+ />
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if (this.state.items.length === 0) {
|
|
if (this.state.items.length === 0) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
@@ -336,7 +376,9 @@ class FilterList extends React.Component<Props, State> {
|
|
|
showEmptyList={
|
|
showEmptyList={
|
|
|
this.state.items.length === 0 &&
|
|
this.state.items.length === 0 &&
|
|
|
this.state.filterStatus === "all" &&
|
|
this.state.filterStatus === "all" &&
|
|
|
- this.state.filterText === ""
|
|
|
|
|
|
|
+ this.state.filterText === "" &&
|
|
|
|
|
+ (!this.props.apiPagination ||
|
|
|
|
|
+ this.props.apiPagination.currentPage === 1)
|
|
|
}
|
|
}
|
|
|
emptyListImage={this.props.emptyListImage}
|
|
emptyListImage={this.props.emptyListImage}
|
|
|
emptyListMessage={this.props.emptyListMessage}
|
|
emptyListMessage={this.props.emptyListMessage}
|
|
@@ -345,7 +387,7 @@ class FilterList extends React.Component<Props, State> {
|
|
|
emptyListComponent={this.props.emptyListComponent}
|
|
emptyListComponent={this.props.emptyListComponent}
|
|
|
onEmptyListButtonClick={this.props.onEmptyListButtonClick}
|
|
onEmptyListButtonClick={this.props.onEmptyListButtonClick}
|
|
|
/>
|
|
/>
|
|
|
- {this.state.items.length > 0 && (
|
|
|
|
|
|
|
+ {(this.state.items.length > 0 || this.props.apiPagination) && (
|
|
|
<Footer>
|
|
<Footer>
|
|
|
<div>{this.getFooterText()}</div>
|
|
<div>{this.getFooterText()}</div>
|
|
|
<div style={{ flex: 1, display: "flex", justifyContent: "center" }}>
|
|
<div style={{ flex: 1, display: "flex", justifyContent: "center" }}>
|