|
@@ -4,11 +4,12 @@ import { Button, Dropdown, Menu, Popover } from 'antd'
|
|
import React, { useState, useContext } from 'react'
|
|
import React, { useState, useContext } from 'react'
|
|
import { getBezierPath, getEdgeCenter, getMarkerEnd } from 'react-flow-renderer'
|
|
import { getBezierPath, getEdgeCenter, getMarkerEnd } from 'react-flow-renderer'
|
|
import { Actions, FlowContext } from '../../context'
|
|
import { Actions, FlowContext } from '../../context'
|
|
|
|
+import { generateElements } from '../../util'
|
|
import styles from './index.less'
|
|
import styles from './index.less'
|
|
|
|
|
|
const foreignObjectSize = 40
|
|
const foreignObjectSize = 40
|
|
|
|
|
|
-const renderMenu = ({ dispatch, elements, togglePopver, ...node }) => {
|
|
|
|
|
|
+const renderMenu = ({ dispatch, elements, togglePopver, id }) => {
|
|
const setElements = els => {
|
|
const setElements = els => {
|
|
dispatch({
|
|
dispatch({
|
|
type: Actions.SET_ELEMENTS,
|
|
type: Actions.SET_ELEMENTS,
|
|
@@ -33,13 +34,17 @@ const renderMenu = ({ dispatch, elements, togglePopver, ...node }) => {
|
|
}
|
|
}
|
|
|
|
|
|
const addAuditor = () => {
|
|
const addAuditor = () => {
|
|
|
|
+ // console.log(buildUUID())
|
|
|
|
+
|
|
const newNode = {
|
|
const newNode = {
|
|
id: buildUUID(),
|
|
id: buildUUID(),
|
|
tpye: 'input',
|
|
tpye: 'input',
|
|
- position: { x: 400, y: 0 },
|
|
|
|
|
|
+ // position: { x: 400, y: 0 },
|
|
data: {}
|
|
data: {}
|
|
}
|
|
}
|
|
- setElements(elements.concat(newNode))
|
|
|
|
|
|
+ const currentEdge = elements.find(item => item.id === id)
|
|
|
|
+ setElements(generateElements(elements, newNode, currentEdge))
|
|
|
|
+ togglePopver(false)
|
|
}
|
|
}
|
|
|
|
|
|
return (
|
|
return (
|
|
@@ -56,18 +61,21 @@ const renderMenu = ({ dispatch, elements, togglePopver, ...node }) => {
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
|
|
-export function ButtonEdge({
|
|
|
|
- id,
|
|
|
|
- sourceX,
|
|
|
|
- sourceY,
|
|
|
|
- targetX,
|
|
|
|
- targetY,
|
|
|
|
- sourcePosition,
|
|
|
|
- targetPosition,
|
|
|
|
- style = {},
|
|
|
|
- arrowHeadType,
|
|
|
|
- markerEndId
|
|
|
|
-}) {
|
|
|
|
|
|
+export function CommonEdge(props) {
|
|
|
|
+ const {
|
|
|
|
+ id,
|
|
|
|
+ sourceX,
|
|
|
|
+ sourceY,
|
|
|
|
+ targetX,
|
|
|
|
+ targetY,
|
|
|
|
+ sourcePosition,
|
|
|
|
+ targetPosition,
|
|
|
|
+ style = {},
|
|
|
|
+ arrowHeadType,
|
|
|
|
+ markerEndId
|
|
|
|
+ } = props
|
|
|
|
+ // console.log('props', props)
|
|
|
|
+
|
|
const [visible, setVisible] = useState(false)
|
|
const [visible, setVisible] = useState(false)
|
|
const { state, dispatch } = useContext(FlowContext)
|
|
const { state, dispatch } = useContext(FlowContext)
|
|
const { elements } = state
|
|
const { elements } = state
|
|
@@ -88,8 +96,6 @@ export function ButtonEdge({
|
|
})
|
|
})
|
|
|
|
|
|
const togglePopver = (isShow: boolean) => {
|
|
const togglePopver = (isShow: boolean) => {
|
|
- console.log(isShow)
|
|
|
|
-
|
|
|
|
setVisible(isShow)
|
|
setVisible(isShow)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -109,11 +115,11 @@ export function ButtonEdge({
|
|
y={edgeCenterY - foreignObjectSize / 2}>
|
|
y={edgeCenterY - foreignObjectSize / 2}>
|
|
<div className={styles.addIcon}>
|
|
<div className={styles.addIcon}>
|
|
<Popover
|
|
<Popover
|
|
- content={renderMenu({ elements, dispatch, togglePopver })}
|
|
|
|
|
|
+ content={renderMenu({ elements, dispatch, togglePopver, id })}
|
|
trigger="click"
|
|
trigger="click"
|
|
placement="right"
|
|
placement="right"
|
|
- // visible={visible}
|
|
|
|
- // destroyTooltipOnHide
|
|
|
|
|
|
+ visible={visible}
|
|
|
|
+ destroyTooltipOnHide
|
|
// onVisibleChange={togglePopver}
|
|
// onVisibleChange={togglePopver}
|
|
overlayClassName="flow-popover">
|
|
overlayClassName="flow-popover">
|
|
<Button
|
|
<Button
|