diff --git a/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx b/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx index a1d022901..9e7ce45d3 100644 --- a/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx +++ b/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx @@ -30,7 +30,6 @@ import { BlockItem } from '../block-item'; import { removeNullCondition } from '../filter'; import { HTMLEncode } from '../input/shared'; import { FilterDynamicComponent } from '../table-v2/FilterDynamicComponent'; -import { isInvariable } from '../variable'; import { FilterFormDesigner } from './FormItem.FilterFormDesigner'; import { useEnsureOperatorsValid } from './SchemaSettingOptions'; @@ -354,70 +353,73 @@ FormItem.Designer = function Designer() { type: 'object', title: t('Set default value'), properties: { - default: isInvariable(interfaceConfig) - ? { - ...(fieldSchemaWithoutRequired || {}), - 'x-decorator': 'FormItem', - 'x-component-props': { - ...fieldSchema['x-component-props'], - targetField, - component: - collectionField?.target && collectionField?.interface !== 'chinaRegion' - ? 'AssociationSelect' - : undefined, - service: { - resource: collectionField?.target, - }, - style: { - width: '100%', - verticalAlign: 'top', - }, - }, - name: 'default', - title: t('Default value'), - default: getFieldDefaultValue(fieldSchema, collectionField), - 'x-read-pretty': false, - 'x-disabled': false, - } - : { - ...(fieldSchemaWithoutRequired || {}), - 'x-decorator': 'FormItem', - 'x-component': 'VariableInput', - 'x-component-props': { - ...(fieldSchema?.['x-component-props'] || {}), - targetField, - collectionName: collectionField?.collectionName, - schema: collectionField?.uiSchema, - className: defaultInputStyle, - renderSchemaComponent: function Com(props) { - const s = _.cloneDeep(fieldSchemaWithoutRequired) || ({} as Schema); - s.title = ''; - s['x-read-pretty'] = false; - s['x-disabled'] = false; + default: + // isInvariable(interfaceConfig) + // ? { + // ...(fieldSchemaWithoutRequired || {}), + // 'x-decorator': 'FormItem', + // 'x-component-props': { + // ...fieldSchema['x-component-props'], + // targetField, + // component: + // collectionField?.target && collectionField?.interface !== 'chinaRegion' + // ? 'AssociationSelect' + // : undefined, + // service: { + // resource: collectionField?.target, + // }, + // style: { + // width: '100%', + // verticalAlign: 'top', + // }, + // }, + // name: 'default', + // title: t('Default value'), + // default: getFieldDefaultValue(fieldSchema, collectionField), + // 'x-read-pretty': false, + // 'x-disabled': false, + // } + // : + { + ...(fieldSchemaWithoutRequired || {}), + 'x-decorator': 'FormItem', + 'x-component': 'VariableInput', + 'x-component-props': { + ...(fieldSchema?.['x-component-props'] || {}), + collectionField, + targetField, + collectionName: collectionField?.collectionName, + schema: collectionField?.uiSchema, + className: defaultInputStyle, + renderSchemaComponent: function Com(props) { + const s = _.cloneDeep(fieldSchemaWithoutRequired) || ({} as Schema); + s.title = ''; + s['x-read-pretty'] = false; + s['x-disabled'] = false; - return ( - - ); - }, + }, + }} + /> + ); }, - name: 'default', - title: t('Default value'), - default: getFieldDefaultValue(fieldSchema, collectionField), }, + name: 'default', + title: t('Default value'), + default: getFieldDefaultValue(fieldSchema, collectionField), + }, }, } as ISchema } diff --git a/packages/core/client/src/schema-settings/VariableInput/VariableInput.tsx b/packages/core/client/src/schema-settings/VariableInput/VariableInput.tsx index d7085908b..8960becd2 100644 --- a/packages/core/client/src/schema-settings/VariableInput/VariableInput.tsx +++ b/packages/core/client/src/schema-settings/VariableInput/VariableInput.tsx @@ -1,5 +1,6 @@ import React, { useMemo } from 'react'; -import { Variable, useCompile } from '../../schema-component'; +import { CollectionFieldOptions } from '../../collection-manager'; +import { useCompile, Variable } from '../../schema-component'; import { useUserVariable } from './hooks/useUserVariable'; type Props = { @@ -12,15 +13,23 @@ type Props = { children?: any; className?: string; style?: React.CSSProperties; + collectionField?: CollectionFieldOptions; }; export const VariableInput = (props: Props) => { - const { value, onChange, renderSchemaComponent: RenderSchemaComponent, style, schema, className } = props; + const { + value, + onChange, + renderSchemaComponent: RenderSchemaComponent, + style, + schema, + className, + collectionField, + } = props; const compile = useCompile(); const userVariable = useUserVariable({ schema, maxDepth: 1 }); const scope = useMemo(() => { - return [ - userVariable, + const data = [ compile({ label: `{{t("Date variables")}}`, value: '$date', @@ -35,6 +44,10 @@ export const VariableInput = (props: Props) => { ], }), ]; + if (collectionField?.target === 'users') { + data.unshift(userVariable); + } + return data; }, []); return (