fix: templateBlockProvider support association field append (#3866)

* fix: templateBlockProvider support association field append

* fix: linkage rule for add new form

* test: linkage rule fireImmediately test
This commit is contained in:
katherinehhh 2024-04-01 10:42:56 +08:00 committed by GitHub
parent 1775c6a57e
commit f909f4c376
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 809 additions and 7 deletions

View File

@ -30,6 +30,7 @@ import { DataBlockCollector } from '../filter-provider/FilterProvider';
import { RecordProvider, useRecordIndex } from '../record-provider';
import { useAssociationNames } from './hooks';
import { useDataBlockSourceId } from './hooks/useDataBlockSourceId';
import { useTemplateBlockContext } from './TemplateBlockProvider';
/**
* @deprecated
@ -222,6 +223,7 @@ export const BlockProvider = (props: {
}) => {
const { name, dataSource, association, useParams, parentRecord } = props;
const sourceId = useCompatDataBlockSourceId(props);
const { templateFinshed } = useTemplateBlockContext();
// 新版1.0)已弃用 useParams这里之所以继续保留是为了兼容旧版的 UISchema
const paramsFromHook = useParams?.();
@ -233,7 +235,7 @@ export const BlockProvider = (props: {
return { ...props.params, appends, ...paramsFromHook };
}
return { ...props.params, ...paramsFromHook };
}, [appends, paramsFromHook, props.params]);
}, [appends, paramsFromHook, props.params, templateFinshed]);
const blockValue = useMemo(() => ({ name }), [name]);
return (

View File

@ -8,6 +8,7 @@ import { RecordProvider } from '../record-provider';
import { BlockProvider, useBlockRequestContext } from './BlockProvider';
import { useParsedFilter } from './hooks';
import { withDynamicSchemaProps } from '../application/hoc/withDynamicSchemaProps';
import { TemplateBlockProvider } from './TemplateBlockProvider';
export const DetailsBlockContext = createContext<any>({});
DetailsBlockContext.displayName = 'DetailsBlockContext';
@ -64,9 +65,11 @@ const InternalDetailsBlockProvider = (props) => {
export const DetailsBlockProvider = withDynamicSchemaProps((props) => {
return (
<TemplateBlockProvider>
<BlockProvider name="details" {...props}>
<InternalDetailsBlockProvider {...props} />
</BlockProvider>
</TemplateBlockProvider>
);
});

View File

@ -9,7 +9,7 @@ import {
oneTableBlockWithAddNewAndViewAndEditAndBasicFields,
test,
} from '@nocobase/test/e2e';
import { T2165, T2174, T3251, T3806 } from './templatesOfBug';
import { T2165, T2174, T3251, T3806, T3815 } from './templatesOfBug';
const clickOption = async (page: Page, optionName: string) => {
await page.getByLabel('block-item-CardItem-general-form').hover();
@ -295,6 +295,27 @@ test.describe('creation form block schema settings', () => {
await expect(page.getByRole('row', { name: 'Users_Form' }).first()).toBeHidden();
}
});
// https://nocobase.height.app/T-T3815 &&T-3802
test('fireImmediately in create form & edit form', async ({ page, mockPage, mockRecord }) => {
const nocoPage = await mockPage(T3815).waitForInit();
await mockRecord('general', {
RadioGroup: '002',
number: 66,
select: '002',
});
await nocoPage.goto();
// 编辑表单中获取到接口数据后再触发联动规则
await page.getByLabel('action-Action.Link-Edit-').click();
await expect(await page.getByRole('spinbutton').inputValue()).toBe('66');
await page.getByLabel('drawer-Action.Container-general-Edit record-mask').click();
//新建表单中的赋默认值后的联动规则
await expect(await page.getByLabel('block-item-CardItem-general-')).toBeVisible();
await page.getByLabel('action-Action-Add new-create-').click();
await expect(await page.getByRole('spinbutton').inputValue()).toBe('88');
});
});
test('Save as block template & convert reference to duplicate', async ({ page, mockPage }) => {

View File

@ -6267,3 +6267,777 @@ export const T3806: PageConfig = {
'x-index': 1,
},
};
export const T3815: PageConfig = {
collections: [
{
name: 'general',
title: 'general',
fields: [
{
key: '1uk7lqex9o4',
name: 'number',
type: 'double',
interface: 'number',
description: null,
collectionName: 'general',
parentKey: null,
reverseKey: null,
uiSchema: {
'x-component-props': {
step: '1',
stringMode: true,
},
type: 'number',
'x-component': 'InputNumber',
title: 'number',
},
},
{
key: 'ymhle3x0w86',
name: 'RadioGroup',
type: 'string',
interface: 'radioGroup',
description: null,
collectionName: 'general',
parentKey: null,
reverseKey: null,
uiSchema: {
enum: [
{
value: '001',
label: '001',
},
{
value: '002',
label: '002',
},
{
value: '003',
label: '003',
},
],
type: 'string',
'x-component': 'Radio.Group',
title: 'RadioGroup',
},
},
{
key: 'bnmn0f12yz1',
name: 'select',
type: 'string',
interface: 'select',
description: null,
collectionName: 'general',
parentKey: null,
reverseKey: null,
uiSchema: {
enum: [
{
value: '001',
label: '001',
},
{
value: '002',
label: '002',
},
],
type: 'string',
'x-component': 'Select',
title: 'select',
},
},
],
},
],
pageSchema: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Page',
properties: {
nhr8mj576ht: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid',
'x-initializer': 'page:addBlock',
properties: {
p6xjvwkmmeq: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Row',
properties: {
mttf5p61t1x: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Col',
properties: {
'4tzpzqss38o': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-decorator': 'TableBlockProvider',
'x-acl-action': 'general:list',
'x-use-decorator-props': 'useTableBlockDecoratorProps',
'x-decorator-props': {
collection: 'general',
dataSource: 'main',
action: 'list',
params: {
pageSize: 20,
},
rowKey: 'id',
showIndex: true,
dragSort: false,
},
'x-toolbar': 'BlockSchemaToolbar',
'x-settings': 'blockSettings:table',
'x-component': 'CardItem',
'x-filter-targets': [],
properties: {
actions: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-initializer': 'table:configureActions',
'x-component': 'ActionBar',
'x-component-props': {
style: {
marginBottom: 'var(--nb-spacing)',
},
},
properties: {
'1o0e395gfsh': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-action': 'create',
'x-acl-action': 'create',
title: "{{t('Add new')}}",
'x-toolbar': 'ActionSchemaToolbar',
'x-settings': 'actionSettings:addNew',
'x-component': 'Action',
'x-decorator': 'ACLActionProvider',
'x-component-props': {
openMode: 'drawer',
type: 'primary',
component: 'CreateRecordAction',
icon: 'PlusOutlined',
},
'x-align': 'right',
'x-acl-action-props': {
skipScopeCheck: true,
},
properties: {
drawer: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
title: '{{ t("Add record") }}',
'x-component': 'Action.Container',
'x-component-props': {
className: 'nb-action-popup',
},
properties: {
tabs: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Tabs',
'x-component-props': {},
'x-initializer': 'TabPaneInitializersForCreateFormBlock',
properties: {
tab1: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
title: '{{t("Add new")}}',
'x-component': 'Tabs.TabPane',
'x-designer': 'Tabs.Designer',
'x-component-props': {},
properties: {
grid: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid',
'x-initializer': 'popup:addNew:addBlock',
properties: {
'4fsnnaaestz': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Row',
properties: {
osb7r02dhfu: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Col',
properties: {
jid8ny6v3mj: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-acl-action-props': {
skipScopeCheck: true,
},
'x-acl-action': 'general:create',
'x-decorator': 'FormBlockProvider',
'x-use-decorator-props': 'useCreateFormBlockDecoratorProps',
'x-decorator-props': {
dataSource: 'main',
collection: 'general',
},
'x-toolbar': 'BlockSchemaToolbar',
'x-settings': 'blockSettings:createForm',
'x-component': 'CardItem',
properties: {
'2eeu8jiuxwa': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'FormV2',
'x-use-component-props': 'useCreateFormBlockProps',
properties: {
grid: {
'x-uid': '7x8aol12h2w',
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid',
'x-initializer': 'form:configureFields',
'x-linkage-rules': [
{
condition: {
$and: [
{
RadioGroup: {
$eq: '001',
},
},
],
},
actions: [
{
targetFields: ['number'],
operator: 'value',
value: {
mode: 'constant',
value: 88,
},
},
],
},
],
properties: {
noz6nzl8na7: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Row',
properties: {
sdzg1t5dw7h: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Col',
properties: {
RadioGroup: {
'x-uid': 'xks5rpnseko',
_isJSONSchemaObject: true,
version: '2.0',
type: 'string',
'x-toolbar': 'FormItemSchemaToolbar',
'x-settings': 'fieldSettings:FormItem',
'x-component': 'CollectionField',
'x-decorator': 'FormItem',
'x-collection-field': 'general.RadioGroup',
'x-component-props': {},
default: '001',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'qz7vzsndftl',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'hsx84f2y6ua',
'x-async': false,
'x-index': 1,
},
'55y5v9xzhrr': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Row',
properties: {
kllmw9omiy0: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Col',
properties: {
number: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'string',
'x-toolbar': 'FormItemSchemaToolbar',
'x-settings': 'fieldSettings:FormItem',
'x-component': 'CollectionField',
'x-decorator': 'FormItem',
'x-collection-field': 'general.number',
'x-component-props': {},
'x-uid': '4qwesoyn2lv',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'oqgux8bvwus',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'cpky70ftn7n',
'x-async': false,
'x-index': 2,
},
},
'x-async': false,
'x-index': 1,
},
t6s3uqz32i3: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-initializer': 'createForm:configureActions',
'x-component': 'ActionBar',
'x-component-props': {
layout: 'one-column',
style: {
marginTop: 24,
},
},
properties: {
e77n01j6706: {
_isJSONSchemaObject: true,
version: '2.0',
title: '{{ t("Submit") }}',
'x-action': 'submit',
'x-component': 'Action',
'x-toolbar': 'ActionSchemaToolbar',
'x-settings': 'actionSettings:createSubmit',
'x-component-props': {
type: 'primary',
htmlType: 'submit',
useProps: '{{ useCreateActionProps }}',
},
'x-action-settings': {
triggerWorkflows: [],
},
type: 'void',
'x-uid': 'i3m7mcprpsj',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'qgfh4mnqn47',
'x-async': false,
'x-index': 2,
},
},
'x-uid': 'yt356mb8su8',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'bir25av2h8c',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'yw8lzedzqa8',
'x-async': false,
'x-index': 1,
},
},
'x-uid': '2ali05rbh1t',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'cavysdb03y0',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'ghzaxyk7qj2',
'x-async': false,
'x-index': 1,
},
},
'x-uid': '2753r2whfbk',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'wm3t5fa9kbd',
'x-async': false,
'x-index': 1,
},
},
'x-uid': '5esm05tfs46',
'x-async': false,
'x-index': 1,
},
},
'x-uid': '5buucn2bfe7',
'x-async': false,
'x-index': 1,
},
tpibv7vu56j: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'array',
'x-initializer': 'table:configureColumns',
'x-component': 'TableV2',
'x-use-component-props': 'useTableBlockProps',
'x-component-props': {
rowKey: 'id',
rowSelection: {
type: 'checkbox',
},
},
properties: {
actions: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
title: '{{ t("Actions") }}',
'x-action-column': 'actions',
'x-decorator': 'TableV2.Column.ActionBar',
'x-component': 'TableV2.Column',
'x-designer': 'TableV2.ActionColumnDesigner',
'x-initializer': 'table:configureItemActions',
properties: {
ig2hd5z6klq: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-decorator': 'DndContext',
'x-component': 'Space',
'x-component-props': {
split: '|',
},
properties: {
xyh1a9t00fx: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
title: '{{ t("Edit") }}',
'x-action': 'update',
'x-toolbar': 'ActionSchemaToolbar',
'x-settings': 'actionSettings:edit',
'x-component': 'Action.Link',
'x-component-props': {
openMode: 'drawer',
icon: 'EditOutlined',
},
'x-decorator': 'ACLActionProvider',
'x-designer-props': {
linkageAction: true,
},
properties: {
drawer: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
title: '{{ t("Edit record") }}',
'x-component': 'Action.Container',
'x-component-props': {
className: 'nb-action-popup',
},
properties: {
tabs: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Tabs',
'x-component-props': {},
'x-initializer': 'TabPaneInitializers',
properties: {
tab1: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
title: '{{t("Edit")}}',
'x-component': 'Tabs.TabPane',
'x-designer': 'Tabs.Designer',
'x-component-props': {},
properties: {
grid: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid',
'x-initializer': 'popup:common:addBlock',
properties: {
cpjlt6mmwzd: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Row',
properties: {
jf9arnl1c1s: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Col',
properties: {
'9ip2xowsjjv': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-acl-action-props': {
skipScopeCheck: false,
},
'x-acl-action': 'general:update',
'x-decorator': 'FormBlockProvider',
'x-use-decorator-props':
'useEditFormBlockDecoratorProps',
'x-decorator-props': {
action: 'get',
dataSource: 'main',
collection: 'general',
},
'x-toolbar': 'BlockSchemaToolbar',
'x-settings': 'blockSettings:editForm',
'x-component': 'CardItem',
properties: {
icc7ijerfsm: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'FormV2',
'x-use-component-props': 'useEditFormBlockProps',
properties: {
grid: {
'x-uid': 'r6h74xj4jeo',
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid',
'x-initializer': 'form:configureFields',
'x-linkage-rules': [
{
condition: {
$and: [
{
RadioGroup: {
$empty: true,
},
},
],
},
actions: [
{
targetFields: ['number'],
operator: 'value',
value: {
mode: 'constant',
value: 33,
},
},
],
},
],
properties: {
allz7qqlxuk: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Row',
properties: {
gjvql4asspw: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Col',
properties: {
RadioGroup: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'string',
'x-toolbar':
'FormItemSchemaToolbar',
'x-settings':
'fieldSettings:FormItem',
'x-component': 'CollectionField',
'x-decorator': 'FormItem',
'x-collection-field':
'general.RadioGroup',
'x-component-props': {},
'x-uid': 'e25m7niryeq',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'oecqrrznd0v',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'dduijjct95t',
'x-async': false,
'x-index': 1,
},
trhja7zflmm: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Row',
properties: {
xf5cb7vo6ct: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Col',
properties: {
number: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'string',
'x-toolbar':
'FormItemSchemaToolbar',
'x-settings':
'fieldSettings:FormItem',
'x-component': 'CollectionField',
'x-decorator': 'FormItem',
'x-collection-field':
'general.number',
'x-component-props': {},
'x-uid': 'vb1n12dt6bn',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'ifh8nu58qj3',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'soiv7nthgdg',
'x-async': false,
'x-index': 2,
},
},
'x-async': false,
'x-index': 1,
},
v3b9ap97bd2: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-initializer': 'editForm:configureActions',
'x-component': 'ActionBar',
'x-component-props': {
layout: 'one-column',
style: {
marginTop: 24,
},
},
'x-uid': 'rircmjh6moa',
'x-async': false,
'x-index': 2,
},
},
'x-uid': 'enxcig2gaes',
'x-async': false,
'x-index': 1,
},
},
'x-uid': '3oqp9l1k6af',
'x-async': false,
'x-index': 1,
},
},
'x-uid': '8bdt3qp62te',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'cxj16fgweac',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'e3l5tbygcyc',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'dui5obth7od',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'uyhhcn2go29',
'x-async': false,
'x-index': 1,
},
},
'x-uid': '8tmovl28ezr',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'cb2pq303nq1',
'x-async': false,
'x-index': 1,
},
},
'x-uid': '4wqf7u004dt',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'glisvno0yqy',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'jm0bu0makzv',
'x-async': false,
'x-index': 2,
},
},
'x-uid': 'q768rtdam1p',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'blf1f85fvce',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'hkj1q8tqey9',
'x-async': false,
'x-index': 1,
},
},
'x-uid': '6ij3k3ipjbe',
'x-async': false,
'x-index': 1,
},
},
'x-uid': '6dw4ah33eku',
'x-async': true,
'x-index': 1,
},
};

View File

@ -24,7 +24,9 @@ import { useTemplateBlockContext } from '../../../block-provider/TemplateBlockPr
export interface FormProps {
[key: string]: any;
}
function hasInitialValues(obj) {
return Object.values(obj).some((value) => value !== null);
}
const FormComponent: React.FC<FormProps> = (props) => {
const { form, children, ...others } = props;
const field = useField();
@ -153,7 +155,7 @@ const WithForm = (props: WithFormProps) => {
return result;
},
getSubscriber(action, field, rule, variables, localVariables),
{ fireImmediately: false },
{ fireImmediately: hasInitialValues(form.initialValues) },
),
);
});