mirror of
https://github.com/nocobase/nocobase
synced 2024-11-14 16:23:30 +00:00
fix(variable): fix the issue of inherited table fields not being able to use variables normally (#5346)
Some checks failed
auto-merge / push-commit (push) Has been cancelled
Build Docker Image / build-and-push (push) Has been cancelled
Build Pro Image / build-and-push (push) Has been cancelled
deploy client docs / Build (push) Has been cancelled
E2E / Build (push) Has been cancelled
NocoBase FrontEnd Test / frontend-test (18) (push) Has been cancelled
E2E / Core and plugins (push) Has been cancelled
E2E / plugin-workflow (push) Has been cancelled
E2E / plugin-workflow-approval (push) Has been cancelled
E2E / plugin-data-source-main (push) Has been cancelled
E2E / Comment on PR (push) Has been cancelled
Some checks failed
auto-merge / push-commit (push) Has been cancelled
Build Docker Image / build-and-push (push) Has been cancelled
Build Pro Image / build-and-push (push) Has been cancelled
deploy client docs / Build (push) Has been cancelled
E2E / Build (push) Has been cancelled
NocoBase FrontEnd Test / frontend-test (18) (push) Has been cancelled
E2E / Core and plugins (push) Has been cancelled
E2E / plugin-workflow (push) Has been cancelled
E2E / plugin-workflow-approval (push) Has been cancelled
E2E / plugin-data-source-main (push) Has been cancelled
E2E / Comment on PR (push) Has been cancelled
This commit is contained in:
parent
c273f33081
commit
b98a63fee6
@ -16,8 +16,10 @@ import { useCallback, useEffect } from 'react';
|
||||
import { useRecordIndex } from '../../../../../src/record-provider';
|
||||
import { useOperators } from '../../../../block-provider/CollectOperators';
|
||||
import { useFormBlockContext } from '../../../../block-provider/FormBlockProvider';
|
||||
import { useCollection_deprecated } from '../../../../collection-manager';
|
||||
import { InheritanceCollectionMixin, useCollection_deprecated } from '../../../../collection-manager';
|
||||
import { useCollectionRecord } from '../../../../data-source/collection-record/CollectionRecordProvider';
|
||||
import { DataSourceManager } from '../../../../data-source/data-source/DataSourceManager';
|
||||
import { useDataSourceManager } from '../../../../data-source/data-source/DataSourceManagerProvider';
|
||||
import { useFlag } from '../../../../flag-provider';
|
||||
import { DEBOUNCE_WAIT, useLocalVariables, useVariables } from '../../../../variables';
|
||||
import { getPath } from '../../../../variables/utils/getPath';
|
||||
@ -43,6 +45,7 @@ const useParseDefaultValue = () => {
|
||||
const index = useRecordIndex();
|
||||
const { type, form } = useFormBlockContext();
|
||||
const { getOperator } = useOperators();
|
||||
const dm = useDataSourceManager();
|
||||
|
||||
/**
|
||||
* name: 如 $user
|
||||
@ -97,16 +100,25 @@ const useParseDefaultValue = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const { value: parsedValue, collectionName: collectionNameOfVariable } = await variables.parseVariable(
|
||||
fieldSchema.default,
|
||||
localVariables,
|
||||
{
|
||||
fieldOperator: getOperator(fieldSchema.name),
|
||||
},
|
||||
);
|
||||
const {
|
||||
value: parsedValue,
|
||||
collectionName: collectionNameOfVariable,
|
||||
dataSource = 'main',
|
||||
} = await variables.parseVariable(fieldSchema.default, localVariables, {
|
||||
fieldOperator: getOperator(fieldSchema.name),
|
||||
});
|
||||
|
||||
// fix https://tasks.aliyun.nocobase.com/admin/ugmnj2ycfgg/popups/1qlw5c38t3b/puid/dz42x7ffr7i/filterbytk/199
|
||||
if (collectionField.target && collectionField.target !== collectionNameOfVariable) {
|
||||
if (
|
||||
collectionField.target &&
|
||||
collectionField.target !== collectionNameOfVariable &&
|
||||
!isInherit({
|
||||
collectionName: collectionField.target,
|
||||
targetCollectionName: collectionNameOfVariable,
|
||||
dm,
|
||||
dataSource,
|
||||
})
|
||||
) {
|
||||
field.loading = false;
|
||||
return;
|
||||
}
|
||||
@ -179,7 +191,30 @@ const useParseDefaultValue = () => {
|
||||
// 解决子表格(或子表单)中新增一行数据时,默认值不生效的问题
|
||||
field.setValue(fieldSchema.default);
|
||||
}
|
||||
}, [fieldSchema.default, localVariables, type, getOperator]);
|
||||
}, [fieldSchema.default, localVariables, type, getOperator, dm]);
|
||||
};
|
||||
|
||||
export default useParseDefaultValue;
|
||||
|
||||
/**
|
||||
* Determine if there is an inheritance relationship between two data tables
|
||||
* @param param0
|
||||
* @returns
|
||||
*/
|
||||
const isInherit = ({
|
||||
collectionName,
|
||||
targetCollectionName,
|
||||
dm,
|
||||
dataSource,
|
||||
}: {
|
||||
collectionName: string;
|
||||
targetCollectionName: string;
|
||||
dm: DataSourceManager;
|
||||
dataSource: string;
|
||||
}) => {
|
||||
const cm = dm?.getDataSource(dataSource)?.collectionManager;
|
||||
return cm
|
||||
?.getCollection<InheritanceCollectionMixin>(collectionName)
|
||||
?.getAllCollectionsInheritChain()
|
||||
?.includes(targetCollectionName);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user