Skip to content

Commit

Permalink
fix: use form.setValuesIn instead of field.removeProperty (#1160)
Browse files Browse the repository at this point in the history
  • Loading branch information
soulwu authored Feb 25, 2021
1 parent 81361f2 commit f5fc7e6
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/next/src/logic-diagram/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Schema,
useField,
useFieldSchema,
useForm,
} from '@formily/react'
import { FormPath } from '@formily/core'
import { usePrefixCls } from '../__builtins__'
Expand All @@ -19,7 +20,6 @@ import { ButtonProps } from '@alifd/next/lib/button'
import { TooltipProps } from '@alifd/next/lib/balloon'
import { IconProps } from '@alifd/next/types/icon'
import cls from 'classnames'
import { toJS } from 'mobx'

interface ObservableDiagramSource {
relationSchema?: Schema
Expand Down Expand Up @@ -333,6 +333,7 @@ LogicDiagram.AddRuleGroup = ({
}

LogicDiagram.RemoveRule = ({ iconProps, ...buttonProps }) => {
const form = useForm()
const logicDiagram = useLogicDiagram()
const nodePath = useNodePath()
const prefixCls = usePrefixCls('formily-logic-diagram')
Expand All @@ -349,11 +350,18 @@ LogicDiagram.RemoveRule = ({ iconProps, ...buttonProps }) => {
const siblingsPath = FormPath.parse(p).parent()
const parentPath = siblingsPath.parent()
const siblings = FormPath.getIn(
toJS(logicDiagram.field.value),
siblingsPath.toString()
logicDiagram.field.value,
siblingsPath
)
if (siblings.length > 1 || parentPath.length === 0) {
logicDiagram.field.removeProperty(p)
const cur = FormPath.getIn(logicDiagram.field.value, p)
const curIndex = siblings.indexOf(cur)
const newSiblings = [...siblings]
newSiblings.splice(curIndex, 1)
form.setValuesIn(
logicDiagram.field.address.concat(siblingsPath),
newSiblings
)
} else {
remove(parentPath.toString())
}
Expand Down

0 comments on commit f5fc7e6

Please sign in to comment.