Skip to content

Commit d2715f8

Browse files
committed
Added utilities for pagination.
1 parent 9410dc7 commit d2715f8

File tree

3 files changed

+80
-7
lines changed

3 files changed

+80
-7
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import styled from "styled-components";
2+
import { Pagination } from "antd";
3+
4+
const PaginationLayout = styled(Pagination)`
5+
display: flex;
6+
justify-content: center;
7+
margin-top: 40px;
8+
margin-bottom: 20px;
9+
`;
10+
11+
interface PaginationCompProps {
12+
setCurrentPage: (page: number) => void;
13+
setPageSize: (size: number) => void;
14+
currentPage: number;
15+
pageSize: number;
16+
total: number;
17+
}
18+
19+
const PaginationComp = (props: PaginationCompProps) => {
20+
const {
21+
setCurrentPage,
22+
setPageSize,
23+
currentPage,
24+
pageSize,
25+
total,
26+
} = props;
27+
28+
const handlePageChange = (page: number, pageSize: number | undefined) => {
29+
if (setCurrentPage) {
30+
setCurrentPage(page);
31+
}
32+
};
33+
34+
const handlePageSizeChange = (current: number, size: number) => {
35+
if (setPageSize) {
36+
setPageSize(size);
37+
}
38+
};
39+
40+
return (
41+
<PaginationLayout
42+
current={currentPage}
43+
pageSize={pageSize}
44+
onChange={handlePageChange}
45+
onShowSizeChange={handlePageSizeChange}
46+
total={total}
47+
showSizeChanger
48+
/>
49+
);
50+
};
51+
52+
export default PaginationComp;

client/packages/lowcoder/src/util/pagination/axios.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { FolderApi } from "@lowcoder-ee/api/folderApi";
2-
import { FetchFolderElementsPaginationPayload } from "@lowcoder-ee/redux/reduxActions/folderActions";
3-
import {
4-
FetchApplicationElementsPaginationPayload,
5-
} from "@lowcoder-ee/redux/reduxActions/applicationActions";
62
import ApplicationApi from "@lowcoder-ee/api/applicationApi";
3+
import {fetchAppRequestType, fetchFolderRequestType} from "@lowcoder-ee/util/pagination/type";
74

8-
export const fetchFolderElements = async (request: FetchFolderElementsPaginationPayload) => {
5+
6+
7+
export const fetchFolderElements = async (request: fetchFolderRequestType) => {
98
try {
109
const response = await FolderApi.fetchFolderElementsPagination(request);
1110
return {
@@ -23,7 +22,7 @@ export const fetchFolderElements = async (request: FetchFolderElementsPagination
2322
}
2423

2524

26-
export const fetchApplicationElements = async (request: FetchApplicationElementsPaginationPayload)=> {
25+
export const fetchApplicationElements = async (request: fetchAppRequestType)=> {
2726
try {
2827
const response = await ApplicationApi.fetchAllApplicationsPagination(request);
2928
return {

client/packages/lowcoder/src/util/pagination/type.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,26 @@ export const ApplicationPaginationType: ApplicationType = {
1111
4: "FOLDER",
1212
6: "MOBILETABLAYOUT",
1313
7: "NAVIGATION",
14-
};
14+
};
15+
16+
export interface fetchAppRequestType {
17+
pageNum?: number;
18+
pageSize?: number;
19+
name?: string;
20+
applicationType?: number;
21+
}
22+
23+
export interface fetchFolderRequestType {
24+
pageNum?: number;
25+
pageSize?: number;
26+
name?: string;
27+
applicationType?: string;
28+
}
29+
30+
export interface GenericApiPaginationResponse<T> {
31+
total: number;
32+
success: boolean;
33+
code: number;
34+
message: string;
35+
data: T;
36+
}

0 commit comments

Comments
 (0)