diff --git a/packages/core/client/src/modules/actions/view-edit-popup/__e2e__/linkageRules.test.ts b/packages/core/client/src/modules/actions/view-edit-popup/__e2e__/linkageRules.test.ts new file mode 100644 index 0000000000..91546623b9 --- /dev/null +++ b/packages/core/client/src/modules/actions/view-edit-popup/__e2e__/linkageRules.test.ts @@ -0,0 +1,10 @@ +import { expect, test } from '@nocobase/test/e2e'; +import { T3910 } from './templatesOfBug'; + +test.describe('LinkageRules of view-edit-popup', () => { + test('should be disabled', async ({ page, mockPage }) => { + await mockPage(T3910).goto(); + + await expect(page.getByLabel('action-Action-Edit-update-')).toBeDisabled(); + }); +}); diff --git a/packages/core/client/src/modules/actions/view-edit-popup/__e2e__/templatesOfBug.ts b/packages/core/client/src/modules/actions/view-edit-popup/__e2e__/templatesOfBug.ts new file mode 100644 index 0000000000..2880cd94aa --- /dev/null +++ b/packages/core/client/src/modules/actions/view-edit-popup/__e2e__/templatesOfBug.ts @@ -0,0 +1,300 @@ +import { PageConfig } from '@nocobase/test/e2e'; + +export const T3910: PageConfig = { + pageSchema: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Page', + 'x-app-version': '0.21.0-alpha.5', + properties: { + g31hdrdqs8h: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid', + 'x-initializer': 'page:addBlock', + 'x-app-version': '0.21.0-alpha.5', + properties: { + row_iz2b4igru45: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Row', + 'x-index': 3, + 'x-uid': '617eufdvnh6', + 'x-async': false, + }, + row_a5ts27jsr0r: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Row', + 'x-index': 5, + 'x-uid': '5y6xse8lly4', + 'x-async': false, + }, + row_7kgysy6ebmv: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Row', + 'x-index': 7, + 'x-uid': 'xinsxfgxn6w', + 'x-async': false, + }, + row_8up6dvn9s9x: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Row', + 'x-index': 8, + properties: { + srvh9gyv314: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Col', + 'x-uid': 'cmfgvfgiu5c', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'xqhlz9kb9cn', + 'x-async': false, + }, + ellejr0qqmk: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Row', + 'x-app-version': '0.21.0-alpha.5', + 'x-uid': '332sv3qoo02', + 'x-async': false, + 'x-index': 9, + }, + iikykifub90: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Row', + 'x-app-version': '0.21.0-alpha.5', + 'x-uid': 'kwwfi3g1s9c', + 'x-async': false, + 'x-index': 10, + }, + eocpt7rr5nf: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Row', + 'x-app-version': '0.21.0-alpha.5', + 'x-uid': 'n8inyj1o337', + 'x-async': false, + 'x-index': 11, + }, + dmguqyj163z: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Row', + 'x-app-version': '0.21.0-alpha.5', + properties: { + '45z8xeagwh9': { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Col', + 'x-app-version': '0.21.0-alpha.5', + properties: { + ox51hs3hrtl: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-acl-action': 'roles:view', + 'x-decorator': 'DetailsBlockProvider', + 'x-use-decorator-props': 'useDetailsWithPaginationDecoratorProps', + 'x-decorator-props': { + dataSource: 'main', + collection: 'roles', + readPretty: true, + action: 'list', + params: { + pageSize: 1, + }, + }, + 'x-toolbar': 'BlockSchemaToolbar', + 'x-settings': 'blockSettings:detailsWithPagination', + 'x-component': 'CardItem', + 'x-app-version': '0.21.0-alpha.5', + properties: { + xhstm4sfzvf: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Details', + 'x-read-pretty': true, + 'x-use-component-props': 'useDetailsWithPaginationProps', + 'x-app-version': '0.21.0-alpha.5', + properties: { + sg4oe8v52dv: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-initializer': 'details:configureActions', + 'x-component': 'ActionBar', + 'x-component-props': { + style: { + marginBottom: 24, + }, + }, + 'x-app-version': '0.21.0-alpha.5', + properties: { + hhwgvc571rv: { + 'x-uid': '4xht3tnzsuc', + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + title: '{{ t("Edit") }}', + 'x-action': 'update', + 'x-toolbar': 'ActionSchemaToolbar', + 'x-settings': 'actionSettings:edit', + 'x-component': 'Action', + 'x-component-props': { + openMode: 'drawer', + icon: 'EditOutlined', + type: 'primary', + }, + 'x-decorator': 'ACLActionProvider', + 'x-app-version': '0.21.0-alpha.5', + 'x-linkage-rules': [ + { + condition: { + $and: [], + }, + actions: [ + { + operator: 'disabled', + }, + ], + }, + ], + properties: { + drawer: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + title: '{{ t("Edit record") }}', + 'x-component': 'Action.Container', + 'x-component-props': { + className: 'nb-action-popup', + }, + 'x-app-version': '0.21.0-alpha.5', + properties: { + tabs: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Tabs', + 'x-component-props': {}, + 'x-initializer': 'popup:addTab', + 'x-app-version': '0.21.0-alpha.5', + properties: { + tab1: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + title: '{{t("Edit")}}', + 'x-component': 'Tabs.TabPane', + 'x-designer': 'Tabs.Designer', + 'x-component-props': {}, + 'x-app-version': '0.21.0-alpha.5', + properties: { + grid: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid', + 'x-initializer': 'popup:common:addBlock', + 'x-app-version': '0.21.0-alpha.5', + 'x-uid': 'ahcfvqtca2t', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'm3qh2qam848', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'qp5j0fo0uz3', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': '0jn3kvh5043', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'a0vogjl5s40', + 'x-async': false, + 'x-index': 1, + }, + grid: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid', + 'x-initializer': 'details:configureFields', + 'x-app-version': '0.21.0-alpha.5', + 'x-uid': '088lqkedkmm', + 'x-async': false, + 'x-index': 2, + }, + pagination: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Pagination', + 'x-use-component-props': 'useDetailsPaginationProps', + 'x-app-version': '0.21.0-alpha.5', + 'x-uid': 'yg4znwidty0', + 'x-async': false, + 'x-index': 3, + }, + }, + 'x-uid': 'x8clfl5dzzx', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'r91isw3r5hi', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': '5dtzmsf8zfj', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'twyfj5klim7', + 'x-async': false, + 'x-index': 12, + }, + }, + 'x-uid': 'gvzvz05oi9h', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'mk589w74bvs', + 'x-async': true, + 'x-index': 1, + }, +}; diff --git a/packages/core/client/src/schema-component/antd/action/Action.tsx b/packages/core/client/src/schema-component/antd/action/Action.tsx index 734d503211..0b60268832 100644 --- a/packages/core/client/src/schema-component/antd/action/Action.tsx +++ b/packages/core/client/src/schema-component/antd/action/Action.tsx @@ -3,11 +3,13 @@ import { isPortalInBody } from '@nocobase/utils/client'; import { App, Button } from 'antd'; import classnames from 'classnames'; import { default as lodash } from 'lodash'; -import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'; +import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { StablePopover, useActionContext } from '../..'; import { useDesignable } from '../../'; import { useACLActionParamsContext } from '../../../acl'; +import { withDynamicSchemaProps } from '../../../application/hoc/withDynamicSchemaProps'; +import { useDataBlockRequest } from '../../../data-source'; import { Icon } from '../../../icon'; import { RecordProvider, useRecord } from '../../../record-provider'; import { useLocalVariables, useVariables } from '../../../variables'; @@ -26,8 +28,6 @@ import { useA } from './hooks'; import { useGetAriaLabelOfAction } from './hooks/useGetAriaLabelOfAction'; import { ComposedAction } from './types'; import { linkageAction } from './utils'; -import { withDynamicSchemaProps } from '../../../application/hoc/withDynamicSchemaProps'; -import { useDataBlockRequest } from '../../../data-source'; export const Action: ComposedAction = withDynamicSchemaProps( observer((props: any) => { @@ -76,13 +76,7 @@ export const Action: ComposedAction = withDynamicSchemaProps( const variables = useVariables(); const localVariables = useLocalVariables({ currentForm: { values: record } as any }); const { getAriaLabel } = useGetAriaLabelOfAction(title); - const [btnHover, setBtnHover] = useState(popover); const service = useDataBlockRequest(); - useEffect(() => { - if (popover) { - setBtnHover(true); - } - }, [popover]); const actionTitle = useMemo(() => { const res = title || compile(fieldSchema.title); @@ -90,7 +84,6 @@ export const Action: ComposedAction = withDynamicSchemaProps( }, [title, fieldSchema.title, t]); useEffect(() => { - if (!btnHover) return; field.stateOfLinkageRules = {}; linkageRules .filter((k) => !k.disabled) @@ -105,15 +98,13 @@ export const Action: ComposedAction = withDynamicSchemaProps( }); }); }); - }, [btnHover, field, linkageRules, localVariables, record, variables]); + }, [field, linkageRules, localVariables, variables]); const handleButtonClick = useCallback( (e: React.MouseEvent) => { if (isPortalInBody(e.target as Element)) { return; } - setBtnHover(true); - e.preventDefault(); e.stopPropagation(); @@ -153,7 +144,6 @@ export const Action: ComposedAction = withDynamicSchemaProps( const handleMouseEnter = useCallback( (e) => { - setBtnHover(true); onMouseEnter?.(e); }, [onMouseEnter],