Skip to content

Commit 7c9aaf0

Browse files
committed
Implemented pagination in User Group List.
1 parent d2715f8 commit 7c9aaf0

File tree

6 files changed

+90
-38
lines changed

6 files changed

+90
-38
lines changed

client/packages/lowcoder/src/api/orgApi.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
UpdateUserOrgRolePayload,
1111
} from "redux/reduxActions/orgActions";
1212
import { ApiResponse, GenericApiResponse } from "./apiResponses";
13+
import {GenericApiPaginationResponse, orgGroupRequestType} from "@lowcoder-ee/util/pagination/type";
1314

1415
export interface GroupUsersResponse extends ApiResponse {
1516
data: {
@@ -66,6 +67,10 @@ export class OrgApi extends Api {
6667
return Api.get(OrgApi.fetchGroupURL);
6768
}
6869

70+
static fetchGroupPagination(request: orgGroupRequestType): AxiosPromise<GenericApiPaginationResponse<OrgGroup[]>> {
71+
return Api.get(OrgApi.fetchGroupURL, {...request});
72+
}
73+
6974
static deleteGroup(groupId: string): AxiosPromise<ApiResponse> {
7075
return Api.delete(OrgApi.deleteGroupURL(groupId));
7176
}

client/packages/lowcoder/src/pages/ApplicationV2/HomeLayout.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@ export function HomeLayout(props: HomeLayoutProps) {
334334
setTypeFilterPagination,
335335

336336
} = props;
337-
console.log("elements", elements, total);
338337
const handlePageChange = (page: number) => {
339338
setCurrentPage(page);
340339
};

client/packages/lowcoder/src/pages/ApplicationV2/TrashView.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ export function TrashView() {
4545
<>
4646
<Helmet>{<title>{trans("home.trash")}</title>}</Helmet>
4747
<HomeLayout
48-
elements={elements.elements}
49-
breadcrumb={[{ text: trans("home.trash"), path: TRASH_URL }]}
50-
mode={"trash"}
51-
currentPage ={currentPage}
52-
setCurrentPage={setCurrentPage}
53-
pageSize={pageSize}
54-
setPageSize={setPageSize}
55-
total={elements.total}
56-
setSearchValues={setSearchValues}
57-
setTypeFilterPagination={setTypeFilter}
48+
elements={elements.elements}
49+
breadcrumb={[{ text: trans("home.trash"), path: TRASH_URL }]}
50+
mode={"trash"}
51+
currentPage ={currentPage}
52+
setCurrentPage={setCurrentPage}
53+
pageSize={pageSize}
54+
setPageSize={setPageSize}
55+
total={elements.total}
56+
setSearchValues={setSearchValues}
57+
setTypeFilterPagination={setTypeFilter}
5858
/>
5959
</>
6060
);

client/packages/lowcoder/src/pages/setting/permission/permissionList.tsx

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
} from "lowcoder-design";
2222
import styled from "styled-components";
2323
import { trans } from "i18n";
24-
import { getOrgGroups } from "redux/selectors/orgSelectors";
2524
import { Table } from "components/Table";
2625
import history from "util/history";
2726
import { Level1SettingPageContentWithList, Level1SettingPageTitleWithBtn } from "../styled";
@@ -32,6 +31,8 @@ import { OrgGroup } from "constants/orgConstants";
3231
import { messageInstance } from "lowcoder-design/src/components/GlobalInstances";
3332
import InviteDialog from "pages/common/inviteDialog";
3433
import { Flex } from "antd";
34+
import {fetchOrgGroups} from "@lowcoder-ee/util/pagination/axios";
35+
import PaginationComp from "@lowcoder-ee/util/pagination/Pagination";
3536

3637
const NEW_GROUP_PREFIX = trans("memberSettings.newGroupPrefix");
3738

@@ -51,17 +52,48 @@ type DataItemInfo = {
5152
group?: OrgGroup;
5253
};
5354

55+
interface ElementsState {
56+
elements: OrgGroup[];
57+
total: number;
58+
}
59+
5460
export default function PermissionSetting() {
61+
let dataSource: DataItemInfo[] = [];
5562
const user = useSelector(getUser);
5663
const orgId = user.currentOrgId;
57-
const orgGroups = useSelector(getOrgGroups);
58-
const visibleOrgGroups = orgGroups.filter((g) => !g.allUsersGroup);
59-
const allUsersGroup = orgGroups.find((g) => g.allUsersGroup);
6064
const dispatch = useDispatch();
6165
const [needRenameId, setNeedRenameId] = useState<string | undefined>(undefined);
6266
const { nameSuffixFunc, menuItemsFunc, menuExtraView } = usePermissionMenuItems(orgId);
6367
const [groupCreating, setGroupCreating] = useState(false);
68+
const [elements, setElements] = useState<ElementsState>({ elements: [], total: 0 });
69+
const [currentPage, setCurrentPage] = useState(1);
70+
const [pageSize, setPageSize] = useState(10);
6471

72+
useEffect( () => {
73+
fetchOrgGroups(
74+
{
75+
pageNum: currentPage,
76+
pageSize: pageSize,
77+
}
78+
).then(result => {
79+
if (result.success){
80+
setElements({elements: result.data || [], total: result.total || 1})
81+
}
82+
else
83+
console.error("ERROR: fetchFolderElements", result.error)
84+
})
85+
}, [currentPage, pageSize]
86+
)
87+
const visibleOrgGroups = elements.elements.filter((g) => !g.allUsersGroup);
88+
const allUsersGroup = elements.elements.find((g) => g.allUsersGroup);
89+
dataSource = currentPage === 1 ? [{
90+
key: "users",
91+
label: trans("memberSettings.allMembers"),
92+
createTime: allUsersGroup?.createTime,
93+
lock: true,
94+
del: false,
95+
rename: false,
96+
}] : [];
6597
useEffect(() => {
6698
if (!orgId) {
6799
return;
@@ -105,17 +137,6 @@ export default function PermissionSetting() {
105137
});
106138
};
107139

108-
const dataSource: DataItemInfo[] = [
109-
{
110-
key: "users",
111-
label: trans("memberSettings.allMembers"),
112-
createTime: allUsersGroup?.createTime,
113-
lock: true,
114-
del: false,
115-
rename: false,
116-
},
117-
];
118-
119140
visibleOrgGroups.forEach((group) => {
120141
dataSource.push({
121142
key: group.groupId,
@@ -255,6 +276,13 @@ export default function PermissionSetting() {
255276
/>
256277
</div>
257278
{menuExtraView}
279+
<PaginationComp
280+
currentPage={currentPage}
281+
pageSize={pageSize}
282+
setPageSize={setPageSize}
283+
setCurrentPage={setCurrentPage}
284+
total={elements.total}
285+
/>
258286
</Level1SettingPageContentWithList>
259287
);
260288
}

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { FolderApi } from "@lowcoder-ee/api/folderApi";
22
import ApplicationApi from "@lowcoder-ee/api/applicationApi";
3-
import {fetchAppRequestType, fetchFolderRequestType} from "@lowcoder-ee/util/pagination/type";
4-
5-
3+
import {fetchAppRequestType, fetchFolderRequestType, orgGroupRequestType} from "@lowcoder-ee/util/pagination/type";
4+
import OrgApi from "@lowcoder-ee/api/orgApi";
65

76
export const fetchFolderElements = async (request: fetchFolderRequestType) => {
87
try {
@@ -21,7 +20,6 @@ export const fetchFolderElements = async (request: fetchFolderRequestType) => {
2120
}
2221
}
2322

24-
2523
export const fetchApplicationElements = async (request: fetchAppRequestType)=> {
2624
try {
2725
const response = await ApplicationApi.fetchAllApplicationsPagination(request);
@@ -37,4 +35,22 @@ export const fetchApplicationElements = async (request: fetchAppRequestType)=> {
3735
error: error
3836
};
3937
}
38+
}
39+
40+
export const fetchOrgGroups = async (request: orgGroupRequestType) => {
41+
try{
42+
const response = await OrgApi.fetchGroupPagination(request);
43+
return {
44+
success: true,
45+
data:response.data.data,
46+
total:response.data.total
47+
}
48+
}
49+
catch (error: any) {
50+
console.error('Failed to fetch data:', error);
51+
return {
52+
success: false,
53+
error: error
54+
};
55+
}
4056
}

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ type ApplicationType = {
22
[key: number]: string; // This allows numeric indexing
33
};
44

5-
// Define the const with explicit type
5+
export interface GenericApiPaginationResponse<T> {
6+
total: number;
7+
success: boolean;
8+
code: number;
9+
message: string;
10+
data: T;
11+
}
12+
613
export const ApplicationPaginationType: ApplicationType = {
714
0: "",
815
1: "APPLICATION",
@@ -27,10 +34,7 @@ export interface fetchFolderRequestType {
2734
applicationType?: string;
2835
}
2936

30-
export interface GenericApiPaginationResponse<T> {
31-
total: number;
32-
success: boolean;
33-
code: number;
34-
message: string;
35-
data: T;
36-
}
37+
export interface orgGroupRequestType{
38+
pageNum?: number;
39+
pageSize?: number;
40+
}

0 commit comments

Comments
 (0)