fix(acl): bug when adding users to roles (#3783)

* fix(acl): bug when adding users to roles

* fix: bug
This commit is contained in:
YANG QIA 2024-03-21 20:44:06 +08:00 committed by GitHub
parent f385c34c72
commit 49759c1ebf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 4 deletions

View File

@ -18,20 +18,30 @@ export const RolesMenu: React.FC & {
Item: React.FC<{ item: any; onEdit: () => void }>; Item: React.FC<{ item: any; onEdit: () => void }>;
} = () => { } = () => {
const { t } = useACLTranslation(); const { t } = useACLTranslation();
const { data, run, loading } = useResourceActionContext(); const { data, mutate, loading } = useResourceActionContext();
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const [record, setRecord] = useState(null); const [record, setRecord] = useState(null);
const { role, setRole } = useContext(RolesManagerContext); const { role, setRole } = useContext(RolesManagerContext);
const [roles, setRoles] = useState([]); const [roles, setRoles] = useState([]);
const api = useAPIClient();
const loadMore = useCallback(() => { const loadMore = useCallback(async () => {
const meta = data?.meta; const meta = data?.meta;
if (!meta || meta.page >= meta.totalPage) { if (!meta || meta.page >= meta.totalPage) {
return; return;
} }
run({
const res = await api.resource('roles').list({
page: meta.page + 1, page: meta.page + 1,
pageSize: meta.pageSize,
filter: {
'name.$ne': 'root',
},
showAnonymous: true,
sort: ['createdAt'],
appends: [],
}); });
mutate(res?.data || {});
}, [data]); }, [data]);
const { lastItem, setLastItem } = useLoadMoreObserver({ loadMore }); const { lastItem, setLastItem } = useLoadMoreObserver({ loadMore });
@ -54,7 +64,11 @@ export const RolesMenu: React.FC & {
const ref = React.createRef<any>(); const ref = React.createRef<any>();
setLastItem(ref); 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]); }, [data, setLastItem]);
const items = useMemo( const items = useMemo(

View File

@ -93,7 +93,9 @@ export const RoleUsersManager: React.FC = () => {
const handleSelectRoleUsers = (_: number[], rows: any[]) => { const handleSelectRoleUsers = (_: number[], rows: any[]) => {
selectedRoleUsers.current = rows; selectedRoleUsers.current = rows;
}; };
const useAddRoleUsers = () => { const useAddRoleUsers = () => {
const { role } = useContext(RolesManagerContext);
const api = useAPIClient(); const api = useAPIClient();
const { setVisible } = useActionContext(); const { setVisible } = useActionContext();
const { refresh } = useResourceActionContext(); const { refresh } = useResourceActionContext();