From d9d8105b36150967c080ae5450732e25f6e8b905 Mon Sep 17 00:00:00 2001 From: "bai.zixv" Date: Fri, 20 Sep 2024 11:27:58 +0800 Subject: [PATCH] =?UTF-8?q?fix(departments):=20=E5=88=87=E6=8D=A2=E9=83=A8?= =?UTF-8?q?=E9=97=A8,=E8=87=AA=E5=8A=A8=E5=88=B7=E6=96=B0=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=BD=93=E5=89=8D=E7=94=A8=E6=88=B7=E5=88=97=E8=A1=A8?= =?UTF-8?q?=20(#1549)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachybase/pulls/1549 Reviewed-by: sealday Co-authored-by: bai.zixv Co-committed-by: bai.zixv --- .../common/scopes/useDepartmentFilterActionProps.tsx | 1 - .../departments/main-tab/DepartmentIndex.tsx | 4 ++-- .../departments-block/DepartmentsTree.component.tsx | 4 ---- .../DepartmentsUsersBlock.tsx | 8 ++++++-- .../departments-users-block/MemberActions.schema.tsx | 12 ++++++++++++ .../departments-users-block/MemberActions.view.tsx | 10 +++++++++- .../scopes/useMembersDataSource.tsx | 3 ++- .../scopes/useRefreshActionProps.ts | 11 +++++++++++ 8 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/departments-users-block/scopes/useRefreshActionProps.ts diff --git a/packages/plugins/@hera/plugin-core/src/client/features/departments/common/scopes/useDepartmentFilterActionProps.tsx b/packages/plugins/@hera/plugin-core/src/client/features/departments/common/scopes/useDepartmentFilterActionProps.tsx index 7710f0f61..6cf66eea7 100644 --- a/packages/plugins/@hera/plugin-core/src/client/features/departments/common/scopes/useDepartmentFilterActionProps.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/features/departments/common/scopes/useDepartmentFilterActionProps.tsx @@ -10,6 +10,5 @@ export const useDepartmentFilterActionProps = () => { params: service.state?.params?.[0] || service.params, service, }); - return result; }; diff --git a/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/DepartmentIndex.tsx b/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/DepartmentIndex.tsx index 40a80608e..1ce2760a8 100644 --- a/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/DepartmentIndex.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/DepartmentIndex.tsx @@ -1,12 +1,12 @@ import React from 'react'; import { SchemaComponentContext, useSchemaComponentContext } from '@tachybase/client'; -import { ViewDepartmentManagement } from './DepartmentManagement.view'; import { ProviderDepartmentIndex } from './DepartmentIndex.provider'; +import { ViewDepartmentManagement } from './DepartmentManagement.view'; /** * TODO: 组件名称有待重新确认 - * @returns + * @returns */ export const DepartmentIndex = () => { const context = useSchemaComponentContext(); diff --git a/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/departments-block/DepartmentsTree.component.tsx b/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/departments-block/DepartmentsTree.component.tsx index 6f61df4f9..a6b48133d 100644 --- a/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/departments-block/DepartmentsTree.component.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/departments-block/DepartmentsTree.component.tsx @@ -5,7 +5,6 @@ import { MoreOutlined } from '@ant-design/icons'; import { App, Dropdown, Empty, Tree } from 'antd'; import { useTranslation } from '../../../../locale'; -import { getUserListByDepartment } from '../../utils/getUserListByDepartment'; import { useContextDepartments } from '../context/Department.context'; import { useContextDepartmentsExpanded } from '../context/DepartmentsExpanded.context'; import { schemaDepartmentEdit } from './schemas/schemaDepartmentEdit'; @@ -13,7 +12,6 @@ import { schemaDepartmentNewSub } from './schemas/schemaDepartmentNewSub'; // 部门左边-部门列表 export const DepartmentsTree = () => { - const api = useAPIClient(); const { data, loading } = useResourceActionContext(); const { department, setDepartment, setUser } = useContextDepartments(); const { treeData, nodeMap, loadData, loadedKeys, setLoadedKeys, initData, expandedKeys, setExpandedKeys } = @@ -24,8 +22,6 @@ export const DepartmentsTree = () => { return; } const department = nodeMap[keys[0]]; - const userList = await getUserListByDepartment(api, department.id); - setDepartment(department); setUser(null); }; diff --git a/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/departments-users-block/DepartmentsUsersBlock.tsx b/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/departments-users-block/DepartmentsUsersBlock.tsx index 4e2f42805..87d5219ed 100644 --- a/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/departments-users-block/DepartmentsUsersBlock.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/departments-users-block/DepartmentsUsersBlock.tsx @@ -19,13 +19,13 @@ import { UserDepartmentsField } from './UserDepartmentsField.component'; export const ViewDepartmentsUsersBlock = () => { const { t } = useTranslation(); const { department, user } = useContextDepartments(); - const { data, setState } = useResourceActionContext(); + const { data, setState, refresh } = useResourceActionContext(); const MemberActions = () => ; const RowRemoveAction = () => ; - const schema = useMemo(() => getSchemaDepartmentsUsersBlock(department, user), [department, user]); + const schema = useMemo(() => getSchemaDepartmentsUsersBlock(department, user), [department?.id, user]); useEffect(() => { setState?.({ @@ -33,6 +33,10 @@ export const ViewDepartmentsUsersBlock = () => { }); }, [data, setState]); + useEffect(() => { + refresh?.(); + }, [department?.id, user]); + return ( <>

{user ? t('Search results') : t(department?.title ?? 'All users')}

diff --git a/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/departments-users-block/MemberActions.schema.tsx b/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/departments-users-block/MemberActions.schema.tsx index f4379bda9..ee67d09f0 100644 --- a/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/departments-users-block/MemberActions.schema.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/departments-users-block/MemberActions.schema.tsx @@ -18,6 +18,18 @@ export const schemaMemberActions = { useAction: '{{ useBulkRemoveMembersAction }}', }, }, + refresh: { + type: 'void', + title: '{{ t("Refresh") }}', + 'x-component': 'Action', + 'x-use-component-props': 'useRefreshActionProps', + 'x-component-props': { + icon: 'ReloadOutlined', + style: { + marginRight: 8, + }, + }, + }, create: { type: 'void', title: '{{t("Add members")}}', diff --git a/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/departments-users-block/MemberActions.view.tsx b/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/departments-users-block/MemberActions.view.tsx index 44cb04153..2f0b66c6e 100644 --- a/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/departments-users-block/MemberActions.view.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/departments-users-block/MemberActions.view.tsx @@ -2,8 +2,16 @@ import React from 'react'; import { SchemaComponent } from '@tachybase/client'; import { schemaMemberActions } from './MemberActions.schema'; +import { useRefreshActionProps } from './scopes/useRefreshActionProps'; export const ViewMemberActions = (props) => { const { department } = props; - return department ? : null; + return department ? ( + + ) : null; }; diff --git a/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/departments-users-block/scopes/useMembersDataSource.tsx b/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/departments-users-block/scopes/useMembersDataSource.tsx index 318759394..4e82e916d 100644 --- a/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/departments-users-block/scopes/useMembersDataSource.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/departments-users-block/scopes/useMembersDataSource.tsx @@ -6,6 +6,7 @@ import { useContextDepartments } from '../../context/Department.context'; export const useMembersDataSource = (props) => { const { user } = useContextDepartments(); const ctx = useResourceActionContext(); + const { onSuccess } = props; useEffect(() => { if (user) { props?.onSuccess({ data: [user] }); @@ -14,7 +15,7 @@ export const useMembersDataSource = (props) => { } if (!ctx.loading) { - props?.onSuccess(ctx.data); + onSuccess?.(ctx.data); } }, [user, ctx.loading]); diff --git a/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/departments-users-block/scopes/useRefreshActionProps.ts b/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/departments-users-block/scopes/useRefreshActionProps.ts new file mode 100644 index 000000000..1362ab581 --- /dev/null +++ b/packages/plugins/@hera/plugin-core/src/client/features/departments/main-tab/departments-users-block/scopes/useRefreshActionProps.ts @@ -0,0 +1,11 @@ +import { useResourceActionContext } from '@tachybase/client'; + +export function useRefreshActionProps() { + const service = useResourceActionContext(); + + return { + async onClick() { + service?.refresh?.(); + }, + }; +}