refactor: the default value setting of association field supports variables (#2138)
* refactor: association field support variablein default value * refactor: the current user variable only supports the target collection us users
This commit is contained in:
parent
a9aab8ed92
commit
f567f887de
@ -30,7 +30,6 @@ import { BlockItem } from '../block-item';
|
|||||||
import { removeNullCondition } from '../filter';
|
import { removeNullCondition } from '../filter';
|
||||||
import { HTMLEncode } from '../input/shared';
|
import { HTMLEncode } from '../input/shared';
|
||||||
import { FilterDynamicComponent } from '../table-v2/FilterDynamicComponent';
|
import { FilterDynamicComponent } from '../table-v2/FilterDynamicComponent';
|
||||||
import { isInvariable } from '../variable';
|
|
||||||
import { FilterFormDesigner } from './FormItem.FilterFormDesigner';
|
import { FilterFormDesigner } from './FormItem.FilterFormDesigner';
|
||||||
import { useEnsureOperatorsValid } from './SchemaSettingOptions';
|
import { useEnsureOperatorsValid } from './SchemaSettingOptions';
|
||||||
|
|
||||||
@ -354,37 +353,40 @@ FormItem.Designer = function Designer() {
|
|||||||
type: 'object',
|
type: 'object',
|
||||||
title: t('Set default value'),
|
title: t('Set default value'),
|
||||||
properties: {
|
properties: {
|
||||||
default: isInvariable(interfaceConfig)
|
default:
|
||||||
? {
|
// isInvariable(interfaceConfig)
|
||||||
...(fieldSchemaWithoutRequired || {}),
|
// ? {
|
||||||
'x-decorator': 'FormItem',
|
// ...(fieldSchemaWithoutRequired || {}),
|
||||||
'x-component-props': {
|
// 'x-decorator': 'FormItem',
|
||||||
...fieldSchema['x-component-props'],
|
// 'x-component-props': {
|
||||||
targetField,
|
// ...fieldSchema['x-component-props'],
|
||||||
component:
|
// targetField,
|
||||||
collectionField?.target && collectionField?.interface !== 'chinaRegion'
|
// component:
|
||||||
? 'AssociationSelect'
|
// collectionField?.target && collectionField?.interface !== 'chinaRegion'
|
||||||
: undefined,
|
// ? 'AssociationSelect'
|
||||||
service: {
|
// : undefined,
|
||||||
resource: collectionField?.target,
|
// service: {
|
||||||
},
|
// resource: collectionField?.target,
|
||||||
style: {
|
// },
|
||||||
width: '100%',
|
// style: {
|
||||||
verticalAlign: 'top',
|
// width: '100%',
|
||||||
},
|
// verticalAlign: 'top',
|
||||||
},
|
// },
|
||||||
name: 'default',
|
// },
|
||||||
title: t('Default value'),
|
// name: 'default',
|
||||||
default: getFieldDefaultValue(fieldSchema, collectionField),
|
// title: t('Default value'),
|
||||||
'x-read-pretty': false,
|
// default: getFieldDefaultValue(fieldSchema, collectionField),
|
||||||
'x-disabled': false,
|
// 'x-read-pretty': false,
|
||||||
}
|
// 'x-disabled': false,
|
||||||
: {
|
// }
|
||||||
|
// :
|
||||||
|
{
|
||||||
...(fieldSchemaWithoutRequired || {}),
|
...(fieldSchemaWithoutRequired || {}),
|
||||||
'x-decorator': 'FormItem',
|
'x-decorator': 'FormItem',
|
||||||
'x-component': 'VariableInput',
|
'x-component': 'VariableInput',
|
||||||
'x-component-props': {
|
'x-component-props': {
|
||||||
...(fieldSchema?.['x-component-props'] || {}),
|
...(fieldSchema?.['x-component-props'] || {}),
|
||||||
|
collectionField,
|
||||||
targetField,
|
targetField,
|
||||||
collectionName: collectionField?.collectionName,
|
collectionName: collectionField?.collectionName,
|
||||||
schema: collectionField?.uiSchema,
|
schema: collectionField?.uiSchema,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import React, { useMemo } from 'react';
|
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';
|
import { useUserVariable } from './hooks/useUserVariable';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@ -12,15 +13,23 @@ type Props = {
|
|||||||
children?: any;
|
children?: any;
|
||||||
className?: string;
|
className?: string;
|
||||||
style?: React.CSSProperties;
|
style?: React.CSSProperties;
|
||||||
|
collectionField?: CollectionFieldOptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const VariableInput = (props: Props) => {
|
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 compile = useCompile();
|
||||||
const userVariable = useUserVariable({ schema, maxDepth: 1 });
|
const userVariable = useUserVariable({ schema, maxDepth: 1 });
|
||||||
const scope = useMemo(() => {
|
const scope = useMemo(() => {
|
||||||
return [
|
const data = [
|
||||||
userVariable,
|
|
||||||
compile({
|
compile({
|
||||||
label: `{{t("Date variables")}}`,
|
label: `{{t("Date variables")}}`,
|
||||||
value: '$date',
|
value: '$date',
|
||||||
@ -35,6 +44,10 @@ export const VariableInput = (props: Props) => {
|
|||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
if (collectionField?.target === 'users') {
|
||||||
|
data.unshift(userVariable);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user