diff --git a/packages/plugins/@hera/plugin-core/src/client/schema-components/association-cascader/AssociationCascader.tsx b/packages/plugins/@hera/plugin-core/src/client/schema-components/association-cascader/AssociationCascader.tsx index 90de53c42..2b323669e 100644 --- a/packages/plugins/@hera/plugin-core/src/client/schema-components/association-cascader/AssociationCascader.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/schema-components/association-cascader/AssociationCascader.tsx @@ -4,12 +4,6 @@ import { connect, useFieldSchema } from '@formily/react'; import { useCollectionManager, useRequest } from '@nocobase/client'; import _ from 'lodash'; -interface Option { - name: string | number; - id: string; - children?: Option[]; -} - const AssociationCascader = connect((props) => { const fieldSchema = useFieldSchema(); const collection = fieldSchema['collectionName']; @@ -18,35 +12,34 @@ const AssociationCascader = connect((props) => { const titleField = cm.getCollection(collection).titleField; const joinTitleField = cm.getCollection(collection + '.' + associationField).titleField; + const params = { + appends: [associationField], + fields: [titleField], + pageSize: 99999, + filter: props?.params?.filter ? { ...props?.params?.filter } : {}, + }; + const { data } = useRequest({ resource: collection, action: 'list', - params: { - appends: [associationField], - fields: [titleField], - pageSize: 99999, - }, + params, }); const options = useMemo(() => { - const dict = {}; - data?.data.forEach((item) => { - if (item[associationField]) { - dict[item[associationField][joinTitleField]] ??= []; - dict[item[associationField][joinTitleField]].push(item[titleField]); - } - }); - const options: Option[] = []; - _.forEach(dict, (values: any, key) => { - options.push({ - name: key, - id: key, - children: values.map((value) => ({ - name: value, - id: value, - })), - }); - }); + const dict: { [key: string]: string[] } = + data?.data.reduce((acc, item) => { + if (item[associationField]) { + const key = item[associationField][joinTitleField]; + acc[key] ??= []; + acc[key].push(item[titleField]); + } + return acc; + }, {}) || {}; + const options = Object.entries(dict).map(([key, values]) => ({ + name: key, + id: key, + children: values.map((value) => ({ name: value, id: value })), + })); return options; }, [associationField, joinTitleField, titleField, data?.data]); return ; diff --git a/packages/plugins/@nocobase/plugin-acl/src/client/RolesMenu.tsx b/packages/plugins/@nocobase/plugin-acl/src/client/RolesMenu.tsx index 46ed56c2f..1c4b02db2 100644 --- a/packages/plugins/@nocobase/plugin-acl/src/client/RolesMenu.tsx +++ b/packages/plugins/@nocobase/plugin-acl/src/client/RolesMenu.tsx @@ -18,20 +18,32 @@ export const RolesMenu: React.FC & { Item: React.FC<{ item: any; onEdit: () => void }>; } = () => { const { t } = useACLTranslation(); - const { data, run, 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(() => { + const loadMore = useCallback(async () => { const meta = data?.meta; if (!meta || meta.page >= meta.totalPage) { return; } - run({ + setLoading(true); + 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 || {}); + setLoading(false); }, [data]); const { lastItem, setLastItem } = useLoadMoreObserver({ loadMore }); @@ -54,7 +66,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( @@ -88,15 +104,12 @@ export const RolesMenu: React.FC & { return ( <> {roles.length ? ( - <> - - {loading && } - + }] : [])]} + selectedKeys={[role?.name]} + onSelect={handleSelect} + /> ) : ( )} 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();