From c6915c69f81e6cdd280c1ed87d34a8d939d4f0a2 Mon Sep 17 00:00:00 2001 From: Zeke Zhang <958414905@qq.com> Date: Fri, 29 Dec 2023 11:34:27 +0800 Subject: [PATCH] fix: use appends param to load association data (#3282) * fix: use appends param to load association data * chore: update yarn.lock * test: add test * test: remove the 'BUG:' text * test: fix 'window is not defined' * test: increase timeout --- .../src/block-provider/BlockProvider.tsx | 3 +- .../client/src/block-provider/hooks/index.ts | 20 +- .../__e2e__/lazyLoadAssociationFields.test.ts | 57 +- .../__e2e__/schemaSettings.test.ts | 4 +- .../form-creation/__e2e__/templatesOfBug.ts | 1516 +++++++++++++++++ .../table/__e2e__/actions/duplicate.test.ts | 2 +- .../table/__e2e__/actions/filter.test.ts | 4 +- ...eLazyLoadDisplayAssociationFieldsOfForm.ts | 6 +- .../src/variables/VariablesProvider.tsx | 26 +- packages/core/client/src/variables/types.ts | 9 +- packages/core/test/setup/client.ts | 4 + .../fields/password/schemaSettings.test.ts | 1 + .../instruction/DetailsBlockProvider.tsx | 7 +- .../client/instruction/FormBlockProvider.tsx | 3 +- yarn.lock | 5 + 15 files changed, 1641 insertions(+), 26 deletions(-) diff --git a/packages/core/client/src/block-provider/BlockProvider.tsx b/packages/core/client/src/block-provider/BlockProvider.tsx index 9d30a56f8..bcb7f3a56 100644 --- a/packages/core/client/src/block-provider/BlockProvider.tsx +++ b/packages/core/client/src/block-provider/BlockProvider.tsx @@ -305,7 +305,8 @@ export const BlockProvider = (props: { }) => { const { collection, association, name } = props; const resource = useResource(props); - const { appends, updateAssociationValues } = useAssociationNames(); + const { getAssociationAppends } = useAssociationNames(); + const { appends, updateAssociationValues } = getAssociationAppends(); const params = useMemo(() => { if (!props.params?.['appends']) { return { ...props.params, appends }; diff --git a/packages/core/client/src/block-provider/hooks/index.ts b/packages/core/client/src/block-provider/hooks/index.ts index 066d1c163..1ab0ce7a8 100644 --- a/packages/core/client/src/block-provider/hooks/index.ts +++ b/packages/core/client/src/block-provider/hooks/index.ts @@ -1295,11 +1295,11 @@ export function getAssociationPath(str) { } export const useAssociationNames = () => { + let updateAssociationValues = new Set([]); + let appends = new Set([]); const { getCollectionJoinField, getCollection } = useCollectionManager(); const fieldSchema = useFieldSchema(); - const updateAssociationValues = new Set([]); - const appends = new Set([]); - const getAssociationAppends = (schema, str) => { + const _getAssociationAppends = (schema, str) => { schema.reduceProperties((pre, s) => { const prefix = pre || str; const collectionField = s['x-collection-field'] && getCollectionJoinField(s['x-collection-field']); @@ -1338,7 +1338,7 @@ export const useAssociationNames = () => { if (['Nester', 'SubTable', 'PopoverNester'].includes(s['x-component-props']?.mode)) { updateAssociationValues.add(path); const bufPrefix = prefix && prefix !== '' ? prefix + '.' + s.name : s.name; - getAssociationAppends(s, bufPrefix); + _getAssociationAppends(s, bufPrefix); } } else if ( ![ @@ -1354,12 +1354,18 @@ export const useAssociationNames = () => { 'TableField', ].includes(s['x-component']) ) { - getAssociationAppends(s, str); + _getAssociationAppends(s, str); } }, str); }; - getAssociationAppends(fieldSchema, ''); - return { appends: [...appends], updateAssociationValues: [...updateAssociationValues] }; + const getAssociationAppends = () => { + updateAssociationValues = new Set([]); + appends = new Set([]); + _getAssociationAppends(fieldSchema, ''); + return { appends: [...appends], updateAssociationValues: [...updateAssociationValues] }; + }; + + return { getAssociationAppends }; }; function getTargetField(obj) { diff --git a/packages/core/client/src/modules/form-creation/__e2e__/lazyLoadAssociationFields.test.ts b/packages/core/client/src/modules/form-creation/__e2e__/lazyLoadAssociationFields.test.ts index 6c423f9af..63350111b 100644 --- a/packages/core/client/src/modules/form-creation/__e2e__/lazyLoadAssociationFields.test.ts +++ b/packages/core/client/src/modules/form-creation/__e2e__/lazyLoadAssociationFields.test.ts @@ -6,7 +6,7 @@ import { oneTableSubtableWithMultiLevelAssociationFields, test, } from '@nocobase/test/e2e'; -import { T2200, T2614, T2615 } from './templatesOfBug'; +import { T2200, T2614, T2615, T2845 } from './templatesOfBug'; test.describe('display association fields', () => { test('form: should display correctly', async ({ page, mockPage, mockRecord }) => { @@ -50,7 +50,7 @@ test.describe('display association fields', () => { }); // https://nocobase.height.app/T-2615 - test('BUG: should load association data', async ({ page, mockPage, mockRecord }) => { + test('should load association data', async ({ page, mockPage, mockRecord }) => { const nocoPage = await mockPage(T2615).waitForInit(); await mockRecord('T2615'); await nocoPage.goto(); @@ -87,8 +87,57 @@ test.describe('display association fields', () => { ); }); + // https://nocobase.height.app/T-2845 + test('should load association data of subform', async ({ page, mockPage, mockRecord }) => { + const nocoPage = await mockPage(T2845).waitForInit(); + // 和 T2615 使用一样的数据表结构 + const record = await mockRecord('T2615'); + await nocoPage.goto(); + + // 1. 新增表单中应该显示关系字段的数据 + await page.getByRole('button', { name: 'Add new' }).click(); + await page + .getByLabel('block-item-CollectionField-T2615-form-T2615.m2o-m2o') + .getByTestId('select-object-single') + .click(); + await page.getByRole('option', { name: String(record.m2o.id) }).click(); + await expect(page.getByLabel('block-item-CollectionField-T2615Target2-form-T2615Target2.id-ID')).toHaveText( + `ID:${record.m2o.m2oOfTarget1.id}`, + ); + await expect(page.getByLabel('block-item-CollectionField-T2615Target2-form-T2615Target2.m2oOfTarget2-')).toHaveText( + `m2oOfTarget2:${record.m2o.m2oOfTarget1.m2oOfTarget2.id}`, + ); + + // 关闭弹窗 + await page.getByLabel('drawer-Action.Container-T2615-Add record-mask').click(); + await page.getByRole('button', { name: 'OK', exact: true }).click(); + + // 2. 编辑表单中应该显示关系字段的数据 + await page.getByLabel(`action-Action.Link-Edit record-update-T2615-table-${record.id - 1}`).click(); + await expect(page.getByLabel('block-item-CollectionField-T2615Target2-form-T2615Target2.id-ID')).toHaveText( + `ID:${record.m2o.m2oOfTarget1.id}`, + ); + await expect(page.getByLabel('block-item-CollectionField-T2615Target2-form-T2615Target2.m2oOfTarget2-')).toHaveText( + `m2oOfTarget2:${record.m2o.m2oOfTarget1.m2oOfTarget2.id}`, + ); + + await page.getByLabel('drawer-Action.Container-T2615-Edit record-mask').click(); + + // 3. 详情中应该显示关系字段的数据 + await page.getByLabel(`action-Action.Link-View record-view-T2615-table-${record.id - 1}`).click(); + await expect(page.getByLabel('block-item-CollectionField-T2615-form-T2615.m2o-m2o')).toHaveText( + `m2o:${record.m2o.id}`, + ); + await expect(page.getByLabel('block-item-CollectionField-T2615Target2-form-T2615Target2.id-ID')).toHaveText( + `ID:${record.m2o.m2oOfTarget1.id}`, + ); + await expect(page.getByLabel('block-item-CollectionField-T2615Target2-form-T2615Target2.m2oOfTarget2-')).toHaveText( + `m2oOfTarget2:${record.m2o.m2oOfTarget1.m2oOfTarget2.id}`, + ); + }); + // https://nocobase.height.app/T-2614 - test('BUG: should load association data in subform', async ({ page, mockPage, mockRecord }) => { + test('should load association data in subform', async ({ page, mockPage, mockRecord }) => { const nocoPage = await mockPage(T2614).waitForInit(); await mockRecord('T2614'); await nocoPage.goto(); @@ -198,7 +247,7 @@ test.describe('association fields', () => { }); // fix https://nocobase.height.app/T-2200 - test('BUG: should be possible to change the value of the association field normally', async ({ page, mockPage }) => { + test('should be possible to change the value of the association field normally', async ({ page, mockPage }) => { await mockPage(T2200).goto(); await page.getByLabel('action-Action.Link-Edit-update-users-table-0').click(); diff --git a/packages/core/client/src/modules/form-creation/__e2e__/schemaSettings.test.ts b/packages/core/client/src/modules/form-creation/__e2e__/schemaSettings.test.ts index 710ded893..58d601a9b 100644 --- a/packages/core/client/src/modules/form-creation/__e2e__/schemaSettings.test.ts +++ b/packages/core/client/src/modules/form-creation/__e2e__/schemaSettings.test.ts @@ -212,7 +212,7 @@ test.describe('creation form block schema settings', () => { }); // fix https://nocobase.height.app/T-2165 - test('BUG: variable labels should be displayed normally', async ({ page, mockPage }) => { + test('variable labels should be displayed normally', async ({ page, mockPage }) => { await mockPage(T2165).goto(); await page.getByLabel('block-item-CardItem-users-form').hover(); @@ -628,7 +628,7 @@ test.describe('creation form block schema settings', () => { }); // fix https://nocobase.height.app/T-2174 - test('BUG: should show default value option', async ({ page, mockPage, mockRecord }) => { + test('should show default value option', async ({ page, mockPage, mockRecord }) => { const nocoPage = await mockPage(T2174).waitForInit(); await mockRecord('test2174'); await nocoPage.goto(); diff --git a/packages/core/client/src/modules/form-creation/__e2e__/templatesOfBug.ts b/packages/core/client/src/modules/form-creation/__e2e__/templatesOfBug.ts index 44d41364e..0c5c794da 100644 --- a/packages/core/client/src/modules/form-creation/__e2e__/templatesOfBug.ts +++ b/packages/core/client/src/modules/form-creation/__e2e__/templatesOfBug.ts @@ -2580,6 +2580,1522 @@ export const T2615: PageConfig = { 'x-index': 1, }, }; + +export const T2845: PageConfig = { + collections: [ + { + name: 'T2615', + fields: [ + { + name: 'm2o', + interface: 'm2o', + target: 'T2615Target1', + }, + ], + }, + { + name: 'T2615Target1', + fields: [ + { + name: 'm2oOfTarget1', + interface: 'm2o', + target: 'T2615Target2', + }, + ], + }, + { + name: 'T2615Target2', + fields: [ + { + name: 'm2oOfTarget2', + interface: 'm2o', + target: 'users', + }, + ], + }, + ], + pageSchema: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Page', + 'x-index': 1, + properties: { + eoe6sphevnd: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid', + 'x-initializer': 'BlockInitializers', + 'x-index': 1, + properties: { + '1valv0kj8vs': { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Row', + 'x-index': 1, + properties: { + nkq10mh10ps: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Col', + 'x-index': 1, + properties: { + '22lk2du0ib3': { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-decorator': 'TableBlockProvider', + 'x-acl-action': 'T2615:list', + 'x-decorator-props': { + collection: 'T2615', + resource: 'T2615', + action: 'list', + params: { + pageSize: 20, + }, + rowKey: 'id', + showIndex: true, + dragSort: false, + disableTemplate: false, + }, + 'x-designer': 'TableBlockDesigner', + 'x-component': 'CardItem', + 'x-filter-targets': [], + 'x-index': 1, + properties: { + actions: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-initializer': 'TableActionInitializers', + 'x-component': 'ActionBar', + 'x-component-props': { + style: { + marginBottom: 'var(--nb-spacing)', + }, + }, + 'x-index': 1, + properties: { + unexw8b0ued: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-action': 'create', + 'x-acl-action': 'create', + title: "{{t('Add new')}}", + 'x-designer': 'Action.Designer', + '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, + }, + 'x-index': 1, + properties: { + drawer: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + title: '{{ t("Add record") }}', + 'x-component': 'Action.Container', + 'x-component-props': { + className: 'nb-action-popup', + }, + 'x-index': 1, + properties: { + tabs: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Tabs', + 'x-component-props': {}, + 'x-initializer': 'TabPaneInitializersForCreateFormBlock', + 'x-index': 1, + properties: { + tab1: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + title: '{{t("Add new")}}', + 'x-component': 'Tabs.TabPane', + 'x-designer': 'Tabs.Designer', + 'x-component-props': {}, + 'x-index': 1, + properties: { + grid: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid', + 'x-initializer': 'CreateFormBlockInitializers', + 'x-index': 1, + properties: { + '8ei3tsaojf6': { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Row', + 'x-index': 1, + properties: { + '5u0ju1wsgkl': { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Col', + 'x-index': 1, + properties: { + zxwg35f8sg7: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-acl-action-props': { + skipScopeCheck: true, + }, + 'x-acl-action': 'T2615:create', + 'x-decorator': 'FormBlockProvider', + 'x-decorator-props': { + resource: 'T2615', + collection: 'T2615', + }, + 'x-designer': 'FormV2.Designer', + 'x-component': 'CardItem', + 'x-component-props': {}, + 'x-index': 1, + properties: { + '9i2u8628hoz': { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'FormV2', + 'x-component-props': { + useProps: '{{ useFormBlockProps }}', + }, + 'x-index': 1, + properties: { + grid: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid', + 'x-initializer': 'FormItemInitializers', + 'x-index': 1, + properties: { + i7cb2o172ey: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Row', + 'x-index': 1, + properties: { + enue1mnnt4g: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Col', + 'x-index': 1, + properties: { + m2o: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'string', + 'x-designer': 'FormItem.Designer', + 'x-component': 'CollectionField', + 'x-decorator': 'FormItem', + 'x-collection-field': 'T2615.m2o', + 'x-component-props': {}, + 'x-index': 1, + 'x-uid': 'vtclwzomalz', + 'x-async': false, + }, + }, + 'x-uid': 'g837gkiq4wy', + 'x-async': false, + }, + }, + 'x-uid': '7vumu2u8h6x', + 'x-async': false, + }, + qfr6n6ymx77: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Row', + 'x-index': 2, + properties: { + ldlk5ifn56r: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Col', + 'x-index': 1, + properties: { + 'm2o.m2oOfTarget1': { + 'x-uid': 'sos7suq8jac', + _isJSONSchemaObject: true, + version: '2.0', + type: 'string', + 'x-designer': 'FormItem.Designer', + 'x-component': 'CollectionField', + 'x-read-pretty': true, + 'x-component-props': { + 'pattern-disable': true, + fieldNames: { + label: 'id', + value: 'id', + }, + mode: 'Nester', + }, + 'x-decorator': 'FormItem', + 'x-collection-field': + 'T2615.m2o.m2oOfTarget1', + 'x-index': 1, + default: null, + properties: { + f1l1qqex42p: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': + 'AssociationField.Nester', + 'x-index': 1, + properties: { + grid: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid', + 'x-initializer': + 'FormItemInitializers', + properties: { + '3wg2gga1tgx': { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Row', + properties: { + jphbd0t9pya: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Col', + properties: { + id: { + _isJSONSchemaObject: + true, + version: '2.0', + type: 'string', + 'x-designer': + 'FormItem.Designer', + 'x-component': + 'CollectionField', + 'x-decorator': + 'FormItem', + 'x-collection-field': + 'T2615Target2.id', + 'x-component-props': {}, + 'x-read-pretty': true, + 'x-uid': '7b8oc8mukl8', + 'x-async': false, + 'x-index': 1, + }, + m2oOfTarget2: { + _isJSONSchemaObject: + true, + version: '2.0', + type: 'string', + 'x-designer': + 'FormItem.Designer', + 'x-component': + 'CollectionField', + 'x-decorator': + 'FormItem', + 'x-collection-field': + 'T2615Target2.m2oOfTarget2', + 'x-component-props': {}, + properties: { + gvf4lwpwqvr: { + _isJSONSchemaObject: + true, + version: '2.0', + type: 'void', + title: + '{{ t("View record") }}', + 'x-component': + 'AssociationField.Viewer', + 'x-component-props': + { + className: + 'nb-action-popup', + }, + 'x-index': 1, + 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("Details")}}', + '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': + 'RecordBlockInitializers', + 'x-uid': + 'fen65isdi05', + 'x-async': + false, + 'x-index': 1, + }, + }, + 'x-uid': + 'ict6mk9c9dg', + 'x-async': + false, + 'x-index': 1, + }, + }, + 'x-uid': + 'nld7ff0tdbv', + 'x-async': + false, + 'x-index': 1, + }, + }, + 'x-uid': + '313g2f8cj1r', + 'x-async': false, + }, + }, + 'x-uid': 'ryf842sv29w', + 'x-async': false, + 'x-index': 2, + }, + }, + 'x-uid': 'crqnl1a6qzr', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'bjvuyt9tu2y', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': '46ypgnhxfg2', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'kppb0578oc0', + 'x-async': false, + }, + '0bqrmbk4dm0': { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + title: '{{ t("View record") }}', + 'x-component': + 'AssociationField.Viewer', + 'x-component-props': { + className: 'nb-action-popup', + }, + 'x-index': 2, + 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("Details")}}', + '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': + 'RecordBlockInitializers', + properties: { + dksoesw9cnq: { + _isJSONSchemaObject: + true, + version: '2.0', + type: 'void', + 'x-component': + 'Grid.Row', + properties: { + n82qzgbe8vp: { + _isJSONSchemaObject: + true, + version: '2.0', + type: 'void', + 'x-component': + 'Grid.Col', + properties: { + stqrc22o99g: { + _isJSONSchemaObject: + true, + version: '2.0', + type: 'void', + 'x-acl-action-props': + { + skipScopeCheck: + false, + }, + 'x-acl-action': + 'T2615Target1.m2oOfTarget1:update', + 'x-decorator': + 'FormBlockProvider', + 'x-decorator-props': + { + useSourceId: + '{{ useSourceIdFromParentRecord }}', + useParams: + '{{ useParamsFromRecord }}', + action: + 'get', + resource: + 'T2615Target1.m2oOfTarget1', + collection: + 'T2615Target2', + association: + 'T2615Target1.m2oOfTarget1', + }, + 'x-designer': + 'FormV2.Designer', + 'x-component': + 'CardItem', + 'x-component-props': + {}, + properties: { + j1wlc1fsg8h: { + _isJSONSchemaObject: + true, + version: + '2.0', + type: 'void', + 'x-component': + 'FormV2', + 'x-component-props': + { + useProps: + '{{ useFormBlockProps }}', + }, + properties: + { + grid: { + _isJSONSchemaObject: + true, + version: + '2.0', + type: 'void', + 'x-component': + 'Grid', + 'x-initializer': + 'FormItemInitializers', + 'x-uid': + 'slesgjv4uxx', + 'x-async': + false, + 'x-index': 1, + }, + actions: + { + _isJSONSchemaObject: + true, + version: + '2.0', + type: 'void', + 'x-initializer': + 'UpdateFormActionInitializers', + 'x-component': + 'ActionBar', + 'x-component-props': + { + layout: + 'one-column', + style: + { + marginTop: 24, + }, + }, + 'x-uid': + '530aei12n31', + 'x-async': + false, + 'x-index': 2, + }, + }, + 'x-uid': + 'lj3m9mv944b', + 'x-async': + false, + 'x-index': 1, + }, + }, + 'x-uid': + 'evpd62m3q7k', + 'x-async': + false, + 'x-index': 1, + }, + }, + 'x-uid': + 'dpnhmlgpxf6', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'ruk9rhunoa0', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'v260my8cg4k', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'o8cdftjs2lw', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'bqke3e0jzo2', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'xmvwga75f7l', + 'x-async': false, + }, + }, + 'x-async': false, + }, + }, + 'x-uid': 'essybj9hlwd', + 'x-async': false, + }, + }, + 'x-uid': 'qb9mj6yj01j', + 'x-async': false, + }, + }, + 'x-uid': 'f2fhjs2ejnj', + 'x-async': false, + }, + actions: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-initializer': 'CreateFormActionInitializers', + 'x-component': 'ActionBar', + 'x-component-props': { + layout: 'one-column', + style: { + marginTop: 24, + }, + }, + 'x-index': 2, + 'x-uid': 'c4b36vqkq6u', + 'x-async': false, + }, + }, + 'x-uid': 'm74kumi1e9a', + 'x-async': false, + }, + }, + 'x-uid': '18pkdz8ts5y', + 'x-async': false, + }, + }, + 'x-uid': 'bwhvrn3czfw', + 'x-async': false, + }, + }, + 'x-uid': '624h0vckaff', + 'x-async': false, + }, + }, + 'x-uid': 'zu8n5qkbcuq', + 'x-async': false, + }, + }, + 'x-uid': '8b46pgf3tj5', + 'x-async': false, + }, + }, + 'x-uid': 'sdxjbqf4iy6', + 'x-async': false, + }, + }, + 'x-uid': '5tv6ty40alj', + 'x-async': false, + }, + }, + 'x-uid': 'zdh1hzm1npt', + 'x-async': false, + }, + }, + 'x-uid': 'pryhuyw95qq', + 'x-async': false, + }, + '3m6w3iz4c5t': { + _isJSONSchemaObject: true, + version: '2.0', + type: 'array', + 'x-initializer': 'TableColumnInitializers', + 'x-component': 'TableV2', + 'x-component-props': { + rowKey: 'id', + rowSelection: { + type: 'checkbox', + }, + useProps: '{{ useTableBlockProps }}', + }, + 'x-index': 2, + 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': 'TableActionColumnInitializers', + 'x-index': 1, + properties: { + actions: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-decorator': 'DndContext', + 'x-component': 'Space', + 'x-component-props': { + split: '|', + }, + 'x-index': 1, + properties: { + yych9x95hrp: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + title: 'Edit record', + 'x-action': 'update', + 'x-designer': 'Action.Designer', + 'x-component': 'Action.Link', + 'x-component-props': { + openMode: 'drawer', + danger: false, + }, + 'x-decorator': 'ACLActionProvider', + 'x-designer-props': { + linkageAction: true, + }, + 'x-index': 1, + 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-index': 1, + properties: { + tabs: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Tabs', + 'x-component-props': {}, + 'x-initializer': 'TabPaneInitializers', + 'x-index': 1, + properties: { + tab1: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + title: '{{t("Edit")}}', + 'x-component': 'Tabs.TabPane', + 'x-designer': 'Tabs.Designer', + 'x-component-props': {}, + 'x-index': 1, + properties: { + grid: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid', + 'x-initializer': 'RecordBlockInitializers', + 'x-index': 1, + properties: { + l79xm6sfjst: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Row', + 'x-index': 1, + properties: { + '7cyquusb2ca': { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Col', + 'x-index': 1, + properties: { + '8dxzx9t0571': { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-acl-action-props': { + skipScopeCheck: false, + }, + 'x-acl-action': 'T2615:update', + 'x-decorator': 'FormBlockProvider', + 'x-decorator-props': { + useSourceId: '{{ useSourceIdFromParentRecord }}', + useParams: '{{ useParamsFromRecord }}', + action: 'get', + resource: 'T2615', + collection: 'T2615', + }, + 'x-designer': 'FormV2.Designer', + 'x-component': 'CardItem', + 'x-component-props': {}, + 'x-index': 1, + properties: { + '21sxtdkbcw0': { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'FormV2', + 'x-component-props': { + useProps: '{{ useFormBlockProps }}', + }, + 'x-index': 1, + properties: { + grid: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid', + 'x-initializer': 'FormItemInitializers', + 'x-index': 1, + properties: { + '7eayo28dgzo': { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Row', + 'x-index': 1, + properties: { + oj9yj21ujd8: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Col', + 'x-index': 1, + properties: { + m2o: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'string', + 'x-designer': 'FormItem.Designer', + 'x-component': 'CollectionField', + 'x-decorator': 'FormItem', + 'x-collection-field': 'T2615.m2o', + 'x-component-props': {}, + 'x-index': 1, + 'x-uid': 'ldansmb778w', + 'x-async': false, + }, + }, + 'x-uid': 'xdn43xxuamx', + 'x-async': false, + }, + }, + 'x-uid': 'baciuspht8n', + 'x-async': false, + }, + zsdbhvdvaru: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Row', + 'x-index': 2, + properties: { + '082hatydnd0': { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Col', + 'x-index': 1, + properties: { + 'm2o.m2oOfTarget1': { + 'x-uid': 'k9zjnfbcr35', + _isJSONSchemaObject: true, + version: '2.0', + type: 'string', + 'x-designer': 'FormItem.Designer', + 'x-component': 'CollectionField', + 'x-read-pretty': true, + 'x-component-props': { + 'pattern-disable': true, + fieldNames: { + label: 'id', + value: 'id', + }, + mode: 'Nester', + }, + 'x-decorator': 'FormItem', + 'x-collection-field': + 'T2615.m2o.m2oOfTarget1', + 'x-index': 1, + properties: { + '1fihmdamirf': { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': + 'AssociationField.Nester', + 'x-index': 1, + properties: { + grid: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid', + 'x-initializer': + 'FormItemInitializers', + properties: { + ddo3fvkz6hw: { + _isJSONSchemaObject: + true, + version: '2.0', + type: 'void', + 'x-component': + 'Grid.Row', + properties: { + '3vttqmamk12': { + _isJSONSchemaObject: + true, + version: '2.0', + type: 'void', + 'x-component': + 'Grid.Col', + properties: { + id: { + _isJSONSchemaObject: + true, + version: '2.0', + type: 'string', + 'x-designer': + 'FormItem.Designer', + 'x-component': + 'CollectionField', + 'x-decorator': + 'FormItem', + 'x-collection-field': + 'T2615Target2.id', + 'x-component-props': + {}, + 'x-read-pretty': + true, + 'x-uid': + 'k7r752iwwd5', + 'x-async': + false, + 'x-index': 1, + }, + }, + 'x-uid': + '3hduhm9mz36', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': '7zuhu25svbi', + 'x-async': false, + 'x-index': 1, + }, + sckuusv6msv: { + _isJSONSchemaObject: + true, + version: '2.0', + type: 'void', + 'x-component': + 'Grid.Row', + properties: { + '15osna9mddn': { + _isJSONSchemaObject: + true, + version: '2.0', + type: 'void', + 'x-component': + 'Grid.Col', + properties: { + m2oOfTarget2: { + _isJSONSchemaObject: + true, + version: '2.0', + type: 'string', + 'x-designer': + 'FormItem.Designer', + 'x-component': + 'CollectionField', + 'x-decorator': + 'FormItem', + 'x-collection-field': + 'T2615Target2.m2oOfTarget2', + 'x-component-props': + {}, + 'x-uid': + '74cv1njsuun', + 'x-async': + false, + 'x-index': 1, + }, + }, + 'x-uid': + 'av4n8b963yx', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'rfkz4hhvner', + 'x-async': false, + 'x-index': 2, + }, + }, + 'x-uid': 'xq6xht5akci', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': '9jr86f58foi', + 'x-async': false, + }, + }, + 'x-async': false, + }, + }, + 'x-uid': 'vxhthrams8z', + 'x-async': false, + }, + }, + 'x-uid': 'd7agqc58s51', + 'x-async': false, + }, + }, + 'x-uid': 'uk9vpzq4pnj', + 'x-async': false, + }, + actions: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-initializer': 'UpdateFormActionInitializers', + 'x-component': 'ActionBar', + 'x-component-props': { + layout: 'one-column', + style: { + marginTop: 24, + }, + }, + 'x-index': 2, + 'x-uid': 'v632h6tvnme', + 'x-async': false, + }, + }, + 'x-uid': '1wqcw49vvf7', + 'x-async': false, + }, + }, + 'x-uid': 'nyfys5ovl5w', + 'x-async': false, + }, + }, + 'x-uid': 'tpwfljzj6jt', + 'x-async': false, + }, + }, + 'x-uid': 'klaug32w9fs', + 'x-async': false, + }, + }, + 'x-uid': 'um1sus2iors', + 'x-async': false, + }, + }, + 'x-uid': 'ezv19uwk15h', + 'x-async': false, + }, + }, + 'x-uid': 'nbprm1hziow', + 'x-async': false, + }, + }, + 'x-uid': '88xlxa1wznb', + 'x-async': false, + }, + }, + 'x-uid': 'oa9csm0i30h', + 'x-async': false, + }, + t452of8muaq: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + title: 'View record', + 'x-action': 'view', + 'x-designer': 'Action.Designer', + 'x-component': 'Action.Link', + 'x-component-props': { + openMode: 'drawer', + danger: false, + }, + 'x-decorator': 'ACLActionProvider', + 'x-designer-props': { + linkageAction: true, + }, + 'x-index': 2, + properties: { + drawer: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + title: '{{ t("View record") }}', + 'x-component': 'Action.Container', + 'x-component-props': { + className: 'nb-action-popup', + }, + 'x-index': 1, + properties: { + tabs: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Tabs', + 'x-component-props': {}, + 'x-initializer': 'TabPaneInitializers', + 'x-index': 1, + properties: { + tab1: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + title: '{{t("Details")}}', + 'x-component': 'Tabs.TabPane', + 'x-designer': 'Tabs.Designer', + 'x-component-props': {}, + 'x-index': 1, + properties: { + grid: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid', + 'x-initializer': 'RecordBlockInitializers', + 'x-index': 1, + properties: { + nlnfd9hnl53: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Row', + 'x-index': 1, + properties: { + o1mvvolrr3n: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Col', + 'x-index': 1, + properties: { + '02tm0tr9gie': { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-acl-action': 'T2615:get', + 'x-decorator': 'FormBlockProvider', + 'x-decorator-props': { + resource: 'T2615', + collection: 'T2615', + readPretty: true, + action: 'get', + useParams: '{{ useParamsFromRecord }}', + useSourceId: '{{ useSourceIdFromParentRecord }}', + }, + 'x-designer': 'FormV2.ReadPrettyDesigner', + 'x-component': 'CardItem', + 'x-index': 1, + properties: { + xa10ops1tmr: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'FormV2', + 'x-read-pretty': true, + 'x-component-props': { + useProps: '{{ useFormBlockProps }}', + }, + 'x-index': 1, + properties: { + actions: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-initializer': + 'ReadPrettyFormActionInitializers', + 'x-component': 'ActionBar', + 'x-component-props': { + style: { + marginBottom: 24, + }, + }, + 'x-index': 1, + 'x-uid': 'j14isfxwsue', + 'x-async': false, + }, + grid: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid', + 'x-initializer': + 'ReadPrettyFormItemInitializers', + 'x-index': 2, + properties: { + j9mxulol74m: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Row', + 'x-index': 1, + properties: { + r4alweypz03: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Col', + 'x-index': 1, + properties: { + m2o: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'string', + 'x-designer': 'FormItem.Designer', + 'x-component': 'CollectionField', + 'x-decorator': 'FormItem', + 'x-collection-field': 'T2615.m2o', + 'x-component-props': {}, + 'x-index': 1, + 'x-uid': 'x3rmljeq2cp', + 'x-async': false, + }, + }, + 'x-uid': '2csk6wqip9t', + 'x-async': false, + }, + }, + 'x-uid': '9kw27wn78fi', + 'x-async': false, + }, + xb97qr5ustn: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Row', + 'x-index': 2, + properties: { + wje8oyfbn1d: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Col', + 'x-index': 1, + properties: { + 'm2o.m2oOfTarget1': { + 'x-uid': 'yax1x9facdc', + _isJSONSchemaObject: true, + version: '2.0', + type: 'string', + 'x-designer': 'FormItem.Designer', + 'x-component': 'CollectionField', + 'x-read-pretty': true, + 'x-component-props': { + 'pattern-disable': true, + fieldNames: { + label: 'id', + value: 'id', + }, + mode: 'Nester', + }, + 'x-decorator': 'FormItem', + 'x-collection-field': + 'T2615.m2o.m2oOfTarget1', + 'x-index': 1, + properties: { + '025zh9o3ey9': { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': + 'AssociationField.Nester', + 'x-index': 1, + properties: { + grid: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid', + 'x-initializer': + 'FormItemInitializers', + properties: { + c5mcb8foh05: { + _isJSONSchemaObject: + true, + version: '2.0', + type: 'void', + 'x-component': + 'Grid.Row', + properties: { + cdxgpdl0ygx: { + _isJSONSchemaObject: + true, + version: '2.0', + type: 'void', + 'x-component': + 'Grid.Col', + properties: { + id: { + _isJSONSchemaObject: + true, + version: '2.0', + type: 'string', + 'x-designer': + 'FormItem.Designer', + 'x-component': + 'CollectionField', + 'x-decorator': + 'FormItem', + 'x-collection-field': + 'T2615Target2.id', + 'x-component-props': + {}, + 'x-read-pretty': + true, + 'x-uid': + '52n1wmp7uc9', + 'x-async': + false, + 'x-index': 1, + }, + }, + 'x-uid': + 'xpir96php8c', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'd0pnmwckejl', + 'x-async': false, + 'x-index': 1, + }, + '7mn5oytntt3': { + _isJSONSchemaObject: + true, + version: '2.0', + type: 'void', + 'x-component': + 'Grid.Row', + properties: { + dh2la7dad9l: { + _isJSONSchemaObject: + true, + version: '2.0', + type: 'void', + 'x-component': + 'Grid.Col', + properties: { + m2oOfTarget2: { + _isJSONSchemaObject: + true, + version: '2.0', + type: 'string', + 'x-designer': + 'FormItem.Designer', + 'x-component': + 'CollectionField', + 'x-decorator': + 'FormItem', + 'x-collection-field': + 'T2615Target2.m2oOfTarget2', + 'x-component-props': + {}, + 'x-uid': + 'jbhrkr56jzm', + 'x-async': + false, + 'x-index': 1, + }, + }, + 'x-uid': + 'khgwbf72ldf', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'vaddvt91z5v', + 'x-async': false, + 'x-index': 2, + }, + }, + 'x-uid': 'jfhkqtlqzng', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'wc0npkmsoro', + 'x-async': false, + }, + }, + 'x-async': false, + }, + }, + 'x-uid': 'y70rl9d06uj', + 'x-async': false, + }, + }, + 'x-uid': 'lgn85q6uj17', + 'x-async': false, + }, + }, + 'x-uid': '8w5c5hak1gr', + 'x-async': false, + }, + }, + 'x-uid': 'whvoy1l9hj9', + 'x-async': false, + }, + }, + 'x-uid': 'e84i0kfwhbf', + 'x-async': false, + }, + }, + 'x-uid': 'smmxsrl51a8', + 'x-async': false, + }, + }, + 'x-uid': 'ow16bzbg6ug', + 'x-async': false, + }, + }, + 'x-uid': 'ai4yry7e0vc', + 'x-async': false, + }, + }, + 'x-uid': '57iueiaapm4', + 'x-async': false, + }, + }, + 'x-uid': 'ai5i8ek5xw1', + 'x-async': false, + }, + }, + 'x-uid': 'x4lflnwlshu', + 'x-async': false, + }, + }, + 'x-uid': '2hlltge34f6', + 'x-async': false, + }, + }, + 'x-uid': '3zx8qacchqt', + 'x-async': false, + }, + }, + 'x-uid': 'jzvgiopg3tb', + 'x-async': false, + }, + }, + 'x-uid': 'dampx66bp7j', + 'x-async': false, + }, + }, + 'x-uid': 'il72zotxejz', + 'x-async': false, + }, + }, + 'x-uid': 'igvr5bmn6wg', + 'x-async': false, + }, + }, + 'x-uid': 'ggvkrz6cc9r', + 'x-async': false, + }, + }, + 'x-uid': 'mikatwm1nop', + 'x-async': false, + }, + }, + 'x-uid': 'sv7dxotrdmq', + 'x-async': true, + }, +}; + export const T2200 = { pageSchema: { _isJSONSchemaObject: true, diff --git a/packages/core/client/src/modules/table/__e2e__/actions/duplicate.test.ts b/packages/core/client/src/modules/table/__e2e__/actions/duplicate.test.ts index cfc8f8f30..b74e33433 100644 --- a/packages/core/client/src/modules/table/__e2e__/actions/duplicate.test.ts +++ b/packages/core/client/src/modules/table/__e2e__/actions/duplicate.test.ts @@ -2,7 +2,7 @@ import { expect, test } from '@nocobase/test/e2e'; import { T2187 } from '../templatesOfBug'; // fix https://nocobase.height.app/T-2187 -test('BUG: in the Duplicate mode, the Roles field should not have a value after clicking it because it is not selected', async ({ +test('in the Duplicate mode, the Roles field should not have a value after clicking it because it is not selected', async ({ page, mockPage, }) => { diff --git a/packages/core/client/src/modules/table/__e2e__/actions/filter.test.ts b/packages/core/client/src/modules/table/__e2e__/actions/filter.test.ts index 9918a2771..48cbc840d 100644 --- a/packages/core/client/src/modules/table/__e2e__/actions/filter.test.ts +++ b/packages/core/client/src/modules/table/__e2e__/actions/filter.test.ts @@ -2,7 +2,7 @@ import { expect, test } from '@nocobase/test/e2e'; import { T2183, T2186 } from '../templatesOfBug'; // fix https://nocobase.height.app/T-2183 -test('BUG: should save conditions', async ({ page, mockPage }) => { +test('should save conditions', async ({ page, mockPage }) => { await mockPage(T2183).goto(); await page.getByLabel('action-Filter.Action-Filter-filter-users-table').click(); await page.getByText('Add condition', { exact: true }).click(); @@ -19,7 +19,7 @@ test('BUG: should save conditions', async ({ page, mockPage }) => { }); // fix https://nocobase.height.app/T-2186 -test('BUG: the input box displayed should correspond to the field type', async ({ page, mockPage }) => { +test('the input box displayed should correspond to the field type', async ({ page, mockPage }) => { await mockPage(T2186).goto(); await page.getByLabel('action-Filter.Action-Filter-filter-users-table').click(); diff --git a/packages/core/client/src/schema-component/antd/form-item/hooks/useLazyLoadDisplayAssociationFieldsOfForm.ts b/packages/core/client/src/schema-component/antd/form-item/hooks/useLazyLoadDisplayAssociationFieldsOfForm.ts index 497bb8aa5..43d995472 100644 --- a/packages/core/client/src/schema-component/antd/form-item/hooks/useLazyLoadDisplayAssociationFieldsOfForm.ts +++ b/packages/core/client/src/schema-component/antd/form-item/hooks/useLazyLoadDisplayAssociationFieldsOfForm.ts @@ -3,6 +3,7 @@ import { useField, useFieldSchema, useForm } from '@formily/react'; import { nextTick } from '@nocobase/utils/client'; import _ from 'lodash'; import { useEffect, useRef } from 'react'; +import { useAssociationNames } from '../../../../block-provider'; import { useCollection, useCollectionManager } from '../../../../collection-manager'; import { useFlag } from '../../../../flag-provider'; import { useVariables } from '../../../../variables'; @@ -25,6 +26,7 @@ const useLazyLoadDisplayAssociationFieldsOfForm = () => { const field = useField(); const { formValue: subFormValue } = useSubFormValue(); const { isInSubForm, isInSubTable } = useFlag() || {}; + const { getAssociationAppends } = useAssociationNames(); const schemaName = fieldSchema.name.toString(); const formValue = _.cloneDeep(isInSubForm || isInSubTable ? subFormValue : form.values); @@ -66,8 +68,10 @@ const useLazyLoadDisplayAssociationFieldsOfForm = () => { return; } + const { appends } = getAssociationAppends(); + variables - .parseVariable(variableString, formVariable) + .parseVariable(variableString, formVariable, { appends }) .then((value) => { nextTick(() => { const result = transformVariableValue(value, { targetCollectionField: collectionFieldRef.current }); diff --git a/packages/core/client/src/variables/VariablesProvider.tsx b/packages/core/client/src/variables/VariablesProvider.tsx index 954ad58b3..0dd15911f 100644 --- a/packages/core/client/src/variables/VariablesProvider.tsx +++ b/packages/core/client/src/variables/VariablesProvider.tsx @@ -51,7 +51,14 @@ const VariablesProvider = ({ children }) => { * 3. 如果某个 `key` 不存在,且 `key` 不是一个关联字段,则返回当前值 */ const getValue = useCallback( - async (variablePath: string, localVariables?: VariableOption[]) => { + async ( + variablePath: string, + localVariables?: VariableOption[], + options?: { + /** 第一次请求时,需要包含的关系字段 */ + appends?: string[]; + }, + ) => { const list = variablePath.split('.'); const variableName = list[0]; const _variableToCollectionName = mergeVariableToCollectionNameWithLocalVariables( @@ -85,6 +92,9 @@ const VariablesProvider = ({ children }) => { const result = api .request({ url, + params: { + appends: options?.appends, + }, }) .then((data) => { clearRequested(url); @@ -106,6 +116,9 @@ const VariablesProvider = ({ children }) => { } else { const waitForData = api.request({ url, + params: { + appends: options?.appends, + }, }); stashRequested(url, waitForData); data = await waitForData; @@ -180,7 +193,14 @@ const VariablesProvider = ({ children }) => { * @param localVariables 局部变量,解析完成后会被清除 * @returns */ - async (str: string, localVariables?: VariableOption | VariableOption[]) => { + async ( + str: string, + localVariables?: VariableOption | VariableOption[], + options?: { + /** 第一次请求时,需要包含的关系字段 */ + appends?: string[]; + }, + ) => { if (!isVariable(str)) { return str; } @@ -190,7 +210,7 @@ const VariablesProvider = ({ children }) => { } const path = getPath(str); - const value = await getValue(path, localVariables as VariableOption[]); + const value = await getValue(path, localVariables as VariableOption[], options); return uniq(filterEmptyValues(value)); }, diff --git a/packages/core/client/src/variables/types.ts b/packages/core/client/src/variables/types.ts index 30f390603..23209cbc7 100644 --- a/packages/core/client/src/variables/types.ts +++ b/packages/core/client/src/variables/types.ts @@ -29,7 +29,14 @@ export interface VariablesContextType { * console.log(value); // test * ``` */ - parseVariable: (str: string, localVariable?: VariableOption | VariableOption[]) => Promise; + parseVariable: ( + str: string, + localVariable?: VariableOption | VariableOption[], + options?: { + /** 第一次请求时,需要包含的关系字段 */ + appends?: string[]; + }, + ) => Promise; /** * 注册变量 * @param variableOption 新变量的配置 diff --git a/packages/core/test/setup/client.ts b/packages/core/test/setup/client.ts index 35e90a3ec..f0ec55cbe 100644 --- a/packages/core/test/setup/client.ts +++ b/packages/core/test/setup/client.ts @@ -34,6 +34,10 @@ Object.defineProperty(window, 'matchMedia', { const { getComputedStyle } = window; window.getComputedStyle = (elt) => getComputedStyle(elt); +// 解决 https://github.com/nocobase/nocobase/actions/runs/7353181446/job/20018831007?pr=3282 +// 该错误是发生在测试环境之后的,应该是存在异步代码没有 await 导致的,但是不知道是哪里的问题,所以先这样处理 +global.window = window; + /** * 解决 TypeError: range.getBoundingClientRect is not a function * 参见:https://github.com/jsdom/jsdom/issues/3002 diff --git a/packages/plugins/@nocobase/plugin-collection-manager/src/client/__e2e__/fields/password/schemaSettings.test.ts b/packages/plugins/@nocobase/plugin-collection-manager/src/client/__e2e__/fields/password/schemaSettings.test.ts index e10604a66..7ca0bc4d4 100644 --- a/packages/plugins/@nocobase/plugin-collection-manager/src/client/__e2e__/fields/password/schemaSettings.test.ts +++ b/packages/plugins/@nocobase/plugin-collection-manager/src/client/__e2e__/fields/password/schemaSettings.test.ts @@ -71,6 +71,7 @@ test.describe('form item & create form', () => { }); test('pattern', async ({ page, mockPage }) => { + test.slow(); await testPattern({ page, gotoPage: () => diff --git a/packages/plugins/@nocobase/plugin-workflow-manual/src/client/instruction/DetailsBlockProvider.tsx b/packages/plugins/@nocobase/plugin-workflow-manual/src/client/instruction/DetailsBlockProvider.tsx index 6b0078a3d..6b586730d 100644 --- a/packages/plugins/@nocobase/plugin-workflow-manual/src/client/instruction/DetailsBlockProvider.tsx +++ b/packages/plugins/@nocobase/plugin-workflow-manual/src/client/instruction/DetailsBlockProvider.tsx @@ -1,4 +1,3 @@ -import React, { useRef, useMemo, useContext } from 'react'; import { createForm } from '@formily/core'; import { useField } from '@formily/react'; import { @@ -9,8 +8,9 @@ import { useAPIClient, useAssociationNames, } from '@nocobase/client'; -import { parse } from '@nocobase/utils/client'; import { useFlowContext } from '@nocobase/plugin-workflow/client'; +import { parse } from '@nocobase/utils/client'; +import React, { useContext, useMemo, useRef } from 'react'; function useFlowContextData(dataSource) { const { execution, nodes } = useFlowContext(); @@ -37,7 +37,8 @@ function useFlowContextData(dataSource) { export function DetailsBlockProvider(props) { const field = useField(); const formBlockRef = useRef(null); - const { appends, updateAssociationValues } = useAssociationNames(); + const { getAssociationAppends } = useAssociationNames(); + const { appends, updateAssociationValues } = getAssociationAppends(); const values = useFlowContextData(props.dataSource); const form = useMemo( diff --git a/packages/plugins/@nocobase/plugin-workflow-manual/src/client/instruction/FormBlockProvider.tsx b/packages/plugins/@nocobase/plugin-workflow-manual/src/client/instruction/FormBlockProvider.tsx index 6144baca8..f7bc931e3 100644 --- a/packages/plugins/@nocobase/plugin-workflow-manual/src/client/instruction/FormBlockProvider.tsx +++ b/packages/plugins/@nocobase/plugin-workflow-manual/src/client/instruction/FormBlockProvider.tsx @@ -19,7 +19,8 @@ export function FormBlockProvider(props) { const fieldSchema = useFieldSchema(); const field = useField(); const formBlockRef = useRef(null); - const { appends, updateAssociationValues } = useAssociationNames(); + const { getAssociationAppends } = useAssociationNames(); + const { appends, updateAssociationValues } = getAssociationAppends(); const [formKey] = Object.keys(fieldSchema.toJSON().properties ?? {}); const values = userJob?.result?.[formKey]; diff --git a/yarn.lock b/yarn.lock index bed847086..03070f55c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4215,6 +4215,11 @@ dependencies: eslint-scope "5.1.1" +"@nocobase/plugin-workflow-test@>=0.17.0-alpha.3": + version "0.17.0-alpha.7" + resolved "https://registry.yarnpkg.com/@nocobase/plugin-workflow-test/-/plugin-workflow-test-0.17.0-alpha.7.tgz#219a3a1e91e51bec08b1adbb1c4c5c9c7184ecce" + integrity sha512-krZlo1xDM66spbQG6jAYSraxazuxCuA2rD9TxptFQXjkAMTGkuDilJ+edMj6p866N3nyzvFh8lZ2/XY1HUC7Xw== + "@node-saml/node-saml@^4.0.2": version "4.0.5" resolved "https://registry.npmmirror.com/@node-saml/node-saml/-/node-saml-4.0.5.tgz#039e387095b54639b06df62b1b4a6d8941c6d907"