mirror of
https://github.com/nocobase/nocobase
synced 2024-11-14 16:13:29 +00:00
fix(varaible): fix Table selected records (#5337)
Some checks are pending
auto-merge / push-commit (push) Waiting to run
Build Docker Image / build-and-push (push) Waiting to run
Build Pro Image / build-and-push (push) Waiting to run
deploy client docs / Build (push) Waiting to run
E2E / Build (push) Waiting to run
E2E / Core and plugins (push) Blocked by required conditions
E2E / plugin-workflow (push) Blocked by required conditions
E2E / plugin-workflow-approval (push) Blocked by required conditions
E2E / plugin-data-source-main (push) Blocked by required conditions
E2E / Comment on PR (push) Blocked by required conditions
NocoBase Backend Test / sqlite-test (20, false) (push) Waiting to run
NocoBase Backend Test / sqlite-test (20, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, nocobase, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, nocobase, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, public, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, public, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, nocobase, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, nocobase, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, public, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, public, true) (push) Waiting to run
NocoBase Backend Test / mysql-test (20, false) (push) Waiting to run
NocoBase Backend Test / mysql-test (20, true) (push) Waiting to run
NocoBase Backend Test / mariadb-test (20, false) (push) Waiting to run
NocoBase Backend Test / mariadb-test (20, true) (push) Waiting to run
NocoBase FrontEnd Test / frontend-test (18) (push) Waiting to run
Test on Windows / build (push) Waiting to run
Some checks are pending
auto-merge / push-commit (push) Waiting to run
Build Docker Image / build-and-push (push) Waiting to run
Build Pro Image / build-and-push (push) Waiting to run
deploy client docs / Build (push) Waiting to run
E2E / Build (push) Waiting to run
E2E / Core and plugins (push) Blocked by required conditions
E2E / plugin-workflow (push) Blocked by required conditions
E2E / plugin-workflow-approval (push) Blocked by required conditions
E2E / plugin-data-source-main (push) Blocked by required conditions
E2E / Comment on PR (push) Blocked by required conditions
NocoBase Backend Test / sqlite-test (20, false) (push) Waiting to run
NocoBase Backend Test / sqlite-test (20, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, nocobase, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, nocobase, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, public, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, public, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, nocobase, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, nocobase, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, public, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, public, true) (push) Waiting to run
NocoBase Backend Test / mysql-test (20, false) (push) Waiting to run
NocoBase Backend Test / mysql-test (20, true) (push) Waiting to run
NocoBase Backend Test / mariadb-test (20, false) (push) Waiting to run
NocoBase Backend Test / mariadb-test (20, true) (push) Waiting to run
NocoBase FrontEnd Test / frontend-test (18) (push) Waiting to run
Test on Windows / build (push) Waiting to run
* fix(varaible): fix Table selected records * test: add e2e test * chore: make unit tests pass * chore: make unit test pass
This commit is contained in:
parent
cf316f6971
commit
570df86261
@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
import { expect, test } from '@nocobase/test/e2e';
|
||||
import { APIToken, tableViewLinkageRulesVariables } from './templates';
|
||||
import { APIToken, tableSelectedRecords, tableViewLinkageRulesVariables } from './templates';
|
||||
|
||||
test.describe('variables', () => {
|
||||
test('linkage rules of table view action', async ({ page, mockPage }) => {
|
||||
@ -43,4 +43,32 @@ test.describe('variables', () => {
|
||||
await page.getByRole('button', { name: 'OK', exact: true }).click();
|
||||
await expect(page.getByRole('textbox')).toHaveValue(token);
|
||||
});
|
||||
|
||||
test('Table selected records', async ({ page, mockPage, mockRecord }) => {
|
||||
const nocoPage = await mockPage(tableSelectedRecords).waitForInit();
|
||||
const record = await mockRecord('testTableSelectedRecords');
|
||||
await nocoPage.goto();
|
||||
|
||||
// 1. First select a row, then click Add new
|
||||
await page.getByLabel('table-index-1', { exact: true }).click();
|
||||
await page.getByLabel('action-Action-Add new-create-').click();
|
||||
|
||||
// 2. Set default value for the field, field content should be the associated records of the previously selected record
|
||||
await page.getByLabel('block-item-CollectionField-').hover();
|
||||
await page.getByLabel('designer-schema-settings-CollectionField-fieldSettings:FormItem-').hover();
|
||||
await page.getByRole('menuitem', { name: 'Set default value' }).click();
|
||||
await page.getByLabel('variable-button').click();
|
||||
await page.getByRole('menuitemcheckbox', { name: 'Table selected records right' }).click();
|
||||
await page.getByRole('menuitemcheckbox', { name: 'm2m' }).click();
|
||||
await page.getByRole('button', { name: 'OK', exact: true }).click();
|
||||
await expect(page.getByLabel('block-item-CollectionField-')).toHaveText(
|
||||
`m2m:${record.m2m.map((r) => r.id).join('')}`,
|
||||
);
|
||||
|
||||
// 3. Deselect the row, click Add new again, field content should be empty
|
||||
await page.getByLabel('drawer-Action.Container-testTableSelectedRecords-Add record-mask').click();
|
||||
await page.getByLabel('table-index-1', { exact: true }).click();
|
||||
await page.getByLabel('action-Action-Add new-create-').click();
|
||||
await expect(page.getByLabel('block-item-CollectionField-')).toHaveText('m2m:');
|
||||
});
|
||||
});
|
||||
|
@ -863,3 +863,437 @@ export const T4874 = {
|
||||
'x-index': 1,
|
||||
},
|
||||
};
|
||||
export const tableSelectedRecords = {
|
||||
collections: [
|
||||
{
|
||||
name: 'testTableSelectedRecords',
|
||||
fields: [
|
||||
{
|
||||
name: 'm2m',
|
||||
interface: 'm2m',
|
||||
target: 'testTableSelectedRecords',
|
||||
},
|
||||
{
|
||||
name: 'title',
|
||||
interface: 'input',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
pageSchema: {
|
||||
_isJSONSchemaObject: true,
|
||||
version: '2.0',
|
||||
type: 'void',
|
||||
'x-component': 'Page',
|
||||
properties: {
|
||||
bfbkuonks1e: {
|
||||
_isJSONSchemaObject: true,
|
||||
version: '2.0',
|
||||
type: 'void',
|
||||
'x-component': 'Grid',
|
||||
'x-initializer': 'page:addBlock',
|
||||
properties: {
|
||||
bbpnv79ppud: {
|
||||
_isJSONSchemaObject: true,
|
||||
version: '2.0',
|
||||
type: 'void',
|
||||
'x-component': 'Grid.Row',
|
||||
'x-app-version': '1.3.25-beta',
|
||||
properties: {
|
||||
'11nn7v51v72': {
|
||||
_isJSONSchemaObject: true,
|
||||
version: '2.0',
|
||||
type: 'void',
|
||||
'x-component': 'Grid.Col',
|
||||
'x-app-version': '1.3.25-beta',
|
||||
properties: {
|
||||
'94x4wxloe4r': {
|
||||
_isJSONSchemaObject: true,
|
||||
version: '2.0',
|
||||
type: 'void',
|
||||
'x-decorator': 'TableBlockProvider',
|
||||
'x-acl-action': 'testTableSelectedRecords:list',
|
||||
'x-use-decorator-props': 'useTableBlockDecoratorProps',
|
||||
'x-decorator-props': {
|
||||
collection: 'testTableSelectedRecords',
|
||||
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': [],
|
||||
'x-app-version': '1.3.25-beta',
|
||||
properties: {
|
||||
actions: {
|
||||
_isJSONSchemaObject: true,
|
||||
version: '2.0',
|
||||
type: 'void',
|
||||
'x-initializer': 'table:configureActions',
|
||||
'x-component': 'ActionBar',
|
||||
'x-component-props': {
|
||||
style: {
|
||||
marginBottom: 'var(--nb-spacing)',
|
||||
},
|
||||
},
|
||||
'x-app-version': '1.3.25-beta',
|
||||
properties: {
|
||||
pxcv8n30d4o: {
|
||||
_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-action-context': {
|
||||
dataSource: 'main',
|
||||
collection: 'testTableSelectedRecords',
|
||||
},
|
||||
'x-align': 'right',
|
||||
'x-acl-action-props': {
|
||||
skipScopeCheck: true,
|
||||
},
|
||||
'x-app-version': '1.3.25-beta',
|
||||
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-app-version': '1.3.25-beta',
|
||||
properties: {
|
||||
tabs: {
|
||||
_isJSONSchemaObject: true,
|
||||
version: '2.0',
|
||||
type: 'void',
|
||||
'x-component': 'Tabs',
|
||||
'x-component-props': {},
|
||||
'x-initializer': 'popup:addTab',
|
||||
'x-initializer-props': {
|
||||
gridInitializer: 'popup:addNew:addBlock',
|
||||
},
|
||||
'x-app-version': '1.3.25-beta',
|
||||
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-app-version': '1.3.25-beta',
|
||||
properties: {
|
||||
grid: {
|
||||
_isJSONSchemaObject: true,
|
||||
version: '2.0',
|
||||
type: 'void',
|
||||
'x-component': 'Grid',
|
||||
'x-initializer': 'popup:addNew:addBlock',
|
||||
'x-app-version': '1.3.25-beta',
|
||||
properties: {
|
||||
auahz06brj6: {
|
||||
_isJSONSchemaObject: true,
|
||||
version: '2.0',
|
||||
type: 'void',
|
||||
'x-component': 'Grid.Row',
|
||||
'x-app-version': '1.3.25-beta',
|
||||
properties: {
|
||||
abjk8e5yzfq: {
|
||||
_isJSONSchemaObject: true,
|
||||
version: '2.0',
|
||||
type: 'void',
|
||||
'x-component': 'Grid.Col',
|
||||
'x-app-version': '1.3.25-beta',
|
||||
properties: {
|
||||
ijm0brgvegg: {
|
||||
_isJSONSchemaObject: true,
|
||||
version: '2.0',
|
||||
type: 'void',
|
||||
'x-acl-action-props': {
|
||||
skipScopeCheck: true,
|
||||
},
|
||||
'x-acl-action': 'testTableSelectedRecords:create',
|
||||
'x-decorator': 'FormBlockProvider',
|
||||
'x-use-decorator-props': 'useCreateFormBlockDecoratorProps',
|
||||
'x-decorator-props': {
|
||||
dataSource: 'main',
|
||||
collection: 'testTableSelectedRecords',
|
||||
},
|
||||
'x-toolbar': 'BlockSchemaToolbar',
|
||||
'x-settings': 'blockSettings:createForm',
|
||||
'x-component': 'CardItem',
|
||||
'x-app-version': '1.3.25-beta',
|
||||
properties: {
|
||||
lr839d1xqs7: {
|
||||
_isJSONSchemaObject: true,
|
||||
version: '2.0',
|
||||
type: 'void',
|
||||
'x-component': 'FormV2',
|
||||
'x-use-component-props': 'useCreateFormBlockProps',
|
||||
'x-app-version': '1.3.25-beta',
|
||||
properties: {
|
||||
grid: {
|
||||
_isJSONSchemaObject: true,
|
||||
version: '2.0',
|
||||
type: 'void',
|
||||
'x-component': 'Grid',
|
||||
'x-initializer': 'form:configureFields',
|
||||
'x-app-version': '1.3.25-beta',
|
||||
properties: {
|
||||
'9mk2xu1lzbj': {
|
||||
_isJSONSchemaObject: true,
|
||||
version: '2.0',
|
||||
type: 'void',
|
||||
'x-component': 'Grid.Row',
|
||||
'x-app-version': '1.3.25-beta',
|
||||
properties: {
|
||||
'8bfxrqicaz4': {
|
||||
_isJSONSchemaObject: true,
|
||||
version: '2.0',
|
||||
type: 'void',
|
||||
'x-component': 'Grid.Col',
|
||||
'x-app-version': '1.3.25-beta',
|
||||
properties: {
|
||||
m2m: {
|
||||
'x-uid': 'iijs3xapp0r',
|
||||
_isJSONSchemaObject: true,
|
||||
version: '2.0',
|
||||
type: 'string',
|
||||
'x-toolbar': 'FormItemSchemaToolbar',
|
||||
'x-settings': 'fieldSettings:FormItem',
|
||||
'x-component': 'CollectionField',
|
||||
'x-decorator': 'FormItem',
|
||||
'x-collection-field':
|
||||
'testTableSelectedRecords.m2m',
|
||||
'x-component-props': {
|
||||
fieldNames: {
|
||||
label: 'id',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
'x-app-version': '1.3.25-beta',
|
||||
default: null,
|
||||
'x-async': false,
|
||||
'x-index': 1,
|
||||
},
|
||||
},
|
||||
'x-uid': '1v2n8jvdprt',
|
||||
'x-async': false,
|
||||
'x-index': 1,
|
||||
},
|
||||
},
|
||||
'x-uid': 'qpcykg8zxi4',
|
||||
'x-async': false,
|
||||
'x-index': 1,
|
||||
},
|
||||
},
|
||||
'x-uid': 'ovjbhso54ry',
|
||||
'x-async': false,
|
||||
'x-index': 1,
|
||||
},
|
||||
wjx5a7h79ln: {
|
||||
_isJSONSchemaObject: true,
|
||||
version: '2.0',
|
||||
type: 'void',
|
||||
'x-initializer': 'createForm:configureActions',
|
||||
'x-component': 'ActionBar',
|
||||
'x-component-props': {
|
||||
layout: 'one-column',
|
||||
},
|
||||
'x-app-version': '1.3.25-beta',
|
||||
'x-uid': '0bam1xybltd',
|
||||
'x-async': false,
|
||||
'x-index': 2,
|
||||
},
|
||||
},
|
||||
'x-uid': 'z9hll5knsnw',
|
||||
'x-async': false,
|
||||
'x-index': 1,
|
||||
},
|
||||
},
|
||||
'x-uid': 'h35uvzr6v1h',
|
||||
'x-async': false,
|
||||
'x-index': 1,
|
||||
},
|
||||
},
|
||||
'x-uid': 'ujw62wzvaza',
|
||||
'x-async': false,
|
||||
'x-index': 1,
|
||||
},
|
||||
},
|
||||
'x-uid': '5avddlitgwa',
|
||||
'x-async': false,
|
||||
'x-index': 1,
|
||||
},
|
||||
},
|
||||
'x-uid': 'ujmnybap6z8',
|
||||
'x-async': false,
|
||||
'x-index': 1,
|
||||
},
|
||||
},
|
||||
'x-uid': 'pen8qmp14dk',
|
||||
'x-async': false,
|
||||
'x-index': 1,
|
||||
},
|
||||
},
|
||||
'x-uid': '72c5i3pnqy1',
|
||||
'x-async': false,
|
||||
'x-index': 1,
|
||||
},
|
||||
},
|
||||
'x-uid': 'niditkbbb28',
|
||||
'x-async': false,
|
||||
'x-index': 1,
|
||||
},
|
||||
},
|
||||
'x-uid': 'ziy0tpkmr0q',
|
||||
'x-async': false,
|
||||
'x-index': 1,
|
||||
},
|
||||
},
|
||||
'x-uid': 'yigduqp0evh',
|
||||
'x-async': false,
|
||||
'x-index': 1,
|
||||
},
|
||||
'5ify9wgqk4q': {
|
||||
_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',
|
||||
},
|
||||
},
|
||||
'x-app-version': '1.3.25-beta',
|
||||
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-toolbar': 'TableColumnSchemaToolbar',
|
||||
'x-initializer': 'table:configureItemActions',
|
||||
'x-settings': 'fieldSettings:TableColumn',
|
||||
'x-toolbar-props': {
|
||||
initializer: 'table:configureItemActions',
|
||||
},
|
||||
'x-app-version': '1.3.25-beta',
|
||||
properties: {
|
||||
'4daepz6lwyh': {
|
||||
_isJSONSchemaObject: true,
|
||||
version: '2.0',
|
||||
type: 'void',
|
||||
'x-decorator': 'DndContext',
|
||||
'x-component': 'Space',
|
||||
'x-component-props': {
|
||||
split: '|',
|
||||
},
|
||||
'x-app-version': '1.3.25-beta',
|
||||
'x-uid': '348pidu78op',
|
||||
'x-async': false,
|
||||
'x-index': 1,
|
||||
},
|
||||
},
|
||||
'x-uid': 'nxv4u82cosx',
|
||||
'x-async': false,
|
||||
'x-index': 1,
|
||||
},
|
||||
'4pwwe3tqhip': {
|
||||
_isJSONSchemaObject: true,
|
||||
version: '2.0',
|
||||
type: 'void',
|
||||
'x-decorator': 'TableV2.Column.Decorator',
|
||||
'x-toolbar': 'TableColumnSchemaToolbar',
|
||||
'x-settings': 'fieldSettings:TableColumn',
|
||||
'x-component': 'TableV2.Column',
|
||||
'x-app-version': '1.3.25-beta',
|
||||
properties: {
|
||||
m2m: {
|
||||
_isJSONSchemaObject: true,
|
||||
version: '2.0',
|
||||
'x-collection-field': 'testTableSelectedRecords.m2m',
|
||||
'x-component': 'CollectionField',
|
||||
'x-component-props': {
|
||||
fieldNames: {
|
||||
value: 'id',
|
||||
label: 'id',
|
||||
},
|
||||
ellipsis: true,
|
||||
size: 'small',
|
||||
},
|
||||
'x-read-pretty': true,
|
||||
'x-decorator': null,
|
||||
'x-decorator-props': {
|
||||
labelStyle: {
|
||||
display: 'none',
|
||||
},
|
||||
},
|
||||
'x-app-version': '1.3.25-beta',
|
||||
'x-uid': 'n1t3oaopwi4',
|
||||
'x-async': false,
|
||||
'x-index': 1,
|
||||
},
|
||||
},
|
||||
'x-uid': 'pw0sv35l2ty',
|
||||
'x-async': false,
|
||||
'x-index': 2,
|
||||
},
|
||||
},
|
||||
'x-uid': '3sscxqoxcqx',
|
||||
'x-async': false,
|
||||
'x-index': 2,
|
||||
},
|
||||
},
|
||||
'x-uid': 'l25cpwxqdx7',
|
||||
'x-async': false,
|
||||
'x-index': 1,
|
||||
},
|
||||
},
|
||||
'x-uid': 'ftqzihfzwp4',
|
||||
'x-async': false,
|
||||
'x-index': 1,
|
||||
},
|
||||
},
|
||||
'x-uid': 'twnr4ap7vk6',
|
||||
'x-async': false,
|
||||
'x-index': 1,
|
||||
},
|
||||
},
|
||||
'x-uid': 'oohol9ikhrl',
|
||||
'x-async': false,
|
||||
'x-index': 1,
|
||||
},
|
||||
},
|
||||
'x-uid': '3e4ienzcipu',
|
||||
'x-async': true,
|
||||
'x-index': 1,
|
||||
},
|
||||
};
|
||||
|
@ -24,8 +24,6 @@ export const ActionContainer: ComposedActionDrawer = observer(
|
||||
|
||||
const Component = getComponentByOpenMode(openMode);
|
||||
|
||||
console.log('currentLevel', currentLevel);
|
||||
|
||||
return (
|
||||
<PopupLevelContext.Provider value={currentLevel}>
|
||||
<Component footerNodeName={'Action.Container.Footer'} level={currentLevel || 1} {...props} />
|
||||
|
@ -11,6 +11,7 @@ import { ISchema, useFieldSchema } from '@formily/react';
|
||||
import _ from 'lodash';
|
||||
import { useCallback, useContext } from 'react';
|
||||
import { useLocationNoUpdate, useNavigateNoUpdate } from '../../../application';
|
||||
import { useTableBlockContext } from '../../../block-provider/TableBlockProvider';
|
||||
import {
|
||||
CollectionRecord,
|
||||
useAssociationName,
|
||||
@ -48,6 +49,8 @@ export interface PopupContextStorage extends PopupContext {
|
||||
/** used to refresh data for block */
|
||||
service?: any;
|
||||
sourceId?: string;
|
||||
/** Specifically prepared for the 'Table selected records' variable */
|
||||
tableBlockContext?: { field: any; service: any; rowKey: any; collection: string };
|
||||
}
|
||||
|
||||
const popupsContextStorage: Record<string, PopupContextStorage> = {};
|
||||
@ -154,6 +157,7 @@ export const usePopupUtils = (
|
||||
(_parentRecordData || parentRecord?.data)?.[cm.getSourceKeyByAssociation(association)],
|
||||
[parentRecord, association],
|
||||
);
|
||||
const tableBlockContext = useTableBlockContext();
|
||||
|
||||
const setVisibleFromAction = options.setVisible || _setVisibleFromAction;
|
||||
|
||||
@ -245,6 +249,7 @@ export const usePopupUtils = (
|
||||
collection: collection.name,
|
||||
association,
|
||||
sourceId,
|
||||
tableBlockContext,
|
||||
});
|
||||
|
||||
updatePopupContext(getNewPopupContext(), customActionSchema);
|
||||
@ -266,6 +271,7 @@ export const usePopupUtils = (
|
||||
isPopupVisibleControlledByURL,
|
||||
getSourceId,
|
||||
getNewPopupContext,
|
||||
tableBlockContext,
|
||||
],
|
||||
);
|
||||
|
||||
|
@ -31,10 +31,10 @@ import {
|
||||
useCollection,
|
||||
useCollectionParentRecordData,
|
||||
useSchemaInitializerRender,
|
||||
useTableBlockContext,
|
||||
useTableSelectorContext,
|
||||
} from '../../../';
|
||||
import { useACLFieldWhitelist } from '../../../acl/ACLProvider';
|
||||
import { useTableBlockContext } from '../../../block-provider/TableBlockProvider';
|
||||
import { isNewRecord } from '../../../data-source/collection-record/isNewRecord';
|
||||
import { withDynamicSchemaProps } from '../../../hoc/withDynamicSchemaProps';
|
||||
import { useSatisfiedActionValues } from '../../../schema-settings/LinkageRules/useActionValues';
|
||||
|
@ -1,320 +0,0 @@
|
||||
/**
|
||||
* This file is part of the NocoBase (R) project.
|
||||
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
||||
* Authors: NocoBase Team.
|
||||
*
|
||||
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||
*/
|
||||
|
||||
import {
|
||||
BlockSchemaComponentPlugin,
|
||||
FixedBlock,
|
||||
TableBlockProvider,
|
||||
useTableBlockDecoratorProps,
|
||||
} from '@nocobase/client';
|
||||
import {
|
||||
CheckSettingsOptions,
|
||||
checkSchema,
|
||||
checkSettings,
|
||||
renderSettings,
|
||||
screen,
|
||||
userEvent,
|
||||
waitFor,
|
||||
} from '@nocobase/test/client';
|
||||
import { withSchema } from '@nocobase/test/web';
|
||||
|
||||
describe('Table.settings', () => {
|
||||
const TableBlockProviderWithSchema = withSchema(TableBlockProvider);
|
||||
|
||||
const checkTableSettings = (more: CheckSettingsOptions[] = []) => {
|
||||
return checkSettings(
|
||||
[
|
||||
{
|
||||
title: 'Edit block title',
|
||||
type: 'modal',
|
||||
},
|
||||
{
|
||||
title: 'Set block height',
|
||||
type: 'modal',
|
||||
},
|
||||
{
|
||||
title: 'Enable drag and drop sorting',
|
||||
type: 'switch',
|
||||
async afterFirstClick() {
|
||||
await checkSchema({
|
||||
'x-decorator-props': {
|
||||
dragSort: true,
|
||||
},
|
||||
});
|
||||
expect(screen.queryByText('Drag and drop sorting field')).toBeInTheDocument();
|
||||
|
||||
await checkSettings([
|
||||
{
|
||||
title: 'Drag and drop sorting field',
|
||||
type: 'select',
|
||||
options: [
|
||||
{
|
||||
label: 'sort',
|
||||
async checker() {
|
||||
await checkSchema({
|
||||
'x-decorator-props': {
|
||||
dragSortBy: 'sortName',
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
},
|
||||
async afterSecondClick() {
|
||||
await checkSchema({
|
||||
'x-decorator-props': {
|
||||
dragSort: false,
|
||||
},
|
||||
});
|
||||
expect(screen.queryByText('Drag and drop sorting field')).not.toBeInTheDocument();
|
||||
},
|
||||
},
|
||||
// {
|
||||
// title: 'Fix block',
|
||||
// type: 'switch',
|
||||
// async afterFirstClick() {
|
||||
// await checkSchema({
|
||||
// 'x-decorator-props': {
|
||||
// fixedBlock: true,
|
||||
// },
|
||||
// });
|
||||
// },
|
||||
// async afterSecondClick() {
|
||||
// await checkSchema({
|
||||
// 'x-decorator-props': {
|
||||
// fixedBlock: false,
|
||||
// },
|
||||
// });
|
||||
// },
|
||||
// },
|
||||
{
|
||||
title: 'Set the data scope',
|
||||
type: 'modal',
|
||||
modalChecker: {
|
||||
modalTitle: 'Set the data scope',
|
||||
async beforeCheck() {
|
||||
await userEvent.click(screen.getByText('Add condition'));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByTestId('select-filter-field')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
const field = screen.queryByTestId('select-filter-field').querySelector('input');
|
||||
|
||||
await userEvent.click(field);
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByTitle('ID')).toBeInTheDocument();
|
||||
});
|
||||
await userEvent.click(screen.getByTitle('ID'));
|
||||
|
||||
const value = document.querySelector('input[role=spinbutton]');
|
||||
await userEvent.type(value, '1');
|
||||
|
||||
await waitFor(() => {
|
||||
expect(document.querySelector('input[role=spinbutton]')).toHaveValue('1');
|
||||
});
|
||||
},
|
||||
async afterSubmit() {
|
||||
await checkSchema({
|
||||
'x-decorator-props': {
|
||||
params: {
|
||||
filter: {
|
||||
$and: [
|
||||
{
|
||||
id: {
|
||||
$eq: 1,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Set default sorting rules',
|
||||
type: 'modal',
|
||||
modalChecker: {
|
||||
modalTitle: 'Set default sorting rules',
|
||||
contentText: 'Add sort field',
|
||||
async beforeCheck() {
|
||||
await userEvent.click(screen.getByText('Add sort field'));
|
||||
const dialog = screen.getByRole('dialog');
|
||||
await waitFor(() => {
|
||||
expect(dialog.querySelector('.ant-select-selector')).toBeInTheDocument();
|
||||
});
|
||||
await userEvent.click(dialog.querySelector('.ant-select-selector'));
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByText('ID')).toBeInTheDocument();
|
||||
});
|
||||
await userEvent.click(screen.getByText('ID'));
|
||||
|
||||
await userEvent.click(screen.getByText('DESC'));
|
||||
},
|
||||
async afterSubmit() {
|
||||
await checkSchema({
|
||||
'x-decorator-props': {
|
||||
params: {
|
||||
sort: ['-id'],
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Set data loading mode',
|
||||
type: 'modal',
|
||||
modalChecker: {
|
||||
modalTitle: 'Data loading mode',
|
||||
async beforeCheck() {
|
||||
await userEvent.click(screen.getByText('Do not load data when filter is empty'));
|
||||
},
|
||||
async afterSubmit() {
|
||||
await checkSchema({
|
||||
'x-decorator-props': {
|
||||
dataLoadingMode: 'manual',
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Records per page',
|
||||
type: 'select',
|
||||
options: [
|
||||
{
|
||||
label: '10',
|
||||
async checker() {
|
||||
await checkSchema({
|
||||
'x-decorator-props': {
|
||||
params: {
|
||||
pageSize: 10,
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
label: '20',
|
||||
},
|
||||
{
|
||||
label: '50',
|
||||
},
|
||||
{
|
||||
label: '100',
|
||||
},
|
||||
{
|
||||
label: '100',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Save as template',
|
||||
type: 'modal',
|
||||
},
|
||||
{
|
||||
title: 'Delete',
|
||||
type: 'delete',
|
||||
},
|
||||
...more,
|
||||
],
|
||||
true,
|
||||
);
|
||||
};
|
||||
|
||||
const getRenderSettingsOptions = (isOld?: boolean, collection = 'users') => {
|
||||
const toolbarSchema = isOld
|
||||
? {
|
||||
'x-designer': 'TableBlockDesigner',
|
||||
}
|
||||
: {
|
||||
'x-toolbar': 'BlockSchemaToolbar',
|
||||
'x-settings': 'blockSettings:table',
|
||||
};
|
||||
|
||||
return {
|
||||
designable: true,
|
||||
enableUserListDataBlock: true,
|
||||
schema: {
|
||||
type: 'void',
|
||||
'x-component': 'FixedBlock',
|
||||
properties: {
|
||||
table: {
|
||||
type: 'void',
|
||||
'x-decorator': 'TableBlockProviderWithSchema',
|
||||
'x-use-decorator-props': 'useTableBlockDecoratorProps',
|
||||
'x-decorator-props': {
|
||||
collection: collection,
|
||||
dataSource: 'main',
|
||||
action: 'list',
|
||||
rowKey: 'id',
|
||||
showIndex: true,
|
||||
dragSort: false,
|
||||
params: {
|
||||
pageSize: 20,
|
||||
},
|
||||
},
|
||||
...toolbarSchema,
|
||||
'x-component': 'CardItem',
|
||||
'x-index': 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
appOptions: {
|
||||
components: {
|
||||
TableBlockProviderWithSchema,
|
||||
FixedBlock,
|
||||
},
|
||||
plugins: [BlockSchemaComponentPlugin],
|
||||
scopes: {
|
||||
useTableBlockDecoratorProps,
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
test('menu list', async () => {
|
||||
await renderSettings(getRenderSettingsOptions());
|
||||
await checkTableSettings();
|
||||
});
|
||||
|
||||
test('old schema', async () => {
|
||||
await renderSettings(getRenderSettingsOptions(true));
|
||||
await checkTableSettings();
|
||||
});
|
||||
|
||||
test('tree collection', async () => {
|
||||
await renderSettings(getRenderSettingsOptions(false, 'tree'));
|
||||
await checkSettings([
|
||||
{
|
||||
title: 'Tree table',
|
||||
type: 'switch',
|
||||
async afterFirstClick() {
|
||||
await checkSchema({
|
||||
'x-decorator-props': {
|
||||
treeTable: true,
|
||||
},
|
||||
});
|
||||
},
|
||||
async afterSecondClick() {
|
||||
await checkSchema({
|
||||
'x-decorator-props': {
|
||||
treeTable: false,
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
@ -7,13 +7,13 @@
|
||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||
*/
|
||||
|
||||
import { screen, renderAppOptions, userEvent, waitFor, renderReadPrettyApp } from '@nocobase/test/client';
|
||||
import { UnixTimestamp } from '@nocobase/client';
|
||||
import { renderAppOptions, renderReadPrettyApp, screen, userEvent, waitFor } from '@nocobase/test/client';
|
||||
|
||||
describe('UnixTimestamp', () => {
|
||||
it('renders without errors', async () => {
|
||||
const { container } = await renderAppOptions({
|
||||
Component: UnixTimestamp,
|
||||
Component: UnixTimestamp as any,
|
||||
props: {
|
||||
accuracy: 'millisecond',
|
||||
},
|
||||
@ -71,7 +71,7 @@ describe('UnixTimestamp', () => {
|
||||
|
||||
it('millisecond', async () => {
|
||||
await renderAppOptions({
|
||||
Component: UnixTimestamp,
|
||||
Component: UnixTimestamp as any,
|
||||
value: 1712819630000,
|
||||
props: {
|
||||
accuracy: 'millisecond',
|
||||
@ -84,7 +84,7 @@ describe('UnixTimestamp', () => {
|
||||
|
||||
it('second', async () => {
|
||||
await renderAppOptions({
|
||||
Component: UnixTimestamp,
|
||||
Component: UnixTimestamp as any,
|
||||
value: 1712819630,
|
||||
props: {
|
||||
accuracy: 'second',
|
||||
@ -98,7 +98,7 @@ describe('UnixTimestamp', () => {
|
||||
|
||||
it('string', async () => {
|
||||
await renderAppOptions({
|
||||
Component: UnixTimestamp,
|
||||
Component: UnixTimestamp as any,
|
||||
value: '2024-04-11',
|
||||
props: {
|
||||
accuracy: 'millisecond',
|
||||
@ -113,7 +113,7 @@ describe('UnixTimestamp', () => {
|
||||
it('change', async () => {
|
||||
const onChange = vitest.fn();
|
||||
await renderAppOptions({
|
||||
Component: UnixTimestamp,
|
||||
Component: UnixTimestamp as any,
|
||||
value: '2024-04-11',
|
||||
onChange,
|
||||
props: {
|
||||
@ -136,7 +136,7 @@ describe('UnixTimestamp', () => {
|
||||
|
||||
it('read pretty', async () => {
|
||||
const { container } = await renderReadPrettyApp({
|
||||
Component: UnixTimestamp,
|
||||
Component: UnixTimestamp as any,
|
||||
value: '2024-04-11',
|
||||
props: {
|
||||
accuracy: 'millisecond',
|
||||
|
@ -13,9 +13,10 @@ import { theme } from 'antd';
|
||||
import { debounce } from 'lodash';
|
||||
import { useCallback, useMemo, useRef, useState } from 'react';
|
||||
import { useDesignable } from '..';
|
||||
import { useDataBlockRequest, useCollection, useTableBlockContext } from '../../';
|
||||
import { useCollection, useDataBlockRequest } from '../../';
|
||||
import { getPageSchema, useBlockHeightProps } from '../../block-provider/hooks';
|
||||
import { useTableBlockContext } from '../../block-provider/TableBlockProvider';
|
||||
import { HeightMode } from '../../schema-settings/SchemaSettingsBlockHeightItem';
|
||||
import { useBlockHeightProps, getPageSchema } from '../../block-provider/hooks';
|
||||
|
||||
const getPageHeaderHeight = (disablePageHeader, enablePageTabs, hidePageTitle, token) => {
|
||||
if (disablePageHeader) {
|
||||
|
@ -22,8 +22,8 @@ import {
|
||||
useDesignable,
|
||||
useRecord,
|
||||
} from '..';
|
||||
import { useTableBlockContext } from '../block-provider';
|
||||
import { useFormBlockContext } from '../block-provider/FormBlockProvider';
|
||||
import { useTableBlockContext } from '../block-provider/TableBlockProvider';
|
||||
import { useCollectionFilterOptionsV2 } from '../collection-manager/action-hooks';
|
||||
import { FlagProvider, useFlag } from '../flag-provider';
|
||||
import { useLocalVariables, useVariables } from '../variables';
|
||||
@ -38,6 +38,11 @@ import { VariableInput, getShouldChange } from './VariableInput/VariableInput';
|
||||
import { Option } from './VariableInput/type';
|
||||
import { formatVariableScop } from './VariableInput/utils/formatVariableScop';
|
||||
|
||||
const getActionContext = (context: { fieldSchema?: Schema }) => {
|
||||
const actionCtx = (context.fieldSchema?.['x-action-context'] || {}) as { collection?: string; dataSource?: string };
|
||||
return actionCtx;
|
||||
};
|
||||
|
||||
export const SchemaSettingsDefaultValue = function DefaultValueConfigure(props: { fieldSchema?: Schema }) {
|
||||
const currentSchema = useFieldSchema();
|
||||
const fieldSchema = props?.fieldSchema ?? currentSchema;
|
||||
@ -45,6 +50,8 @@ export const SchemaSettingsDefaultValue = function DefaultValueConfigure(props:
|
||||
const { dn } = useDesignable();
|
||||
const { t } = useTranslation();
|
||||
const actionCtx = useActionContext();
|
||||
const actionCollection = getActionContext(actionCtx).collection;
|
||||
|
||||
let targetField;
|
||||
|
||||
const { getField } = useCollection_deprecated();
|
||||
@ -74,9 +81,8 @@ export const SchemaSettingsDefaultValue = function DefaultValueConfigure(props:
|
||||
const parentCollectionField = parentFieldSchema && getCollectionJoinField(parentFieldSchema?.['x-collection-field']);
|
||||
const tableCtx = useTableBlockContext();
|
||||
const isAllowContextVariable =
|
||||
actionCtx?.fieldSchema?.['x-action'] === 'customize:create' &&
|
||||
(collectionField?.interface === 'm2m' ||
|
||||
(parentCollectionField?.type === 'hasMany' && collectionField?.interface === 'm2o'));
|
||||
collectionField?.interface === 'm2m' ||
|
||||
(parentCollectionField?.type === 'hasMany' && collectionField?.interface === 'm2o');
|
||||
|
||||
const returnScope = useCallback(
|
||||
(scope: Option[]) => {
|
||||
@ -119,7 +125,7 @@ export const SchemaSettingsDefaultValue = function DefaultValueConfigure(props:
|
||||
'x-component-props': {
|
||||
...(fieldSchema?.['x-component-props'] || {}),
|
||||
collectionField,
|
||||
contextCollectionName: isAllowContextVariable && tableCtx.collection,
|
||||
contextCollectionName: isAllowContextVariable ? actionCollection : '',
|
||||
schema: collectionField?.uiSchema,
|
||||
targetFieldSchema: fieldSchema,
|
||||
className: defaultInputStyle,
|
||||
|
@ -8,11 +8,27 @@
|
||||
*/
|
||||
|
||||
import { useMemo } from 'react';
|
||||
import { useTableBlockContext } from '../../block-provider';
|
||||
import { useTableBlockContext } from '../../block-provider/TableBlockProvider';
|
||||
import { useCurrentPopupContext } from '../../schema-component/antd/page/PagePopups';
|
||||
import { getStoredPopupContext } from '../../schema-component/antd/page/pagePopupUtils';
|
||||
import { usePopupSettings } from '../../schema-component/antd/page/PopupSettingsProvider';
|
||||
import { VariableOption } from '../types';
|
||||
|
||||
const useContextVariable = (): VariableOption => {
|
||||
const { field, service, rowKey, collection: collectionName } = useTableBlockContext();
|
||||
let tableBlockContext;
|
||||
|
||||
const { isPopupVisibleControlledByURL } = usePopupSettings();
|
||||
const { params } = useCurrentPopupContext();
|
||||
const _tableBlockContext = useTableBlockContext();
|
||||
|
||||
if (isPopupVisibleControlledByURL()) {
|
||||
tableBlockContext = getStoredPopupContext(params?.popupuid)?.tableBlockContext;
|
||||
} else {
|
||||
tableBlockContext = _tableBlockContext;
|
||||
}
|
||||
|
||||
const { field, service, rowKey, collection: collectionName } = tableBlockContext || {};
|
||||
|
||||
const contextData = useMemo(
|
||||
() => service?.data?.data?.filter((v) => (field?.data?.selectedRowKeys || [])?.includes(v[rowKey])),
|
||||
[field?.data?.selectedRowKeys, rowKey, service?.data?.data],
|
||||
|
Loading…
Reference in New Issue
Block a user