mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 05:29:26 +08:00
fix(linkage-rule): variable conversion in sub-table/sub-form linkage rule conditions (#6702)
* fix: variable conversion in sub-table/sub-form linkage rule conditions * fix: bug * fix: style in sub-table * fix: bug
This commit is contained in:
parent
e5b73758bf
commit
d550a628d8
@ -93,7 +93,7 @@ export const useValues = (): UseValuesReturn => {
|
||||
}, 100);
|
||||
};
|
||||
|
||||
useEffect(value2data, [field.value, scopes]);
|
||||
useEffect(value2data, [field.value.leftVar, scopes]);
|
||||
|
||||
const setLeftValue = useCallback(
|
||||
(leftVar, paths) => {
|
||||
|
@ -24,6 +24,7 @@ import { useCurrentFormContext } from '../VariableInput/hooks/useFormVariable';
|
||||
import { LinkageRuleActionGroup } from './LinkageRuleActionGroup';
|
||||
import { EnableLinkage } from './components/EnableLinkage';
|
||||
import { ArrayCollapse } from './components/LinkageHeader';
|
||||
import { useFlag } from '../../flag-provider';
|
||||
|
||||
export interface Props {
|
||||
dynamicComponent: any;
|
||||
@ -65,11 +66,12 @@ function transformConditionData(condition: Condition, variableKey: '$nForm' | '$
|
||||
rightVar: value,
|
||||
};
|
||||
}
|
||||
function getActiveContextName(contextList: { name: string; ctx: any }[]): string | null {
|
||||
const priority = ['$nForm', '$nRecord'];
|
||||
for (const name of priority) {
|
||||
const item = contextList.find((ctx) => ctx.name === name && ctx.ctx);
|
||||
if (item) return name;
|
||||
function getActiveContextName(underNester, shouldDisplayCurrentForm): string | null {
|
||||
if (underNester) {
|
||||
return '$iteration';
|
||||
}
|
||||
if (shouldDisplayCurrentForm) {
|
||||
return '$nForm';
|
||||
}
|
||||
return '$nRecord';
|
||||
}
|
||||
@ -97,15 +99,16 @@ export const FormLinkageRules = withDynamicSchemaProps(
|
||||
const { getAllCollectionsInheritChain } = useCollectionManager_deprecated();
|
||||
const parentRecordData = useCollectionParentRecordData();
|
||||
const { shouldDisplayCurrentForm } = useCurrentFormContext();
|
||||
const variableKey = getActiveContextName(localVariables);
|
||||
const components = useMemo(() => ({ ArrayCollapse }), []);
|
||||
const { isInSubTable, isInSubForm } = useFlag();
|
||||
const variableKey = getActiveContextName(isInSubTable || isInSubForm, shouldDisplayCurrentForm);
|
||||
const schema = useMemo(
|
||||
() => ({
|
||||
type: 'object',
|
||||
properties: {
|
||||
rules: {
|
||||
type: 'array',
|
||||
default: transformDefaultValue(defaultValues, shouldDisplayCurrentForm ? variableKey : '$nRecord'),
|
||||
default: transformDefaultValue(defaultValues, variableKey),
|
||||
'x-component': 'ArrayCollapse',
|
||||
'x-decorator': 'FormItem',
|
||||
'x-component-props': {
|
||||
|
@ -84,7 +84,7 @@ import { AssociationOrCollectionProvider, useDataBlockProps } from '../data-sour
|
||||
import { useDataSourceManager } from '../data-source/data-source/DataSourceManagerProvider';
|
||||
import { useDataSourceKey } from '../data-source/data-source/DataSourceProvider';
|
||||
import { useFilterBlock } from '../filter-provider/FilterProvider';
|
||||
import { FlagProvider } from '../flag-provider';
|
||||
import { FlagProvider, useFlag } from '../flag-provider';
|
||||
import { useGlobalTheme } from '../global-theme';
|
||||
import { useCollectMenuItem, useCollectMenuItems, useMenuItem } from '../hooks/useMenuItem';
|
||||
import {
|
||||
@ -1129,6 +1129,7 @@ export const SchemaSettingsLinkageRules = function LinkageRules(props) {
|
||||
return gridSchema?.[dataKey] || fieldSchema?.[dataKey] || [];
|
||||
}, [gridSchema, fieldSchema, dataKey]);
|
||||
const title = titleMap[category] || t('Linkage rules');
|
||||
const flagVales = useFlag();
|
||||
const schema = useMemo<ISchema>(
|
||||
() => ({
|
||||
type: 'object',
|
||||
@ -1180,7 +1181,16 @@ export const SchemaSettingsLinkageRules = function LinkageRules(props) {
|
||||
);
|
||||
|
||||
return (
|
||||
<SchemaSettingsModalItem title={title} components={components} width={770} schema={schema} onSubmit={onSubmit} />
|
||||
<SchemaSettingsModalItem
|
||||
title={title}
|
||||
components={components}
|
||||
width={770}
|
||||
schema={schema}
|
||||
onSubmit={onSubmit}
|
||||
ModalContextProvider={(props) => {
|
||||
return <FlagProvider {...flagVales}>{props.children}</FlagProvider>;
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user