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 { useTranslation } from 'react-i18next';
|
||||||
import { useFormBlockContext } from '../../../block-provider/FormBlockProvider';
|
import { useFormBlockContext } from '../../../block-provider/FormBlockProvider';
|
||||||
import { CollectionFieldOptions_deprecated } from '../../../collection-manager';
|
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 { useFlag } from '../../../flag-provider/hooks/useFlag';
|
||||||
import { useBaseVariable } from './useBaseVariable';
|
import { useBaseVariable } from './useBaseVariable';
|
||||||
|
|
||||||
@ -107,6 +107,7 @@ export const useCurrentFormVariable = ({
|
|||||||
const { currentFormCtx, shouldDisplayCurrentForm } = useCurrentFormContext({ form: _form });
|
const { currentFormCtx, shouldDisplayCurrentForm } = useCurrentFormContext({ form: _form });
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { collectionName } = useFormBlockContext();
|
const { collectionName } = useFormBlockContext();
|
||||||
|
const dataSource = useDataSource();
|
||||||
const currentFormSettings = useBaseVariable({
|
const currentFormSettings = useBaseVariable({
|
||||||
collectionField,
|
collectionField,
|
||||||
uiSchema: schema,
|
uiSchema: schema,
|
||||||
@ -116,6 +117,7 @@ export const useCurrentFormVariable = ({
|
|||||||
title: t('Current form'),
|
title: t('Current form'),
|
||||||
collectionName: collectionName,
|
collectionName: collectionName,
|
||||||
noDisabled,
|
noDisabled,
|
||||||
|
dataSource: dataSource?.key,
|
||||||
returnFields: (fields, option) => {
|
returnFields: (fields, option) => {
|
||||||
// fix https://nocobase.height.app/T-2277
|
// fix https://nocobase.height.app/T-2277
|
||||||
return fields;
|
return fields;
|
||||||
|
@ -113,6 +113,7 @@ export const useCurrentObjectVariable = ({
|
|||||||
title: t('Current object'),
|
title: t('Current object'),
|
||||||
collectionName: collectionOfCurrentObject?.name || collection?.name,
|
collectionName: collectionOfCurrentObject?.name || collection?.name,
|
||||||
noDisabled,
|
noDisabled,
|
||||||
|
dataSource: collection?.dataSource,
|
||||||
returnFields: (fields, option) => {
|
returnFields: (fields, option) => {
|
||||||
// fix https://nocobase.height.app/T-2277
|
// fix https://nocobase.height.app/T-2277
|
||||||
return fields;
|
return fields;
|
||||||
|
@ -25,6 +25,7 @@ export const useParentObjectContext = () => {
|
|||||||
/** 变量的值 */
|
/** 变量的值 */
|
||||||
parentObjectCtx,
|
parentObjectCtx,
|
||||||
collectionName: collectionOfParentObject?.name,
|
collectionName: collectionOfParentObject?.name,
|
||||||
|
dataSource: collectionOfParentObject?.dataSource,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -47,7 +48,7 @@ export const useParentObjectVariable = ({
|
|||||||
} = {}) => {
|
} = {}) => {
|
||||||
// const { getActiveFieldsName } = useFormActiveFields() || {};
|
// const { getActiveFieldsName } = useFormActiveFields() || {};
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { shouldDisplayParentObject, parentObjectCtx, collectionName } = useParentObjectContext();
|
const { shouldDisplayParentObject, parentObjectCtx, collectionName, dataSource } = useParentObjectContext();
|
||||||
const parentObjectSettings = useBaseVariable({
|
const parentObjectSettings = useBaseVariable({
|
||||||
collectionField,
|
collectionField,
|
||||||
uiSchema: schema,
|
uiSchema: schema,
|
||||||
@ -57,6 +58,7 @@ export const useParentObjectVariable = ({
|
|||||||
title: t('Parent object'),
|
title: t('Parent object'),
|
||||||
collectionName,
|
collectionName,
|
||||||
noDisabled,
|
noDisabled,
|
||||||
|
dataSource,
|
||||||
returnFields: (fields, option) => {
|
returnFields: (fields, option) => {
|
||||||
return fields;
|
return fields;
|
||||||
// const activeFieldsName = getActiveFieldsName?.('nester') || [];
|
// const activeFieldsName = getActiveFieldsName?.('nester') || [];
|
||||||
|
@ -69,6 +69,7 @@ export const useCurrentRecordContext = () => {
|
|||||||
collectionName: realCollectionName,
|
collectionName: realCollectionName,
|
||||||
/** 块类型 */
|
/** 块类型 */
|
||||||
blockType,
|
blockType,
|
||||||
|
dataSource: collection?.dataSource,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -79,7 +80,8 @@ export const useCurrentRecordContext = () => {
|
|||||||
*/
|
*/
|
||||||
export const useCurrentRecordVariable = (props: Props = {}) => {
|
export const useCurrentRecordVariable = (props: Props = {}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { currentRecordCtx, shouldDisplayCurrentRecord, collectionName, blockType } = useCurrentRecordContext();
|
const { currentRecordCtx, shouldDisplayCurrentRecord, collectionName, blockType, dataSource } =
|
||||||
|
useCurrentRecordContext();
|
||||||
const currentRecordSettings = useBaseVariable({
|
const currentRecordSettings = useBaseVariable({
|
||||||
collectionField: props.collectionField,
|
collectionField: props.collectionField,
|
||||||
uiSchema: props.schema,
|
uiSchema: props.schema,
|
||||||
@ -90,6 +92,7 @@ export const useCurrentRecordVariable = (props: Props = {}) => {
|
|||||||
targetFieldSchema: props.targetFieldSchema,
|
targetFieldSchema: props.targetFieldSchema,
|
||||||
deprecated: blockType === 'form',
|
deprecated: blockType === 'form',
|
||||||
tooltip: blockType === 'form' ? t('This variable has been deprecated and can be replaced with "Current form"') : '',
|
tooltip: blockType === 'form' ? t('This variable has been deprecated and can be replaced with "Current form"') : '',
|
||||||
|
dataSource,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user