fix(variable): make all fields of currentForm and currentObject variable optional (#2878)

This commit is contained in:
被雨水过滤的空气-Rain 2023-10-20 14:16:29 +08:00 committed by GitHub
parent d85aa423d0
commit f5f74382f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 16 deletions

View File

@ -1,6 +1,5 @@
import { Schema } from '@formily/json-schema'; import { Schema } from '@formily/json-schema';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useFormActiveFields } from '../../../block-provider';
import { CollectionFieldOptions } from '../../../collection-manager'; import { CollectionFieldOptions } from '../../../collection-manager';
import { useBaseVariable } from './useBaseVariable'; import { useBaseVariable } from './useBaseVariable';
@ -19,7 +18,7 @@ interface Props {
* @returns * @returns
*/ */
export const useFormVariable = ({ collectionName, collectionField, schema, noDisabled, targetFieldSchema }: Props) => { export const useFormVariable = ({ collectionName, collectionField, schema, noDisabled, targetFieldSchema }: Props) => {
const { getActiveFieldsName } = useFormActiveFields() || {}; // const { getActiveFieldsName } = useFormActiveFields() || {};
const { t } = useTranslation(); const { t } = useTranslation();
const result = useBaseVariable({ const result = useBaseVariable({
collectionField, collectionField,
@ -31,13 +30,15 @@ export const useFormVariable = ({ collectionName, collectionField, schema, noDis
collectionName: collectionName, collectionName: collectionName,
noDisabled, noDisabled,
returnFields: (fields, option) => { returnFields: (fields, option) => {
const activeFieldsName = getActiveFieldsName?.('form') || []; // fix https://nocobase.height.app/T-2277
return fields;
// const activeFieldsName = getActiveFieldsName?.('form') || [];
return option.depth === 0 // return option.depth === 0
? fields.filter((field) => { // ? fields.filter((field) => {
return activeFieldsName.includes(field.name); // return activeFieldsName.includes(field.name);
}) // })
: fields; // : fields;
}, },
}); });

View File

@ -1,6 +1,5 @@
import { Schema } from '@formily/json-schema'; import { Schema } from '@formily/json-schema';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useFormActiveFields } from '../../../block-provider';
import { CollectionFieldOptions } from '../../../collection-manager'; import { CollectionFieldOptions } from '../../../collection-manager';
import { useBaseVariable } from './useBaseVariable'; import { useBaseVariable } from './useBaseVariable';
@ -23,7 +22,7 @@ export const useIterationVariable = ({
/** 消费变量值的字段 */ /** 消费变量值的字段 */
targetFieldSchema?: Schema; targetFieldSchema?: Schema;
}) => { }) => {
const { getActiveFieldsName } = useFormActiveFields() || {}; // const { getActiveFieldsName } = useFormActiveFields() || {};
const { t } = useTranslation(); const { t } = useTranslation();
const result = useBaseVariable({ const result = useBaseVariable({
collectionField, collectionField,
@ -35,13 +34,15 @@ export const useIterationVariable = ({
collectionName: currentCollection, collectionName: currentCollection,
noDisabled, noDisabled,
returnFields: (fields, option) => { returnFields: (fields, option) => {
const activeFieldsName = getActiveFieldsName?.('nester') || []; // fix https://nocobase.height.app/T-2277
return fields;
// const activeFieldsName = getActiveFieldsName?.('nester') || [];
return option.depth === 0 // return option.depth === 0
? fields.filter((field) => { // ? fields.filter((field) => {
return activeFieldsName?.includes(field.name); // return activeFieldsName?.includes(field.name);
}) // })
: fields; // : fields;
}, },
}); });