diff --git a/packages/react-schema-editor/src/components/FieldEditor.tsx b/packages/react-schema-editor/src/components/FieldEditor.tsx index b7160b4435c..ab0f585ccc1 100644 --- a/packages/react-schema-editor/src/components/FieldEditor.tsx +++ b/packages/react-schema-editor/src/components/FieldEditor.tsx @@ -66,7 +66,20 @@ const FormItemGroup: React.FC = ({ propsKey ) => { const newSchema = { ...schema } - _.set(newSchema, `${propsKey}.${property}`, value) + if (propsKey === ComponentPropsTypes.X_RULES) { + const newRules = _.map(schema[propsKey], rule => { + if (_.has(rule, property)) { + return { + ...rule, + [property]: value + } + } + return rule + }) + _.set(newSchema, `${propsKey}`, newRules) + } else { + _.set(newSchema, `${propsKey}.${property}`, value) + } onChange(newSchema) } @@ -91,7 +104,20 @@ const FormItemGroup: React.FC = ({ break } } - _.set(newSchema, `${propsKey}.${property}`, defaultValue) + if (propsKey === ComponentPropsTypes.X_RULES) { + const newRules = _.map(schema[propsKey], rule => { + if (_.has(rule, property)) { + return { + ...rule, + [property]: defaultValue + } + } + return rule + }) + _.set(newSchema, `${propsKey}`, newRules) + } else { + _.set(newSchema, `${propsKey}.${property}`, defaultValue) + } onChange(newSchema) } @@ -124,22 +150,65 @@ const FormItemGroup: React.FC = ({ }) } - const handleMinusClick = property => { - onChange({ - ..._.omit(schema, `${propsKey}.${property}`) + const handleRuleMessageChange = (value, property) => { + const newRules = _.map(schema[propsKey], rule => { + if (_.has(rule, property)) { + return { + ...rule, + message: value + } + } + return rule }) - } - const handlePlusClick = () => { onChange({ ...schema, - [propsKey]: { - ...schema[propsKey], - [componentPropsData.defaultValue]: BLANK_PROPERTY_VALUE - } + [ComponentPropsTypes.X_RULES]: newRules }) } + const handleMinusClick = property => { + if (propsKey === ComponentPropsTypes.X_RULES) { + const newRules = _.reduce( + schema[propsKey], + (result, rule) => { + if (_.has(rule, property)) { + return result + } + return _.concat(result, rule) + }, + [] + ) + onChange({ + ...schema, + [ComponentPropsTypes.X_RULES]: newRules + }) + } else { + onChange({ + ..._.omit(schema, `${propsKey}.${property}`) + }) + } + } + + const handlePlusClick = () => { + if (propsKey === ComponentPropsTypes.X_RULES) { + onChange({ + ...schema, + [propsKey]: _.concat(schema[propsKey], { + [componentPropsData.defaultValue]: BLANK_PROPERTY_VALUE + }) + }) + } else { + onChange({ + ...schema, + [propsKey]: { + ...schema[propsKey], + [componentPropsData.defaultValue]: BLANK_PROPERTY_VALUE + } + }) + } + } + return (
{title}
@@ -274,7 +343,12 @@ const FormItemGroup: React.FC = ({ {...formItemLayout} className="field-group-form-item" > - + { + handleRuleMessageChange(event.target.value, property) + }} + /> )} { } export const getInputType = value => { - debugger if (typeof value === 'object' || isExpression(value)) { return InputTypes.TEXT_AREA }