-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <[email protected]> (cherry picked from commit d2b33f6) Co-authored-by: Tyler Ohlsen <[email protected]>
- Loading branch information
1 parent
319aa10
commit 06a593e
Showing
9 changed files
with
124 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
public/pages/workflow_detail/workspace_edge/deletable-edge-styles.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.delete-edge-button { | ||
width: 20px; | ||
height: 20px; | ||
background: #eee; | ||
border: 1px solid #fff; | ||
cursor: pointer; | ||
border-radius: 50%; | ||
font-size: 12px; | ||
line-height: 1; | ||
} | ||
|
||
.delete-edge-button:hover { | ||
box-shadow: 0 0 6px 2px rgba(0, 0, 0, 0.08); | ||
} |
66 changes: 66 additions & 0 deletions
66
public/pages/workflow_detail/workspace_edge/deletable_edge.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React, { useContext } from 'react'; | ||
import { | ||
BaseEdge, | ||
EdgeLabelRenderer, | ||
EdgeProps, | ||
getBezierPath, | ||
} from 'reactflow'; | ||
import { rfContext } from '../../../store'; | ||
|
||
// styling | ||
import './deletable-edge-styles.scss'; | ||
|
||
type DeletableEdgeProps = EdgeProps; | ||
|
||
/** | ||
* A custom deletable edge. Renders a delete button in the center of the edge once connected. | ||
* Using bezier path by default. For all edge types, | ||
* see https://reactflow.dev/docs/examples/edges/edge-types/ | ||
*/ | ||
export function DeletableEdge(props: DeletableEdgeProps) { | ||
const [edgePath, labelX, labelY] = getBezierPath({ | ||
sourceX: props.sourceX, | ||
sourceY: props.sourceY, | ||
sourcePosition: props.sourcePosition, | ||
targetX: props.targetX, | ||
targetY: props.targetY, | ||
targetPosition: props.targetPosition, | ||
}); | ||
|
||
const { deleteEdge } = useContext(rfContext); | ||
|
||
const onEdgeClick = (event: any, edgeId: string) => { | ||
event.stopPropagation(); | ||
deleteEdge(edgeId); | ||
}; | ||
|
||
return ( | ||
<> | ||
<BaseEdge path={edgePath} markerEnd={props.markerEnd} /> | ||
<EdgeLabelRenderer> | ||
{/** Using in-line styling since scss can't support dynamic values*/} | ||
<div | ||
style={{ | ||
position: 'absolute', | ||
transform: `translate(-50%, -50%) translate(${labelX}px,${labelY}px)`, | ||
fontSize: 12, | ||
pointerEvents: 'all', | ||
}} | ||
className="nodrag nopan" | ||
> | ||
<button | ||
className="delete-edge-button" | ||
onClick={(event) => onEdgeClick(event, props.id)} | ||
> | ||
× | ||
</button> | ||
</div> | ||
</EdgeLabelRenderer> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export { DeletableEdge } from './deletable_edge'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters