mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 07:25:15 +00:00
fix: fix linkage rules issue in subtable
This commit is contained in:
parent
9243085ab4
commit
c7569e12fd
@ -9,27 +9,47 @@
|
||||
|
||||
/* eslint-disable react-hooks/rules-of-hooks */
|
||||
import { Field } from '@formily/core';
|
||||
import { useField, useFieldSchema } from '@formily/react';
|
||||
import { Schema, useField, useFieldSchema } from '@formily/react';
|
||||
import { useEffect } from 'react';
|
||||
import { useFlag } from '../../../../flag-provider';
|
||||
import { bindLinkageRulesToFiled } from '../../../../schema-settings/LinkageRules/bindLinkageRulesToFiled';
|
||||
import { forEachLinkageRule } from '../../../../schema-settings/LinkageRules/forEachLinkageRule';
|
||||
import useLocalVariables from '../../../../variables/hooks/useLocalVariables';
|
||||
import useVariables from '../../../../variables/hooks/useVariables';
|
||||
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
|
||||
*/
|
||||
export const useLinkageRulesForSubTableOrSubForm = () => {
|
||||
const { isInSubForm, isInSubTable } = useFlag();
|
||||
const fieldSchema = useFieldSchema();
|
||||
const { isSubFormOrSubTableField } = useIsSubFormOrSubTableField();
|
||||
|
||||
if (!isInSubForm && !isInSubTable) {
|
||||
if (!isSubFormOrSubTableField(fieldSchema)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const field = useField<Field>();
|
||||
const fieldSchema = useFieldSchema();
|
||||
const { fieldSchema: schemaOfSubTableOrSubForm, formValue } = useSubFormValue();
|
||||
const localVariables = useLocalVariables();
|
||||
const variables = useVariables();
|
||||
|
@ -152,6 +152,8 @@ export function useTableColumnInitializerFields() {
|
||||
display: 'none',
|
||||
},
|
||||
},
|
||||
// 目前版本 1.4.0-alpha.2,先在这里占个位,后面会用到
|
||||
'x-use-decorator-props': isSubTable ? 'useSubTableFormItemProps' : 'useTableFormItemProps',
|
||||
};
|
||||
// interfaceConfig?.schemaInitialize?.(schema, { field, readPretty: true, block: 'Table' });
|
||||
return {
|
||||
@ -176,7 +178,7 @@ export function useTableColumnInitializerFields() {
|
||||
}
|
||||
|
||||
export function useAssociatedTableColumnInitializerFields() {
|
||||
const { name, fields } = useCollection_deprecated();
|
||||
const { fields } = useCollection_deprecated();
|
||||
const { t } = useTranslation();
|
||||
const { getInterface, getCollectionFields, getCollection } = useCollectionManager_deprecated();
|
||||
const groups = fields
|
||||
@ -346,6 +348,8 @@ export function useInheritsTableColumnInitializerFields() {
|
||||
display: 'none',
|
||||
},
|
||||
},
|
||||
// 目前版本 1.4.0-alpha.2,先在这里占个位,后面会用到
|
||||
'x-use-decorator-props': isSubTable ? 'useSubTableFormItemProps' : 'useTableFormItemProps',
|
||||
};
|
||||
return {
|
||||
name: k?.uiSchema?.title || k.name,
|
||||
|
Loading…
Reference in New Issue
Block a user