mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-07 22:49:26 +08:00
fix(variable): fix issues where variables cannot be properly used in third-party data source blocks (#5782)
* fix(variable): resolve field visibility issues in multi-data source variables * fix(test): fix unit test error
This commit is contained in:
parent
4cc95587af
commit
e35768ce61
@ -12,7 +12,7 @@ import { Schema } from '@formily/json-schema';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useFormBlockContext } from '../../../block-provider/FormBlockProvider';
|
||||
import { CollectionFieldOptions_deprecated } from '../../../collection-manager';
|
||||
import { useDataBlockRequestData } from '../../../data-source';
|
||||
import { useDataBlockRequestData, useDataSource } from '../../../data-source';
|
||||
import { useFlag } from '../../../flag-provider/hooks/useFlag';
|
||||
import { useBaseVariable } from './useBaseVariable';
|
||||
|
||||
@ -107,6 +107,7 @@ export const useCurrentFormVariable = ({
|
||||
const { currentFormCtx, shouldDisplayCurrentForm } = useCurrentFormContext({ form: _form });
|
||||
const { t } = useTranslation();
|
||||
const { collectionName } = useFormBlockContext();
|
||||
const dataSource = useDataSource();
|
||||
const currentFormSettings = useBaseVariable({
|
||||
collectionField,
|
||||
uiSchema: schema,
|
||||
@ -116,6 +117,7 @@ export const useCurrentFormVariable = ({
|
||||
title: t('Current form'),
|
||||
collectionName: collectionName,
|
||||
noDisabled,
|
||||
dataSource: dataSource?.key,
|
||||
returnFields: (fields, option) => {
|
||||
// fix https://nocobase.height.app/T-2277
|
||||
return fields;
|
||||
|
@ -113,6 +113,7 @@ export const useCurrentObjectVariable = ({
|
||||
title: t('Current object'),
|
||||
collectionName: collectionOfCurrentObject?.name || collection?.name,
|
||||
noDisabled,
|
||||
dataSource: collection?.dataSource,
|
||||
returnFields: (fields, option) => {
|
||||
// fix https://nocobase.height.app/T-2277
|
||||
return fields;
|
||||
|
@ -25,6 +25,7 @@ export const useParentObjectContext = () => {
|
||||
/** 变量的值 */
|
||||
parentObjectCtx,
|
||||
collectionName: collectionOfParentObject?.name,
|
||||
dataSource: collectionOfParentObject?.dataSource,
|
||||
};
|
||||
};
|
||||
|
||||
@ -47,7 +48,7 @@ export const useParentObjectVariable = ({
|
||||
} = {}) => {
|
||||
// const { getActiveFieldsName } = useFormActiveFields() || {};
|
||||
const { t } = useTranslation();
|
||||
const { shouldDisplayParentObject, parentObjectCtx, collectionName } = useParentObjectContext();
|
||||
const { shouldDisplayParentObject, parentObjectCtx, collectionName, dataSource } = useParentObjectContext();
|
||||
const parentObjectSettings = useBaseVariable({
|
||||
collectionField,
|
||||
uiSchema: schema,
|
||||
@ -57,6 +58,7 @@ export const useParentObjectVariable = ({
|
||||
title: t('Parent object'),
|
||||
collectionName,
|
||||
noDisabled,
|
||||
dataSource,
|
||||
returnFields: (fields, option) => {
|
||||
return fields;
|
||||
// const activeFieldsName = getActiveFieldsName?.('nester') || [];
|
||||
|
@ -69,6 +69,7 @@ export const useCurrentRecordContext = () => {
|
||||
collectionName: realCollectionName,
|
||||
/** 块类型 */
|
||||
blockType,
|
||||
dataSource: collection?.dataSource,
|
||||
};
|
||||
};
|
||||
|
||||
@ -79,7 +80,8 @@ export const useCurrentRecordContext = () => {
|
||||
*/
|
||||
export const useCurrentRecordVariable = (props: Props = {}) => {
|
||||
const { t } = useTranslation();
|
||||
const { currentRecordCtx, shouldDisplayCurrentRecord, collectionName, blockType } = useCurrentRecordContext();
|
||||
const { currentRecordCtx, shouldDisplayCurrentRecord, collectionName, blockType, dataSource } =
|
||||
useCurrentRecordContext();
|
||||
const currentRecordSettings = useBaseVariable({
|
||||
collectionField: props.collectionField,
|
||||
uiSchema: props.schema,
|
||||
@ -90,6 +92,7 @@ export const useCurrentRecordVariable = (props: Props = {}) => {
|
||||
targetFieldSchema: props.targetFieldSchema,
|
||||
deprecated: blockType === 'form',
|
||||
tooltip: blockType === 'form' ? t('This variable has been deprecated and can be replaced with "Current form"') : '',
|
||||
dataSource,
|
||||
});
|
||||
|
||||
return {
|
||||
|
Loading…
x
Reference in New Issue
Block a user