fix: fix multi-select field not show 'Allow multiple' switch (#1857)
* fix: fix multi-select field not show 'Allow multiple' switch * fix: use uiSchema
This commit is contained in:
parent
d2e92ead7f
commit
19a33dfe74
@ -15,6 +15,7 @@ import {
|
|||||||
} from '../../../collection-manager';
|
} from '../../../collection-manager';
|
||||||
import { isTitleField } from '../../../collection-manager/Configuration/CollectionFields';
|
import { isTitleField } from '../../../collection-manager/Configuration/CollectionFields';
|
||||||
import { GeneralSchemaDesigner, SchemaSettings, isPatternDisabled, isShowDefaultValue } from '../../../schema-settings';
|
import { GeneralSchemaDesigner, SchemaSettings, isPatternDisabled, isShowDefaultValue } from '../../../schema-settings';
|
||||||
|
import { useIsShowMultipleSwitch } from '../../../schema-settings/hooks/useIsShowMultipleSwitch';
|
||||||
import { useCompile, useDesignable, useFieldComponentOptions, useFieldTitle } from '../../hooks';
|
import { useCompile, useDesignable, useFieldComponentOptions, useFieldTitle } from '../../hooks';
|
||||||
import { removeNullCondition } from '../filter';
|
import { removeNullCondition } from '../filter';
|
||||||
import { RemoteSelect, RemoteSelectProps } from '../remote-select';
|
import { RemoteSelect, RemoteSelectProps } from '../remote-select';
|
||||||
@ -102,6 +103,8 @@ AssociationSelect.Designer = function Designer() {
|
|||||||
const tk = useFilterByTk();
|
const tk = useFilterByTk();
|
||||||
const { dn, refresh, insertAdjacent } = useDesignable();
|
const { dn, refresh, insertAdjacent } = useDesignable();
|
||||||
const compile = useCompile();
|
const compile = useCompile();
|
||||||
|
const IsShowMultipleSwitch = useIsShowMultipleSwitch();
|
||||||
|
|
||||||
const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
|
const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
|
||||||
const fieldComponentOptions = useFieldComponentOptions();
|
const fieldComponentOptions = useFieldComponentOptions();
|
||||||
const isSubFormAssociationField = field.address.segments.includes('__form_grid');
|
const isSubFormAssociationField = field.address.segments.includes('__form_grid');
|
||||||
@ -495,17 +498,12 @@ AssociationSelect.Designer = function Designer() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{form &&
|
{IsShowMultipleSwitch() ? (
|
||||||
!form?.readPretty &&
|
|
||||||
['o2m', 'm2m'].includes(collectionField.interface) &&
|
|
||||||
fieldSchema['x-component'] !== 'TableField' && (
|
|
||||||
<SchemaSettings.SwitchItem
|
<SchemaSettings.SwitchItem
|
||||||
key="multiple"
|
key="multiple"
|
||||||
title={t('Allow multiple')}
|
title={t('Allow multiple')}
|
||||||
checked={
|
checked={
|
||||||
fieldSchema['x-component-props']?.multiple === undefined
|
fieldSchema['x-component-props']?.multiple === undefined ? true : fieldSchema['x-component-props'].multiple
|
||||||
? true
|
|
||||||
: fieldSchema['x-component-props'].multiple
|
|
||||||
}
|
}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
const schema = {
|
const schema = {
|
||||||
@ -524,7 +522,7 @@ AssociationSelect.Designer = function Designer() {
|
|||||||
refresh();
|
refresh();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
) : null}
|
||||||
<SchemaSettings.ModalItem
|
<SchemaSettings.ModalItem
|
||||||
title={t('Set the data scope')}
|
title={t('Set the data scope')}
|
||||||
schema={
|
schema={
|
||||||
|
@ -8,7 +8,7 @@ import moment from 'moment';
|
|||||||
import React, { useContext, useEffect } from 'react';
|
import React, { useContext, useEffect } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { ACLCollectionFieldProvider } from '../../../acl/ACLProvider';
|
import { ACLCollectionFieldProvider } from '../../../acl/ACLProvider';
|
||||||
import { BlockRequestContext, useFilterByTk, useFormBlockContext } from '../../../block-provider';
|
import { BlockRequestContext, useFormBlockContext } from '../../../block-provider';
|
||||||
import {
|
import {
|
||||||
Collection,
|
Collection,
|
||||||
CollectionFieldOptions,
|
CollectionFieldOptions,
|
||||||
@ -20,6 +20,7 @@ import {
|
|||||||
import { isTitleField } from '../../../collection-manager/Configuration/CollectionFields';
|
import { isTitleField } from '../../../collection-manager/Configuration/CollectionFields';
|
||||||
import { GeneralSchemaDesigner, SchemaSettings, isPatternDisabled, isShowDefaultValue } from '../../../schema-settings';
|
import { GeneralSchemaDesigner, SchemaSettings, isPatternDisabled, isShowDefaultValue } from '../../../schema-settings';
|
||||||
import { VariableInput } from '../../../schema-settings/VariableInput/VariableInput';
|
import { VariableInput } from '../../../schema-settings/VariableInput/VariableInput';
|
||||||
|
import { useIsShowMultipleSwitch } from '../../../schema-settings/hooks/useIsShowMultipleSwitch';
|
||||||
import { isVariable, parseVariables, useVariablesCtx } from '../../common/utils/uitls';
|
import { isVariable, parseVariables, useVariablesCtx } from '../../common/utils/uitls';
|
||||||
import { SchemaComponent } from '../../core';
|
import { SchemaComponent } from '../../core';
|
||||||
import { useCompile, useDesignable, useFieldModeOptions } from '../../hooks';
|
import { useCompile, useDesignable, useFieldModeOptions } from '../../hooks';
|
||||||
@ -99,14 +100,15 @@ export const FormItem: any = observer((props: any) => {
|
|||||||
FormItem.Designer = function Designer() {
|
FormItem.Designer = function Designer() {
|
||||||
const { getCollectionFields, getInterface, getCollectionJoinField, getCollection } = useCollectionManager();
|
const { getCollectionFields, getInterface, getCollectionJoinField, getCollection } = useCollectionManager();
|
||||||
const { getField } = useCollection();
|
const { getField } = useCollection();
|
||||||
const tk = useFilterByTk();
|
|
||||||
const { form } = useFormBlockContext();
|
const { form } = useFormBlockContext();
|
||||||
const field = useField<Field>();
|
const field = useField<Field>();
|
||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { dn, refresh, insertAdjacent } = useDesignable();
|
const { dn, refresh } = useDesignable();
|
||||||
const compile = useCompile();
|
const compile = useCompile();
|
||||||
const variablesCtx = useVariablesCtx();
|
const variablesCtx = useVariablesCtx();
|
||||||
|
const IsShowMultipleSwitch = useIsShowMultipleSwitch();
|
||||||
|
|
||||||
const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
|
const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
|
||||||
const targetCollection = getCollection(collectionField?.target);
|
const targetCollection = getCollection(collectionField?.target);
|
||||||
const interfaceConfig = getInterface(collectionField?.interface);
|
const interfaceConfig = getInterface(collectionField?.interface);
|
||||||
@ -705,17 +707,12 @@ FormItem.Designer = function Designer() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{form &&
|
{IsShowMultipleSwitch() ? (
|
||||||
!form?.readPretty &&
|
|
||||||
['o2m', 'm2m'].includes(collectionField?.interface) &&
|
|
||||||
fieldSchema['x-component'] !== 'TableField' && (
|
|
||||||
<SchemaSettings.SwitchItem
|
<SchemaSettings.SwitchItem
|
||||||
key="multiple"
|
key="multiple"
|
||||||
title={t('Allow multiple')}
|
title={t('Allow multiple')}
|
||||||
checked={
|
checked={
|
||||||
fieldSchema['x-component-props']?.multiple === undefined
|
fieldSchema['x-component-props']?.multiple === undefined ? true : fieldSchema['x-component-props'].multiple
|
||||||
? true
|
|
||||||
: fieldSchema['x-component-props'].multiple
|
|
||||||
}
|
}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
const schema = {
|
const schema = {
|
||||||
@ -734,7 +731,7 @@ FormItem.Designer = function Designer() {
|
|||||||
refresh();
|
refresh();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
) : null}
|
||||||
{field.readPretty && options.length > 0 && fieldSchema['x-component'] === 'CollectionField' && !isFileField && (
|
{field.readPretty && options.length > 0 && fieldSchema['x-component'] === 'CollectionField' && !isFileField && (
|
||||||
<SchemaSettings.SwitchItem
|
<SchemaSettings.SwitchItem
|
||||||
title={t('Enable link')}
|
title={t('Enable link')}
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
import { useField, useFieldSchema } from '@formily/react';
|
||||||
|
import { useCollectionManager } from '../../collection-manager';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否显示 `允许多选` 开关
|
||||||
|
*/
|
||||||
|
export function useIsShowMultipleSwitch() {
|
||||||
|
const field = useField();
|
||||||
|
const fieldSchema = useFieldSchema();
|
||||||
|
const { getCollectionField } = useCollectionManager();
|
||||||
|
|
||||||
|
const collectionField = getCollectionField(fieldSchema['x-collection-field']);
|
||||||
|
const uiSchema = collectionField?.uiSchema || fieldSchema;
|
||||||
|
const hasMultiple = uiSchema['x-component-props']?.multiple === true;
|
||||||
|
|
||||||
|
return function IsShowMultipleSwitch() {
|
||||||
|
return !field.readPretty && fieldSchema['x-component'] !== 'TableField' && hasMultiple;
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user