fix: varibales as & &Iteration is not correct in record picker (#3399)
This commit is contained in:
parent
6f72451d27
commit
8d06b73c48
@ -15,7 +15,7 @@ export const FormBlockContext = createContext<any>({});
|
||||
|
||||
const InternalFormBlockProvider = (props) => {
|
||||
const ctx = useFormBlockContext();
|
||||
const { action, readPretty, params, association } = props;
|
||||
const { action, readPretty, params, association, collection } = props;
|
||||
const field = useField();
|
||||
const form = useMemo(
|
||||
() =>
|
||||
@ -40,6 +40,7 @@ const InternalFormBlockProvider = (props) => {
|
||||
resource,
|
||||
updateAssociationValues,
|
||||
formBlockRef,
|
||||
collectionName: collection,
|
||||
};
|
||||
}, [action, field, form, params, resource, service, updateAssociationValues]);
|
||||
|
||||
|
@ -14,12 +14,13 @@ import {
|
||||
TableSelectorParamsProvider,
|
||||
useTableSelectorProps as useTsp,
|
||||
} from '../../../block-provider/TableSelectorProvider';
|
||||
import { CollectionProvider } from '../../../collection-manager';
|
||||
import { CollectionProvider, useCollection } from '../../../collection-manager';
|
||||
import { useCompile } from '../../hooks';
|
||||
import { ActionContextProvider } from '../action';
|
||||
import { useAssociationFieldContext, useFieldNames, useInsertSchema } from './hooks';
|
||||
import schema from './schema';
|
||||
import { flatData, getLabelFormatValue, useLabelUiSchema } from './util';
|
||||
import { useFormBlockContext } from '../../../block-provider/FormBlockProvider';
|
||||
|
||||
export const useTableSelectorProps = () => {
|
||||
const field: any = useField();
|
||||
@ -69,6 +70,7 @@ export const InternalPicker = observer(
|
||||
const fieldSchema = useFieldSchema();
|
||||
const insertSelector = useInsertSchema('Selector');
|
||||
const { options: collectionField } = useAssociationFieldContext();
|
||||
const { collectionName } = useFormBlockContext();
|
||||
const compile = useCompile();
|
||||
const labelUiSchema = useLabelUiSchema(collectionField, fieldNames?.label || 'label');
|
||||
const isAllowAddNew = fieldSchema['x-add-new'];
|
||||
@ -99,6 +101,7 @@ export const InternalPicker = observer(
|
||||
selectedRows,
|
||||
setSelectedRows,
|
||||
collectionField,
|
||||
currentFormCollection: collectionName,
|
||||
};
|
||||
|
||||
const getValue = () => {
|
||||
|
@ -1,12 +1,14 @@
|
||||
import { ArrayItems } from '@formily/antd-v5';
|
||||
import { ISchema, useField, useFieldSchema } from '@formily/react';
|
||||
import { cloneDeep } from 'lodash';
|
||||
import React from 'react';
|
||||
import _ from 'lodash';
|
||||
import React, { useContext } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useFormBlockContext, useTableSelectorContext } from '../../../block-provider';
|
||||
import { recursiveParent } from '../../../block-provider/TableSelectorProvider';
|
||||
import { useCollection, useCollectionManager } from '../../../collection-manager';
|
||||
import { useSortFields } from '../../../collection-manager/action-hooks';
|
||||
import { useRecord } from '../../../record-provider';
|
||||
import { useLocalVariables, useVariables } from '../../../variables';
|
||||
import {
|
||||
GeneralSchemaDesigner,
|
||||
SchemaSettingsDataScope,
|
||||
@ -19,10 +21,13 @@ import {
|
||||
import { useSchemaTemplate } from '../../../schema-templates';
|
||||
import { useDesignable } from '../../hooks';
|
||||
import { removeNullCondition } from '../filter';
|
||||
import { VariableInput, getShouldChange } from '../../../schema-settings/VariableInput/VariableInput';
|
||||
import { RecordPickerContext } from '../../antd/record-picker';
|
||||
|
||||
export const TableSelectorDesigner = () => {
|
||||
const { name, title } = useCollection();
|
||||
const { getCollectionJoinField } = useCollectionManager();
|
||||
const { getCollectionJoinField, getAllCollectionsInheritChain } = useCollectionManager();
|
||||
|
||||
const field = useField();
|
||||
const fieldSchema = useFieldSchema();
|
||||
const { form } = useFormBlockContext();
|
||||
@ -47,10 +52,13 @@ export const TableSelectorDesigner = () => {
|
||||
const template = useSchemaTemplate();
|
||||
const collection = useCollection();
|
||||
const { dragSort } = field.decoratorProps;
|
||||
const record = useRecord();
|
||||
const variables = useVariables();
|
||||
const { currentFormCollection } = useContext(RecordPickerContext);
|
||||
const localVariables = useLocalVariables({ collectionName: currentFormCollection });
|
||||
return (
|
||||
<GeneralSchemaDesigner template={template} title={title || name} disableInitializer>
|
||||
<SchemaSettingsDataScope
|
||||
collectionName={name}
|
||||
defaultFilter={fieldSchema?.['x-decorator-props']?.params?.filter || {}}
|
||||
form={form}
|
||||
onSubmit={({ filter }) => {
|
||||
@ -59,7 +67,7 @@ export const TableSelectorDesigner = () => {
|
||||
params.filter = filter;
|
||||
field.decoratorProps.params = params;
|
||||
fieldSchema['x-decorator-props']['params'] = params;
|
||||
let serviceFilter = cloneDeep(filter);
|
||||
let serviceFilter = _.cloneDeep(filter);
|
||||
if (extraFilter) {
|
||||
if (serviceFilter) {
|
||||
serviceFilter = {
|
||||
@ -77,6 +85,25 @@ export const TableSelectorDesigner = () => {
|
||||
},
|
||||
});
|
||||
}}
|
||||
collectionName={name}
|
||||
dynamicComponent={(props) => {
|
||||
return (
|
||||
<VariableInput
|
||||
{...props}
|
||||
form={form}
|
||||
collectionField={props.collectionField}
|
||||
record={record}
|
||||
shouldChange={getShouldChange({
|
||||
collectionField: props.collectionField,
|
||||
variables,
|
||||
localVariables,
|
||||
getAllCollectionsInheritChain,
|
||||
})}
|
||||
currentFormCollectionName={currentFormCollection}
|
||||
currentIterationCollectionName={collectionField.collectionName}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
{collection?.tree && collectionField?.target === collectionField?.collectionName && (
|
||||
<SchemaSettingsSwitchItem
|
||||
|
@ -41,6 +41,10 @@ type Props = {
|
||||
style?: React.CSSProperties;
|
||||
collectionField: CollectionFieldOptions;
|
||||
contextCollectionName?: string;
|
||||
/**指定当前表单数据表 */
|
||||
currentFormCollectionName?: string;
|
||||
/**指定当前对象数据表 */
|
||||
currentIterationCollectionName?: string;
|
||||
/**
|
||||
* 根据 `onChange` 的第一个参数,判断是否需要触发 `onChange`
|
||||
* @param value `onChange` 的第一个参数
|
||||
@ -82,12 +86,23 @@ export const VariableInput = (props: Props) => {
|
||||
record,
|
||||
returnScope = _.identity,
|
||||
targetFieldSchema,
|
||||
currentFormCollectionName,
|
||||
currentIterationCollectionName,
|
||||
} = props;
|
||||
const { name: blockCollectionName } = useBlockCollection();
|
||||
const scope = useVariableScope();
|
||||
const { operator, schema: uiSchema = collectionField?.uiSchema } = useValues();
|
||||
|
||||
const variableOptions = useVariableOptions({ collectionField, form, record, operator, uiSchema, targetFieldSchema });
|
||||
const variableOptions = useVariableOptions({
|
||||
collectionField,
|
||||
form,
|
||||
record,
|
||||
operator,
|
||||
uiSchema,
|
||||
targetFieldSchema,
|
||||
currentFormCollectionName,
|
||||
currentIterationCollectionName,
|
||||
});
|
||||
const contextVariable = useContextAssociationFields({ schema, maxDepth: 2, contextCollectionName, collectionField });
|
||||
const { compatOldVariables } = useCompatOldVariables({
|
||||
collectionField,
|
||||
@ -115,7 +130,6 @@ export const VariableInput = (props: Props) => {
|
||||
},
|
||||
[onChange, shouldChange],
|
||||
);
|
||||
|
||||
return (
|
||||
<Variable.Input
|
||||
className={className}
|
||||
|
@ -37,6 +37,10 @@ interface Props {
|
||||
noDisabled?: boolean;
|
||||
/** 消费变量值的字段 */
|
||||
targetFieldSchema?: Schema;
|
||||
/**指定当前表单数据表 */
|
||||
currentFormCollectionName?: string;
|
||||
/**指定当前对象数据表 */
|
||||
currentIterationCollectionName?: string;
|
||||
}
|
||||
|
||||
export const useVariableOptions = ({
|
||||
@ -47,6 +51,8 @@ export const useVariableOptions = ({
|
||||
noDisabled,
|
||||
targetFieldSchema,
|
||||
record,
|
||||
currentFormCollectionName,
|
||||
currentIterationCollectionName,
|
||||
}: Props) => {
|
||||
const { name: blockCollectionName = record?.__collectionName } = useBlockCollection();
|
||||
const { isInSubForm, isInSubTable } = useFlag() || {};
|
||||
@ -68,13 +74,13 @@ export const useVariableOptions = ({
|
||||
const dateVariable = useDateVariable({ operator, schema: uiSchema, noDisabled });
|
||||
const formVariable = useFormVariable({
|
||||
schema: uiSchema,
|
||||
collectionName: blockCollectionName,
|
||||
collectionName: currentFormCollectionName || blockCollectionName,
|
||||
collectionField,
|
||||
noDisabled,
|
||||
targetFieldSchema,
|
||||
});
|
||||
const iterationVariable = useIterationVariable({
|
||||
currentCollection: name,
|
||||
currentCollection: currentIterationCollectionName || name,
|
||||
collectionField,
|
||||
schema: uiSchema,
|
||||
noDisabled,
|
||||
|
Loading…
Reference in New Issue
Block a user