-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* move Nodes directory to subcomponent of Tree component * initial custom edge DecisionEdge * set new DecisionEdge as teh deafult edge * optional styling for edge when decision made prop passed * add edge to chosen path implementation * remove old edges from path on selection
- Loading branch information
1 parent
503f551
commit 78607ee
Showing
20 changed files
with
148 additions
and
19 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/components/Tree/Edges/DecisionEdge/DecisionEdge.spec.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,39 @@ | ||
import '@testing-library/jest-dom'; | ||
import { cleanup, render } from '@testing-library/react'; | ||
import { Position, ReactFlowProvider } from 'reactflow'; | ||
import { afterEach, describe, test } from 'vitest'; | ||
import { DecisionEdge } from './DecisionEdge'; | ||
|
||
afterEach(() => cleanup()); | ||
|
||
interface TestComponentProps { | ||
source?: string; | ||
target?: string; | ||
} | ||
|
||
const TestComponent = (props: TestComponentProps) => ( | ||
<ReactFlowProvider> | ||
<svg> | ||
<DecisionEdge | ||
id={'1'} | ||
source={props.source || 'foo'} | ||
target={props.target || 'bar'} | ||
sourceX={0} | ||
sourceY={0} | ||
targetX={0} | ||
targetY={0} | ||
sourcePosition={Position.Left} | ||
targetPosition={Position.Right} | ||
/> | ||
</svg> | ||
</ReactFlowProvider> | ||
); | ||
|
||
// ToDo: We need to find a better way to test this component. | ||
// The challenge is our component is only a slim wrapper for the BaseEdge component from reactflow. | ||
// There's not much to test here, or even grab as a reference to test the component. | ||
describe('Decision Edge', () => { | ||
test('renders', () => { | ||
render(<TestComponent />); | ||
}); | ||
}); |
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,32 @@ | ||
import { BaseEdge, EdgeProps, getSmoothStepPath } from 'reactflow'; | ||
|
||
export interface DecisionEdgeData { | ||
decisionMade?: boolean; | ||
} | ||
|
||
export interface DecisionEdgeProps extends EdgeProps<DecisionEdgeData> {} | ||
|
||
export const DecisionEdge = (props: DecisionEdgeProps) => { | ||
const { id, sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition } = props; | ||
const [edgePath] = getSmoothStepPath({ | ||
sourceX, | ||
sourceY, | ||
targetX, | ||
targetY, | ||
sourcePosition, | ||
targetPosition, | ||
}); | ||
|
||
return ( | ||
<> | ||
<BaseEdge | ||
id={id} | ||
path={edgePath} | ||
style={{ | ||
stroke: props.data?.decisionMade ? '#05b485' : '', | ||
strokeWidth: '3px', | ||
}} | ||
/> | ||
</> | ||
); | ||
}; |
2 changes: 1 addition & 1 deletion
2
...mponents/Nodes/BaseNode/BaseNode.spec.tsx → ...nts/Tree/Nodes/BaseNode/BaseNode.spec.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
5 changes: 2 additions & 3 deletions
5
src/components/Nodes/BaseNode/BaseNode.tsx → ...mponents/Tree/Nodes/BaseNode/BaseNode.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
2 changes: 1 addition & 1 deletion
2
.../Nodes/BaseNode/DragHandle/DragHandle.tsx → .../Nodes/BaseNode/DragHandle/DragHandle.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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...mponents/Nodes/BoolNode/BoolNode.spec.tsx → ...nts/Tree/Nodes/BoolNode/BoolNode.spec.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
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ts/Nodes/DefaultNode/DefaultNode.spec.tsx → ...ee/Nodes/DefaultNode/DefaultNode.spec.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
6 changes: 3 additions & 3 deletions
6
...ponents/Nodes/DefaultNode/DefaultNode.tsx → ...ts/Tree/Nodes/DefaultNode/DefaultNode.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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { Tree } from './Tree'; | ||
export { BoolNode } from './Nodes/BoolNode/BoolNode'; | ||
export type { BoolNodeData } from './Nodes/BoolNode/BoolNode'; | ||
export { DefaultNode } from './Nodes/DefaultNode/DefaultNode'; |
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