fix: fix linkage rules issue in subtable

This commit is contained in:
Zeke Zhang 2024-11-07 20:13:15 +08:00
parent 9243085ab4
commit c7569e12fd
2 changed files with 30 additions and 6 deletions

View File

@ -9,27 +9,47 @@
/* eslint-disable react-hooks/rules-of-hooks */ /* eslint-disable react-hooks/rules-of-hooks */
import { Field } from '@formily/core'; import { Field } from '@formily/core';
import { useField, useFieldSchema } from '@formily/react'; import { Schema, useField, useFieldSchema } from '@formily/react';
import { useEffect } from 'react'; import { useEffect } from 'react';
import { useFlag } from '../../../../flag-provider';
import { bindLinkageRulesToFiled } from '../../../../schema-settings/LinkageRules/bindLinkageRulesToFiled'; import { bindLinkageRulesToFiled } from '../../../../schema-settings/LinkageRules/bindLinkageRulesToFiled';
import { forEachLinkageRule } from '../../../../schema-settings/LinkageRules/forEachLinkageRule'; import { forEachLinkageRule } from '../../../../schema-settings/LinkageRules/forEachLinkageRule';
import useLocalVariables from '../../../../variables/hooks/useLocalVariables'; import useLocalVariables from '../../../../variables/hooks/useLocalVariables';
import useVariables from '../../../../variables/hooks/useVariables'; import useVariables from '../../../../variables/hooks/useVariables';
import { useSubFormValue } from '../../association-field/hooks'; import { useSubFormValue } from '../../association-field/hooks';
import { isSubMode } from '../../association-field/util';
const useIsSubFormOrSubTableField = () => {
const isSubFormOrSubTableField = (fieldSchema: Schema) => {
while (fieldSchema) {
if (isSubMode(fieldSchema)) {
return true;
}
if (fieldSchema['x-component'] === 'FormV2') {
return false;
}
fieldSchema = fieldSchema.parent;
}
return false;
};
return { isSubFormOrSubTableField };
};
/** /**
* used to bind the linkage rules of the sub-table or sub-form with the current field * used to bind the linkage rules of the sub-table or sub-form with the current field
*/ */
export const useLinkageRulesForSubTableOrSubForm = () => { export const useLinkageRulesForSubTableOrSubForm = () => {
const { isInSubForm, isInSubTable } = useFlag(); const fieldSchema = useFieldSchema();
const { isSubFormOrSubTableField } = useIsSubFormOrSubTableField();
if (!isInSubForm && !isInSubTable) { if (!isSubFormOrSubTableField(fieldSchema)) {
return; return;
} }
const field = useField<Field>(); const field = useField<Field>();
const fieldSchema = useFieldSchema();
const { fieldSchema: schemaOfSubTableOrSubForm, formValue } = useSubFormValue(); const { fieldSchema: schemaOfSubTableOrSubForm, formValue } = useSubFormValue();
const localVariables = useLocalVariables(); const localVariables = useLocalVariables();
const variables = useVariables(); const variables = useVariables();

View File

@ -152,6 +152,8 @@ export function useTableColumnInitializerFields() {
display: 'none', display: 'none',
}, },
}, },
// 目前版本 1.4.0-alpha.2,先在这里占个位,后面会用到
'x-use-decorator-props': isSubTable ? 'useSubTableFormItemProps' : 'useTableFormItemProps',
}; };
// interfaceConfig?.schemaInitialize?.(schema, { field, readPretty: true, block: 'Table' }); // interfaceConfig?.schemaInitialize?.(schema, { field, readPretty: true, block: 'Table' });
return { return {
@ -176,7 +178,7 @@ export function useTableColumnInitializerFields() {
} }
export function useAssociatedTableColumnInitializerFields() { export function useAssociatedTableColumnInitializerFields() {
const { name, fields } = useCollection_deprecated(); const { fields } = useCollection_deprecated();
const { t } = useTranslation(); const { t } = useTranslation();
const { getInterface, getCollectionFields, getCollection } = useCollectionManager_deprecated(); const { getInterface, getCollectionFields, getCollection } = useCollectionManager_deprecated();
const groups = fields const groups = fields
@ -346,6 +348,8 @@ export function useInheritsTableColumnInitializerFields() {
display: 'none', display: 'none',
}, },
}, },
// 目前版本 1.4.0-alpha.2,先在这里占个位,后面会用到
'x-use-decorator-props': isSubTable ? 'useSubTableFormItemProps' : 'useTableFormItemProps',
}; };
return { return {
name: k?.uiSchema?.title || k.name, name: k?.uiSchema?.title || k.name,