mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 07:15:36 +00:00
fix: useCurrentFormVariable (#4428)
* refactor: useCurrentFormVariable support detail block * fix: useCurrentFormVariable * fix: bug
This commit is contained in:
parent
26a2a6204a
commit
304f87bee2
@ -969,6 +969,8 @@ export const SchemaSettingsLinkageRules = function LinkageRules(props) {
|
||||
const { type: formBlockType } = useFormBlockType();
|
||||
const type = props?.type || fieldSchema?.['x-action'] ? 'button' : 'field';
|
||||
const gridSchema = findGridSchema(fieldSchema) || fieldSchema;
|
||||
const options = useLinkageCollectionFilterOptions(collectionName);
|
||||
const linkageOptions = useLinkageCollectionFieldOptions(collectionName, readPretty);
|
||||
const schema = useMemo<ISchema>(
|
||||
() => ({
|
||||
type: 'object',
|
||||
@ -977,14 +979,11 @@ export const SchemaSettingsLinkageRules = function LinkageRules(props) {
|
||||
fieldReaction: {
|
||||
'x-component': FormLinkageRules,
|
||||
'x-use-component-props': () => {
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
const options = useLinkageCollectionFilterOptions(collectionName);
|
||||
return {
|
||||
options,
|
||||
defaultValues: gridSchema?.['x-linkage-rules'] || fieldSchema?.['x-linkage-rules'],
|
||||
type,
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
linkageOptions: useLinkageCollectionFieldOptions(collectionName, readPretty),
|
||||
linkageOptions,
|
||||
collectionName,
|
||||
form,
|
||||
variables,
|
||||
|
@ -10,8 +10,13 @@
|
||||
import { Form } from '@formily/core';
|
||||
import { Schema } from '@formily/json-schema';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useFormBlockContext } from '../../../block-provider';
|
||||
import { CollectionFieldOptions_deprecated } from '../../../collection-manager';
|
||||
import { useBlockContext, useDetailsBlockContext, useFormBlockContext } from '../../../block-provider';
|
||||
import {
|
||||
CollectionFieldOptions_deprecated,
|
||||
useResourceActionContext,
|
||||
useResourceContext,
|
||||
} from '../../../collection-manager';
|
||||
import { useDataBlockRequest } from '../../../data-source';
|
||||
import { useBaseVariable } from './useBaseVariable';
|
||||
|
||||
interface Props {
|
||||
@ -60,6 +65,11 @@ export const useFormVariable = ({ collectionName, collectionField, schema, noDis
|
||||
return result;
|
||||
};
|
||||
|
||||
const useCurrentFormData = () => {
|
||||
const ctx = useDataBlockRequest();
|
||||
return ctx?.data?.data?.[0] || ctx?.data?.data;
|
||||
};
|
||||
|
||||
/**
|
||||
* 变量:`当前表单`
|
||||
* @param param0
|
||||
@ -74,7 +84,8 @@ export const useCurrentFormVariable = ({
|
||||
}: Props = {}) => {
|
||||
// const { getActiveFieldsName } = useFormActiveFields() || {};
|
||||
const { t } = useTranslation();
|
||||
const { form, collectionName, service } = useFormBlockContext();
|
||||
const { form, collectionName } = useFormBlockContext();
|
||||
const formData = useCurrentFormData();
|
||||
const currentFormSettings = useBaseVariable({
|
||||
collectionField,
|
||||
uiSchema: schema,
|
||||
@ -103,9 +114,9 @@ export const useCurrentFormVariable = ({
|
||||
currentFormSettings,
|
||||
/** 变量值 */
|
||||
currentFormCtx:
|
||||
formInstance?.values && Object.keys(formInstance?.values)?.length
|
||||
formInstance?.readPretty === false && formInstance?.values && Object.keys(formInstance?.values)?.length
|
||||
? formInstance?.values
|
||||
: service?.data?.data || formInstance?.values,
|
||||
: formData || formInstance?.values,
|
||||
/** 用来判断是否可以显示`当前表单`变量 */
|
||||
shouldDisplayCurrentForm: formInstance && !formInstance.readPretty,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user