mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 13:39:24 +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);
|
}, 100);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(value2data, [field.value, scopes]);
|
useEffect(value2data, [field.value.leftVar, scopes]);
|
||||||
|
|
||||||
const setLeftValue = useCallback(
|
const setLeftValue = useCallback(
|
||||||
(leftVar, paths) => {
|
(leftVar, paths) => {
|
||||||
|
@ -24,6 +24,7 @@ import { useCurrentFormContext } from '../VariableInput/hooks/useFormVariable';
|
|||||||
import { LinkageRuleActionGroup } from './LinkageRuleActionGroup';
|
import { LinkageRuleActionGroup } from './LinkageRuleActionGroup';
|
||||||
import { EnableLinkage } from './components/EnableLinkage';
|
import { EnableLinkage } from './components/EnableLinkage';
|
||||||
import { ArrayCollapse } from './components/LinkageHeader';
|
import { ArrayCollapse } from './components/LinkageHeader';
|
||||||
|
import { useFlag } from '../../flag-provider';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
dynamicComponent: any;
|
dynamicComponent: any;
|
||||||
@ -65,11 +66,12 @@ function transformConditionData(condition: Condition, variableKey: '$nForm' | '$
|
|||||||
rightVar: value,
|
rightVar: value,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function getActiveContextName(contextList: { name: string; ctx: any }[]): string | null {
|
function getActiveContextName(underNester, shouldDisplayCurrentForm): string | null {
|
||||||
const priority = ['$nForm', '$nRecord'];
|
if (underNester) {
|
||||||
for (const name of priority) {
|
return '$iteration';
|
||||||
const item = contextList.find((ctx) => ctx.name === name && ctx.ctx);
|
}
|
||||||
if (item) return name;
|
if (shouldDisplayCurrentForm) {
|
||||||
|
return '$nForm';
|
||||||
}
|
}
|
||||||
return '$nRecord';
|
return '$nRecord';
|
||||||
}
|
}
|
||||||
@ -97,15 +99,16 @@ export const FormLinkageRules = withDynamicSchemaProps(
|
|||||||
const { getAllCollectionsInheritChain } = useCollectionManager_deprecated();
|
const { getAllCollectionsInheritChain } = useCollectionManager_deprecated();
|
||||||
const parentRecordData = useCollectionParentRecordData();
|
const parentRecordData = useCollectionParentRecordData();
|
||||||
const { shouldDisplayCurrentForm } = useCurrentFormContext();
|
const { shouldDisplayCurrentForm } = useCurrentFormContext();
|
||||||
const variableKey = getActiveContextName(localVariables);
|
|
||||||
const components = useMemo(() => ({ ArrayCollapse }), []);
|
const components = useMemo(() => ({ ArrayCollapse }), []);
|
||||||
|
const { isInSubTable, isInSubForm } = useFlag();
|
||||||
|
const variableKey = getActiveContextName(isInSubTable || isInSubForm, shouldDisplayCurrentForm);
|
||||||
const schema = useMemo(
|
const schema = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
rules: {
|
rules: {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
default: transformDefaultValue(defaultValues, shouldDisplayCurrentForm ? variableKey : '$nRecord'),
|
default: transformDefaultValue(defaultValues, variableKey),
|
||||||
'x-component': 'ArrayCollapse',
|
'x-component': 'ArrayCollapse',
|
||||||
'x-decorator': 'FormItem',
|
'x-decorator': 'FormItem',
|
||||||
'x-component-props': {
|
'x-component-props': {
|
||||||
|
@ -84,7 +84,7 @@ import { AssociationOrCollectionProvider, useDataBlockProps } from '../data-sour
|
|||||||
import { useDataSourceManager } from '../data-source/data-source/DataSourceManagerProvider';
|
import { useDataSourceManager } from '../data-source/data-source/DataSourceManagerProvider';
|
||||||
import { useDataSourceKey } from '../data-source/data-source/DataSourceProvider';
|
import { useDataSourceKey } from '../data-source/data-source/DataSourceProvider';
|
||||||
import { useFilterBlock } from '../filter-provider/FilterProvider';
|
import { useFilterBlock } from '../filter-provider/FilterProvider';
|
||||||
import { FlagProvider } from '../flag-provider';
|
import { FlagProvider, useFlag } from '../flag-provider';
|
||||||
import { useGlobalTheme } from '../global-theme';
|
import { useGlobalTheme } from '../global-theme';
|
||||||
import { useCollectMenuItem, useCollectMenuItems, useMenuItem } from '../hooks/useMenuItem';
|
import { useCollectMenuItem, useCollectMenuItems, useMenuItem } from '../hooks/useMenuItem';
|
||||||
import {
|
import {
|
||||||
@ -1129,6 +1129,7 @@ export const SchemaSettingsLinkageRules = function LinkageRules(props) {
|
|||||||
return gridSchema?.[dataKey] || fieldSchema?.[dataKey] || [];
|
return gridSchema?.[dataKey] || fieldSchema?.[dataKey] || [];
|
||||||
}, [gridSchema, fieldSchema, dataKey]);
|
}, [gridSchema, fieldSchema, dataKey]);
|
||||||
const title = titleMap[category] || t('Linkage rules');
|
const title = titleMap[category] || t('Linkage rules');
|
||||||
|
const flagVales = useFlag();
|
||||||
const schema = useMemo<ISchema>(
|
const schema = useMemo<ISchema>(
|
||||||
() => ({
|
() => ({
|
||||||
type: 'object',
|
type: 'object',
|
||||||
@ -1180,7 +1181,16 @@ export const SchemaSettingsLinkageRules = function LinkageRules(props) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
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