From b75fdc7f62727729e0598d92f6f2345cc668dea1 Mon Sep 17 00:00:00 2001 From: Katherine Date: Mon, 12 Aug 2024 15:09:40 +0800 Subject: [PATCH] fix: disable edit and delete button for all records and own record in data scope configuration (#5041) --- .../PermissionManager/schemas/scopes.tsx | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/plugins/@nocobase/plugin-data-source-manager/src/client/component/PermissionManager/schemas/scopes.tsx b/packages/plugins/@nocobase/plugin-data-source-manager/src/client/component/PermissionManager/schemas/scopes.tsx index 06d353c67d..14dc06998a 100644 --- a/packages/plugins/@nocobase/plugin-data-source-manager/src/client/component/PermissionManager/schemas/scopes.tsx +++ b/packages/plugins/@nocobase/plugin-data-source-manager/src/client/component/PermissionManager/schemas/scopes.tsx @@ -15,6 +15,9 @@ import { useFilterFieldOptions, useFormBlockContext, withDynamicSchemaProps, + useCollectionRecord, + Action, + useDestroyActionProps, } from '@nocobase/client'; import React, { useContext, useEffect } from 'react'; import { RoleResourceCollectionContext } from '../RolesResourcesActions'; @@ -51,6 +54,20 @@ const useFormBlockProps = () => { }; }; +const EditScopeActionComponent = (props) => { + const { data } = useCollectionRecord(); + const { id } = data || ({} as any); + const actionProps = { ...props, disabled: [1, 2].includes(id) }; + return ; +}; + +const DestroyScopeActionComponent = (props) => { + const { data } = useCollectionRecord(); + const { id } = data || ({} as any); + const actionProps = { ...props, ...useDestroyActionProps(), disabled: [1, 2].includes(id) }; + return ; +}; + export const getScopesSchema = (dataSourceKey) => { const collection = rolesResourcesScopesCollection(dataSourceKey); return { @@ -247,7 +264,7 @@ export const getScopesSchema = (dataSourceKey) => { title: '{{ t("Edit") }}', 'x-action': 'update', 'x-decorator': 'ACLActionProvider', - 'x-component': 'Action.Link', + 'x-component': EditScopeActionComponent, 'x-component-props': { openMode: 'drawer', icon: 'EditOutlined', @@ -341,8 +358,6 @@ export const getScopesSchema = (dataSourceKey) => { title: '{{ t("Delete") }}', 'x-action': 'destroy', 'x-decorator': 'ACLActionProvider', - 'x-component': 'Action.Link', - 'x-use-component-props': 'useDestroyActionProps', 'x-component-props': { icon: 'DeleteOutlined', confirm: { @@ -350,6 +365,7 @@ export const getScopesSchema = (dataSourceKey) => { content: "{{t('Are you sure you want to delete it?')}}", }, }, + 'x-component': DestroyScopeActionComponent, }, }, },