From 49759c1ebf04573c8f2ba35fbd135a1a686dd896 Mon Sep 17 00:00:00 2001 From: YANG QIA <2013xile@gmail.com> Date: Thu, 21 Mar 2024 20:44:06 +0800 Subject: [PATCH 1/2] fix(acl): bug when adding users to roles (#3783) * fix(acl): bug when adding users to roles * fix: bug --- .../plugin-acl/src/client/RolesMenu.tsx | 22 +++++++++++++++---- .../src/client/RoleUsersManager.tsx | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/plugins/@nocobase/plugin-acl/src/client/RolesMenu.tsx b/packages/plugins/@nocobase/plugin-acl/src/client/RolesMenu.tsx index 46ed56c2f..096df14f7 100644 --- a/packages/plugins/@nocobase/plugin-acl/src/client/RolesMenu.tsx +++ b/packages/plugins/@nocobase/plugin-acl/src/client/RolesMenu.tsx @@ -18,20 +18,30 @@ export const RolesMenu: React.FC & { Item: React.FC<{ item: any; onEdit: () => void }>; } = () => { const { t } = useACLTranslation(); - const { data, run, loading } = useResourceActionContext(); + const { data, mutate, loading } = useResourceActionContext(); const [visible, setVisible] = useState(false); const [record, setRecord] = useState(null); const { role, setRole } = useContext(RolesManagerContext); const [roles, setRoles] = useState([]); + const api = useAPIClient(); - const loadMore = useCallback(() => { + const loadMore = useCallback(async () => { const meta = data?.meta; if (!meta || meta.page >= meta.totalPage) { return; } - run({ + + const res = await api.resource('roles').list({ page: meta.page + 1, + pageSize: meta.pageSize, + filter: { + 'name.$ne': 'root', + }, + showAnonymous: true, + sort: ['createdAt'], + appends: [], }); + mutate(res?.data || {}); }, [data]); const { lastItem, setLastItem } = useLoadMoreObserver({ loadMore }); @@ -54,7 +64,11 @@ export const RolesMenu: React.FC & { const ref = React.createRef(); setLastItem(ref); - setRoles((prev) => prev.concat(data.data)); + if (data.meta?.page > 1) { + setRoles((prev) => prev.concat(data.data)); + } else { + setRoles(data.data); + } }, [data, setLastItem]); const items = useMemo( diff --git a/packages/plugins/@nocobase/plugin-users/src/client/RoleUsersManager.tsx b/packages/plugins/@nocobase/plugin-users/src/client/RoleUsersManager.tsx index a9831c136..db0b56876 100644 --- a/packages/plugins/@nocobase/plugin-users/src/client/RoleUsersManager.tsx +++ b/packages/plugins/@nocobase/plugin-users/src/client/RoleUsersManager.tsx @@ -93,7 +93,9 @@ export const RoleUsersManager: React.FC = () => { const handleSelectRoleUsers = (_: number[], rows: any[]) => { selectedRoleUsers.current = rows; }; + const useAddRoleUsers = () => { + const { role } = useContext(RolesManagerContext); const api = useAPIClient(); const { setVisible } = useActionContext(); const { refresh } = useResourceActionContext(); From 9354e25d7418c1d692a73db9837ba7dc40349383 Mon Sep 17 00:00:00 2001 From: YANG QIA <2013xile@gmail.com> Date: Thu, 21 Mar 2024 21:09:24 +0800 Subject: [PATCH 2/2] fix(acl): role menu loading status (#3787) --- .../plugin-acl/src/client/RolesMenu.tsx | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/plugins/@nocobase/plugin-acl/src/client/RolesMenu.tsx b/packages/plugins/@nocobase/plugin-acl/src/client/RolesMenu.tsx index 096df14f7..1c4b02db2 100644 --- a/packages/plugins/@nocobase/plugin-acl/src/client/RolesMenu.tsx +++ b/packages/plugins/@nocobase/plugin-acl/src/client/RolesMenu.tsx @@ -18,11 +18,12 @@ export const RolesMenu: React.FC & { Item: React.FC<{ item: any; onEdit: () => void }>; } = () => { const { t } = useACLTranslation(); - const { data, mutate, loading } = useResourceActionContext(); + const { data, mutate } = useResourceActionContext(); const [visible, setVisible] = useState(false); const [record, setRecord] = useState(null); const { role, setRole } = useContext(RolesManagerContext); const [roles, setRoles] = useState([]); + const [loading, setLoading] = useState(false); const api = useAPIClient(); const loadMore = useCallback(async () => { @@ -30,7 +31,7 @@ export const RolesMenu: React.FC & { if (!meta || meta.page >= meta.totalPage) { return; } - + setLoading(true); const res = await api.resource('roles').list({ page: meta.page + 1, pageSize: meta.pageSize, @@ -42,6 +43,7 @@ export const RolesMenu: React.FC & { appends: [], }); mutate(res?.data || {}); + setLoading(false); }, [data]); const { lastItem, setLastItem } = useLoadMoreObserver({ loadMore }); @@ -102,15 +104,12 @@ export const RolesMenu: React.FC & { return ( <> {roles.length ? ( - <> - - {loading && } - + }] : [])]} + selectedKeys={[role?.name]} + onSelect={handleSelect} + /> ) : ( )}