Skip to content

Commit

Permalink
reverse null state
Browse files Browse the repository at this point in the history
  • Loading branch information
Hasham268 committed Jun 14, 2024
1 parent 7d99ee6 commit 6f1b818
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 15 deletions.
Binary file added flask/Temp/temp_image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added flask/Temp/temp_image_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added flask/Temp/temp_image_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added flask/Temp/temp_image_3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 23 additions & 3 deletions src/renderer/Flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,22 +605,42 @@ function Flow({ projectType }) {
setUserInput(input);
};

const handleRemoveEdge = useCallback(
(id, source, target) => {
setEdges((prevEdges) => prevEdges.filter((edge) => edge.id !== id));


const targetNode = nodes.find((node) => node.id === target);

if (!targetNode) {
return;
}
if (targetNode.type === 'outputNode') {
setFinalResult(null);
}
},
[setEdges],
);

return (
<>
<div
style={{
width: '100vw',
height: '450px',
fontFamily: 'Gilroy'
fontFamily: 'Gilroy',
// backgroundColor: '#000',
}}
className="border border-black "

>
<ReactFlow
nodes={nodes}
onNodesChange={onNodesChange}
edges={edges}
// edges={edges}
edges={edges.map((edge) => ({
...edge,
data: { ...edge.data, handleRemoveEdge },
}))}
onEdgesChange={onEdgesChange}
onConnect={onConnect}
nodeTypes={nodeTypes}
Expand Down
28 changes: 16 additions & 12 deletions src/utils/customEdge.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
/* eslint-disable react/button-has-type */
import React from 'react';
import PropTypes from 'prop-types';
import {
BezierEdge,
EdgeLabelRenderer,
getBezierPath,
useReactFlow,
} from 'reactflow';
import { BezierEdge, EdgeLabelRenderer, getBezierPath } from 'reactflow';
import { X } from 'react-bootstrap-icons'; // Keep this import if you want to use the X icon from react-bootstrap-icons

function CustomEdge(props) {
Expand All @@ -18,10 +13,9 @@ function CustomEdge(props) {
targetY,
sourcePosition,
targetPosition,
data,
} = props;

const { setEdges } = useReactFlow();

const [edgePath, labelX, labelY] = getBezierPath({
sourceX,
sourceY,
Expand All @@ -38,9 +32,14 @@ function CustomEdge(props) {
<button
aria-label="Delete Edge"
className="absolute text-red-500 transform -translate-x-1/2 -translate-y-1/2 z-10"
style={{ transform: `translate(${labelX}px, ${labelY}px)`, pointerEvents: 'all' }}
style={{
transform: `translate(${labelX}px, ${labelY}px)`,
pointerEvents: 'all',
}}
onClick={() => {
setEdges((prevEdges) => prevEdges.filter((edge) => edge.id !== id));
if (data && data.handleRemoveEdge) {
data.handleRemoveEdge(id, props.source, props.target);
}
}}
>
<X />
Expand All @@ -56,8 +55,13 @@ CustomEdge.propTypes = {
sourceY: PropTypes.number.isRequired,
targetX: PropTypes.number.isRequired,
targetY: PropTypes.number.isRequired,
sourcePosition: PropTypes.oneOf(['top', 'right', 'bottom', 'left']).isRequired,
targetPosition: PropTypes.oneOf(['top', 'right', 'bottom', 'left']).isRequired,
sourcePosition: PropTypes.oneOf(['top', 'right', 'bottom', 'left'])
.isRequired,
targetPosition: PropTypes.oneOf(['top', 'right', 'bottom', 'left'])
.isRequired,
data: PropTypes.shape({
handleRemoveEdge: PropTypes.func,
}),
};

export default CustomEdge;

0 comments on commit 6f1b818

Please sign in to comment.