mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 11:12:20 +08:00
fix: missing multiple selection option for to-many association fields in sub-table (#4742)
This commit is contained in:
parent
dac110931b
commit
bff6dde483
@ -0,0 +1,61 @@
|
|||||||
|
/**
|
||||||
|
* 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 { expectSettingsMenu, test } from '@nocobase/test/e2e';
|
||||||
|
import { oneFormWithSubTableSelectField } from './templatesOfBug';
|
||||||
|
|
||||||
|
//子表格中的对多关系字段
|
||||||
|
test('supports options', async ({ page, mockPage }) => {
|
||||||
|
await mockPage(oneFormWithSubTableSelectField).goto();
|
||||||
|
// 在子表格中
|
||||||
|
await expectSettingsMenu({
|
||||||
|
page,
|
||||||
|
showMenu: async () => {
|
||||||
|
await page.getByRole('button', { name: 'o2m(test3)' }).click();
|
||||||
|
await page.getByLabel('designer-schema-settings-TableV2.Column-fieldSettings:TableColumn-test2').click();
|
||||||
|
},
|
||||||
|
supportedOptions: [
|
||||||
|
'Custom column title',
|
||||||
|
'Column width',
|
||||||
|
'Set default value',
|
||||||
|
'Required',
|
||||||
|
'Fixed',
|
||||||
|
'Field component',
|
||||||
|
'Set the data scope',
|
||||||
|
'Set default sorting rules',
|
||||||
|
'Allow multiple',
|
||||||
|
'Title field',
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
// 在表单中
|
||||||
|
await expectSettingsMenu({
|
||||||
|
page,
|
||||||
|
showMenu: async () => {
|
||||||
|
await page.getByLabel('block-item-CollectionField-').hover();
|
||||||
|
await page.getByLabel('designer-schema-settings-CollectionField-fieldSettings:FormItem-test1-test1.o2m').hover();
|
||||||
|
await page.getByText('Field componentSub-table').click();
|
||||||
|
await page.getByRole('option', { name: 'Select' }).click();
|
||||||
|
},
|
||||||
|
supportedOptions: [
|
||||||
|
'Edit field title',
|
||||||
|
'Display title',
|
||||||
|
'Edit description',
|
||||||
|
'Edit tooltip',
|
||||||
|
'Required',
|
||||||
|
'Pattern',
|
||||||
|
'Field component',
|
||||||
|
'Set the data scope',
|
||||||
|
'Set default sorting rules',
|
||||||
|
'Quick create',
|
||||||
|
'Allow multiple',
|
||||||
|
'Title field',
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
@ -163,3 +163,421 @@ export const T3867 = {
|
|||||||
'x-index': 1,
|
'x-index': 1,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const oneFormWithSubTableSelectField = {
|
||||||
|
pageSchema: {
|
||||||
|
_isJSONSchemaObject: true,
|
||||||
|
version: '2.0',
|
||||||
|
type: 'void',
|
||||||
|
'x-component': 'Page',
|
||||||
|
'x-app-version': '1.2.7-alpha',
|
||||||
|
properties: {
|
||||||
|
iza2br2wzq4: {
|
||||||
|
_isJSONSchemaObject: true,
|
||||||
|
version: '2.0',
|
||||||
|
type: 'void',
|
||||||
|
'x-component': 'Grid',
|
||||||
|
'x-initializer': 'page:addBlock',
|
||||||
|
'x-app-version': '1.2.7-alpha',
|
||||||
|
properties: {
|
||||||
|
hq9u92krwno: {
|
||||||
|
_isJSONSchemaObject: true,
|
||||||
|
version: '2.0',
|
||||||
|
type: 'void',
|
||||||
|
'x-component': 'Grid.Row',
|
||||||
|
'x-app-version': '1.2.7-alpha',
|
||||||
|
properties: {
|
||||||
|
'0xl94yvrqjq': {
|
||||||
|
_isJSONSchemaObject: true,
|
||||||
|
version: '2.0',
|
||||||
|
type: 'void',
|
||||||
|
'x-component': 'Grid.Col',
|
||||||
|
'x-app-version': '1.2.7-alpha',
|
||||||
|
properties: {
|
||||||
|
h8cs7cjc0y5: {
|
||||||
|
_isJSONSchemaObject: true,
|
||||||
|
version: '2.0',
|
||||||
|
type: 'void',
|
||||||
|
'x-acl-action-props': {
|
||||||
|
skipScopeCheck: true,
|
||||||
|
},
|
||||||
|
'x-acl-action': 'test1:create',
|
||||||
|
'x-decorator': 'FormBlockProvider',
|
||||||
|
'x-use-decorator-props': 'useCreateFormBlockDecoratorProps',
|
||||||
|
'x-decorator-props': {
|
||||||
|
dataSource: 'main',
|
||||||
|
collection: 'test1',
|
||||||
|
},
|
||||||
|
'x-toolbar': 'BlockSchemaToolbar',
|
||||||
|
'x-settings': 'blockSettings:createForm',
|
||||||
|
'x-component': 'CardItem',
|
||||||
|
'x-app-version': '1.2.7-alpha',
|
||||||
|
properties: {
|
||||||
|
'6acyz9zsvf9': {
|
||||||
|
_isJSONSchemaObject: true,
|
||||||
|
version: '2.0',
|
||||||
|
type: 'void',
|
||||||
|
'x-component': 'FormV2',
|
||||||
|
'x-use-component-props': 'useCreateFormBlockProps',
|
||||||
|
'x-app-version': '1.2.7-alpha',
|
||||||
|
properties: {
|
||||||
|
grid: {
|
||||||
|
_isJSONSchemaObject: true,
|
||||||
|
version: '2.0',
|
||||||
|
type: 'void',
|
||||||
|
'x-component': 'Grid',
|
||||||
|
'x-initializer': 'form:configureFields',
|
||||||
|
'x-app-version': '1.2.7-alpha',
|
||||||
|
properties: {
|
||||||
|
uc6hcqm7i1p: {
|
||||||
|
_isJSONSchemaObject: true,
|
||||||
|
version: '2.0',
|
||||||
|
type: 'void',
|
||||||
|
'x-component': 'Grid.Row',
|
||||||
|
'x-app-version': '1.2.7-alpha',
|
||||||
|
properties: {
|
||||||
|
ay7buet4shb: {
|
||||||
|
_isJSONSchemaObject: true,
|
||||||
|
version: '2.0',
|
||||||
|
type: 'void',
|
||||||
|
'x-component': 'Grid.Col',
|
||||||
|
'x-app-version': '1.2.7-alpha',
|
||||||
|
properties: {
|
||||||
|
o2m: {
|
||||||
|
'x-uid': 'fuq57lhf9sw',
|
||||||
|
_isJSONSchemaObject: true,
|
||||||
|
version: '2.0',
|
||||||
|
type: 'string',
|
||||||
|
'x-toolbar': 'FormItemSchemaToolbar',
|
||||||
|
'x-settings': 'fieldSettings:FormItem',
|
||||||
|
'x-component': 'CollectionField',
|
||||||
|
'x-decorator': 'FormItem',
|
||||||
|
'x-collection-field': 'test1.o2m',
|
||||||
|
'x-component-props': {
|
||||||
|
fieldNames: {
|
||||||
|
value: 'id',
|
||||||
|
label: 'id',
|
||||||
|
},
|
||||||
|
mode: 'SubTable',
|
||||||
|
},
|
||||||
|
'x-app-version': '1.2.7-alpha',
|
||||||
|
default: null,
|
||||||
|
properties: {
|
||||||
|
lp61waqr2kn: {
|
||||||
|
_isJSONSchemaObject: true,
|
||||||
|
version: '2.0',
|
||||||
|
type: 'void',
|
||||||
|
'x-component': 'AssociationField.SubTable',
|
||||||
|
'x-initializer': 'table:configureColumns',
|
||||||
|
'x-initializer-props': {
|
||||||
|
action: false,
|
||||||
|
},
|
||||||
|
'x-index': 1,
|
||||||
|
'x-app-version': '1.2.7-alpha',
|
||||||
|
properties: {
|
||||||
|
d0eyyy1lzkr: {
|
||||||
|
_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.2.7-alpha',
|
||||||
|
properties: {
|
||||||
|
o2m: {
|
||||||
|
_isJSONSchemaObject: true,
|
||||||
|
version: '2.0',
|
||||||
|
'x-collection-field': 'test2.o2m',
|
||||||
|
'x-component': 'CollectionField',
|
||||||
|
'x-component-props': {
|
||||||
|
fieldNames: {
|
||||||
|
value: 'id',
|
||||||
|
label: 'id',
|
||||||
|
},
|
||||||
|
ellipsis: true,
|
||||||
|
size: 'small',
|
||||||
|
},
|
||||||
|
'x-decorator': 'FormItem',
|
||||||
|
'x-decorator-props': {
|
||||||
|
labelStyle: {
|
||||||
|
display: 'none',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'x-app-version': '1.2.7-alpha',
|
||||||
|
'x-uid': '101fr7c218n',
|
||||||
|
'x-async': false,
|
||||||
|
'x-index': 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'x-uid': 'enhm21ca4bc',
|
||||||
|
'x-async': false,
|
||||||
|
'x-index': 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'x-uid': 'li6u5na3ath',
|
||||||
|
'x-async': false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'x-async': false,
|
||||||
|
'x-index': 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'x-uid': 'w5wa4lqrxnh',
|
||||||
|
'x-async': false,
|
||||||
|
'x-index': 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'x-uid': 'fcan7iyk7y4',
|
||||||
|
'x-async': false,
|
||||||
|
'x-index': 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'x-uid': 'ragpzxlvl3l',
|
||||||
|
'x-async': false,
|
||||||
|
'x-index': 1,
|
||||||
|
},
|
||||||
|
becbhdzvfd4: {
|
||||||
|
_isJSONSchemaObject: true,
|
||||||
|
version: '2.0',
|
||||||
|
type: 'void',
|
||||||
|
'x-initializer': 'createForm:configureActions',
|
||||||
|
'x-component': 'ActionBar',
|
||||||
|
'x-component-props': {
|
||||||
|
layout: 'one-column',
|
||||||
|
style: {
|
||||||
|
marginTop: 'var(--nb-spacing)',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'x-app-version': '1.2.7-alpha',
|
||||||
|
'x-uid': 'kgrvq35c5v1',
|
||||||
|
'x-async': false,
|
||||||
|
'x-index': 2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'x-uid': 'mr5v4ycueol',
|
||||||
|
'x-async': false,
|
||||||
|
'x-index': 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'x-uid': 'gwsv7nvdiam',
|
||||||
|
'x-async': false,
|
||||||
|
'x-index': 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'x-uid': 'n71wq1k8491',
|
||||||
|
'x-async': false,
|
||||||
|
'x-index': 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'x-uid': 'ymnl0yjrviv',
|
||||||
|
'x-async': false,
|
||||||
|
'x-index': 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'x-uid': 'usfanrw7m95',
|
||||||
|
'x-async': false,
|
||||||
|
'x-index': 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'x-uid': 'hizrr7jzogr',
|
||||||
|
'x-async': true,
|
||||||
|
'x-index': 1,
|
||||||
|
},
|
||||||
|
collections: [
|
||||||
|
{
|
||||||
|
name: 'test1',
|
||||||
|
title: 'test1',
|
||||||
|
inherit: false,
|
||||||
|
hidden: false,
|
||||||
|
description: null,
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: 'id',
|
||||||
|
type: 'bigInt',
|
||||||
|
interface: 'integer',
|
||||||
|
description: null,
|
||||||
|
collectionName: 'test1',
|
||||||
|
parentKey: null,
|
||||||
|
reverseKey: null,
|
||||||
|
autoIncrement: true,
|
||||||
|
primaryKey: true,
|
||||||
|
allowNull: false,
|
||||||
|
uiSchema: {
|
||||||
|
type: 'number',
|
||||||
|
title: '{{t("ID")}}',
|
||||||
|
'x-component': 'InputNumber',
|
||||||
|
'x-read-pretty': true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: '6vyl22ibdj1',
|
||||||
|
name: 'o2m',
|
||||||
|
type: 'hasMany',
|
||||||
|
interface: 'o2m',
|
||||||
|
description: null,
|
||||||
|
collectionName: 'test1',
|
||||||
|
parentKey: null,
|
||||||
|
reverseKey: null,
|
||||||
|
sourceKey: 'id',
|
||||||
|
foreignKey: 'f_ul4q5koxzgd',
|
||||||
|
onDelete: 'SET NULL',
|
||||||
|
uiSchema: {
|
||||||
|
'x-component': 'AssociationField',
|
||||||
|
'x-component-props': {
|
||||||
|
multiple: true,
|
||||||
|
},
|
||||||
|
title: 'o2m(test2)',
|
||||||
|
},
|
||||||
|
target: 'test2',
|
||||||
|
targetKey: 'id',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
category: [],
|
||||||
|
logging: true,
|
||||||
|
autoGenId: true,
|
||||||
|
createdAt: false,
|
||||||
|
createdBy: false,
|
||||||
|
updatedAt: false,
|
||||||
|
updatedBy: false,
|
||||||
|
template: 'general',
|
||||||
|
view: false,
|
||||||
|
schema: 'public',
|
||||||
|
filterTargetKey: 'id',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'test2',
|
||||||
|
title: 'test2',
|
||||||
|
inherit: false,
|
||||||
|
hidden: false,
|
||||||
|
description: null,
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: 'id',
|
||||||
|
type: 'bigInt',
|
||||||
|
interface: 'integer',
|
||||||
|
description: null,
|
||||||
|
collectionName: 'test2',
|
||||||
|
parentKey: null,
|
||||||
|
reverseKey: null,
|
||||||
|
autoIncrement: true,
|
||||||
|
primaryKey: true,
|
||||||
|
allowNull: false,
|
||||||
|
uiSchema: {
|
||||||
|
type: 'number',
|
||||||
|
title: '{{t("ID")}}',
|
||||||
|
'x-component': 'InputNumber',
|
||||||
|
'x-read-pretty': true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'kawadu893z7',
|
||||||
|
name: 'f_ul4q5koxzgd',
|
||||||
|
type: 'bigInt',
|
||||||
|
interface: 'integer',
|
||||||
|
description: null,
|
||||||
|
collectionName: 'test2',
|
||||||
|
parentKey: null,
|
||||||
|
reverseKey: null,
|
||||||
|
isForeignKey: true,
|
||||||
|
uiSchema: {
|
||||||
|
type: 'number',
|
||||||
|
title: 'f_ul4q5koxzgd',
|
||||||
|
'x-component': 'InputNumber',
|
||||||
|
'x-read-pretty': true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: '68i40oyixck',
|
||||||
|
name: 'o2m',
|
||||||
|
type: 'hasMany',
|
||||||
|
interface: 'o2m',
|
||||||
|
description: null,
|
||||||
|
collectionName: 'test2',
|
||||||
|
parentKey: null,
|
||||||
|
reverseKey: null,
|
||||||
|
sourceKey: 'id',
|
||||||
|
foreignKey: 'f_pbe3bj214df',
|
||||||
|
onDelete: 'SET NULL',
|
||||||
|
uiSchema: {
|
||||||
|
'x-component': 'AssociationField',
|
||||||
|
'x-component-props': {
|
||||||
|
multiple: true,
|
||||||
|
},
|
||||||
|
title: 'o2m(test3)',
|
||||||
|
},
|
||||||
|
target: 'test3',
|
||||||
|
targetKey: 'id',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
category: [],
|
||||||
|
logging: true,
|
||||||
|
autoGenId: true,
|
||||||
|
createdAt: false,
|
||||||
|
createdBy: false,
|
||||||
|
updatedAt: false,
|
||||||
|
updatedBy: false,
|
||||||
|
template: 'general',
|
||||||
|
view: false,
|
||||||
|
schema: 'public',
|
||||||
|
filterTargetKey: 'id',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'o0nnfuhi5ur',
|
||||||
|
name: 'test3',
|
||||||
|
title: 'test3',
|
||||||
|
inherit: false,
|
||||||
|
hidden: false,
|
||||||
|
description: null,
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
key: 'q75s3xv1jf2',
|
||||||
|
name: 'id',
|
||||||
|
type: 'bigInt',
|
||||||
|
interface: 'integer',
|
||||||
|
description: null,
|
||||||
|
collectionName: 'test3',
|
||||||
|
parentKey: null,
|
||||||
|
reverseKey: null,
|
||||||
|
autoIncrement: true,
|
||||||
|
primaryKey: true,
|
||||||
|
allowNull: false,
|
||||||
|
uiSchema: {
|
||||||
|
type: 'number',
|
||||||
|
title: '{{t("ID")}}',
|
||||||
|
'x-component': 'InputNumber',
|
||||||
|
'x-read-pretty': true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'ggm4fgwukh1',
|
||||||
|
name: 'f_pbe3bj214df',
|
||||||
|
type: 'bigInt',
|
||||||
|
interface: 'integer',
|
||||||
|
description: null,
|
||||||
|
collectionName: 'test3',
|
||||||
|
parentKey: null,
|
||||||
|
reverseKey: null,
|
||||||
|
isForeignKey: true,
|
||||||
|
uiSchema: {
|
||||||
|
type: 'number',
|
||||||
|
title: 'f_pbe3bj214df',
|
||||||
|
'x-component': 'InputNumber',
|
||||||
|
'x-read-pretty': true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
category: [],
|
||||||
|
logging: true,
|
||||||
|
autoGenId: true,
|
||||||
|
createdAt: false,
|
||||||
|
createdBy: false,
|
||||||
|
updatedAt: false,
|
||||||
|
updatedBy: false,
|
||||||
|
template: 'general',
|
||||||
|
view: false,
|
||||||
|
schema: 'public',
|
||||||
|
filterTargetKey: 'id',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
@ -184,7 +184,7 @@ const quickCreate: any = {
|
|||||||
}, null);
|
}, null);
|
||||||
|
|
||||||
if (!hasAddNew) {
|
if (!hasAddNew) {
|
||||||
const addNewActionschema = {
|
const addNewActionSchema = {
|
||||||
'x-action': 'create',
|
'x-action': 'create',
|
||||||
'x-acl-action': 'create',
|
'x-acl-action': 'create',
|
||||||
title: "{{t('Add new')}}",
|
title: "{{t('Add new')}}",
|
||||||
@ -199,7 +199,7 @@ const quickCreate: any = {
|
|||||||
component: 'CreateRecordAction',
|
component: 'CreateRecordAction',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
insertAdjacent('afterBegin', addNewActionschema);
|
insertAdjacent('afterBegin', addNewActionSchema);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const schema = {
|
const schema = {
|
||||||
@ -364,6 +364,7 @@ export const selectComponentFieldSettings = new SchemaSettings({
|
|||||||
useVisible() {
|
useVisible() {
|
||||||
const isAssociationField = useIsAssociationField();
|
const isAssociationField = useIsAssociationField();
|
||||||
const IsShowMultipleSwitch = useIsShowMultipleSwitch();
|
const IsShowMultipleSwitch = useIsShowMultipleSwitch();
|
||||||
|
console.log(isAssociationField, IsShowMultipleSwitch());
|
||||||
return isAssociationField && IsShowMultipleSwitch();
|
return isAssociationField && IsShowMultipleSwitch();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -16,9 +16,10 @@ import { useColumnSchema } from '../../schema-component/antd/table-v2/Table.Colu
|
|||||||
*/
|
*/
|
||||||
export function useIsShowMultipleSwitch() {
|
export function useIsShowMultipleSwitch() {
|
||||||
const field = useField();
|
const field = useField();
|
||||||
const fieldSchema = useFieldSchema();
|
|
||||||
const { getCollectionField } = useCollectionManager_deprecated();
|
const { getCollectionField } = useCollectionManager_deprecated();
|
||||||
|
const { fieldSchema: tableColumnSchema } = useColumnSchema();
|
||||||
|
const schema = useFieldSchema();
|
||||||
|
const fieldSchema = tableColumnSchema || schema;
|
||||||
const collectionField = fieldSchema['x-collection-field']
|
const collectionField = fieldSchema['x-collection-field']
|
||||||
? getCollectionField(fieldSchema['x-collection-field'])
|
? getCollectionField(fieldSchema['x-collection-field'])
|
||||||
: null;
|
: null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user