-
Notifications
You must be signed in to change notification settings - Fork 80
Workflow Elements #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Workflow Elements #116
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ebb0c1f
Draft workflow elements
haydenbleasel 530a37b
Create canvas.tsx
haydenbleasel fe3370f
Draft examples
haydenbleasel f4b8efd
Improve demo
haydenbleasel e295d03
Add Connection component
haydenbleasel 9bb89c5
Add Controls and Panel
haydenbleasel 56e4217
Update components
haydenbleasel 9170b47
Update workflow.tsx
haydenbleasel dff2b11
Update node.tsx
haydenbleasel 50acc81
Update edge.tsx
haydenbleasel d3107eb
Update node.tsx
haydenbleasel bc1f7b4
Scaffold Toolbar
haydenbleasel 40825dc
Fix toolbar classname
haydenbleasel 7c68242
Update controls.tsx
haydenbleasel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,181 @@ | ||
"use client"; | ||
|
||
import { Canvas } from "@repo/elements/canvas"; | ||
import { Edge } from "@repo/elements/edge"; | ||
import { | ||
Node, | ||
NodeContent, | ||
NodeDescription, | ||
NodeFooter, | ||
NodeHeader, | ||
NodeTitle, | ||
} from "@repo/elements/node"; | ||
|
||
const nodeIds = { | ||
start: "start", | ||
process1: "process1", | ||
process2: "process2", | ||
decision: "decision", | ||
output1: "output1", | ||
output2: "output2", | ||
}; | ||
|
||
const nodes = [ | ||
{ | ||
id: nodeIds.start, | ||
type: "workflow", | ||
position: { x: 0, y: 0 }, | ||
data: { | ||
label: "Start", | ||
description: "Initialize workflow", | ||
handles: { target: false, source: true }, | ||
content: "Triggered by user action at 09:30 AM", | ||
footer: "Status: Ready", | ||
}, | ||
}, | ||
{ | ||
id: nodeIds.process1, | ||
type: "workflow", | ||
position: { x: 500, y: 0 }, | ||
data: { | ||
label: "Process Data", | ||
description: "Transform input", | ||
handles: { target: true, source: true }, | ||
content: "Validating 1,234 records and applying business rules", | ||
footer: "Duration: ~2.5s", | ||
}, | ||
}, | ||
{ | ||
id: nodeIds.decision, | ||
type: "workflow", | ||
position: { x: 1000, y: 0 }, | ||
data: { | ||
label: "Decision Point", | ||
description: "Route based on conditions", | ||
handles: { target: true, source: true }, | ||
content: "Evaluating: data.status === 'valid' && data.score > 0.8", | ||
footer: "Confidence: 94%", | ||
}, | ||
}, | ||
{ | ||
id: nodeIds.output1, | ||
type: "workflow", | ||
position: { x: 1500, y: -300 }, | ||
data: { | ||
label: "Success Path", | ||
description: "Handle success case", | ||
handles: { target: true, source: true }, | ||
content: "1,156 records passed validation (93.7%)", | ||
footer: "Next: Send to production", | ||
}, | ||
}, | ||
{ | ||
id: nodeIds.output2, | ||
type: "workflow", | ||
position: { x: 1500, y: 300 }, | ||
data: { | ||
label: "Error Path", | ||
description: "Handle error case", | ||
handles: { target: true, source: true }, | ||
content: "78 records failed validation (6.3%)", | ||
footer: "Next: Queue for review", | ||
}, | ||
}, | ||
{ | ||
id: nodeIds.process2, | ||
type: "workflow", | ||
position: { x: 2000, y: 0 }, | ||
data: { | ||
label: "Complete", | ||
description: "Finalize workflow", | ||
handles: { target: true, source: false }, | ||
content: "All records processed and routed successfully", | ||
footer: "Total time: 4.2s", | ||
}, | ||
}, | ||
]; | ||
|
||
const edges = [ | ||
{ | ||
id: "edge1", | ||
source: nodeIds.start, | ||
target: nodeIds.process1, | ||
type: "animated", | ||
}, | ||
{ | ||
id: "edge2", | ||
source: nodeIds.process1, | ||
target: nodeIds.decision, | ||
type: "animated", | ||
}, | ||
{ | ||
id: "edge3", | ||
source: nodeIds.decision, | ||
target: nodeIds.output1, | ||
type: "animated", | ||
}, | ||
{ | ||
id: "edge4", | ||
source: nodeIds.decision, | ||
target: nodeIds.output2, | ||
type: "temporary", | ||
}, | ||
{ | ||
id: "edge5", | ||
source: nodeIds.output1, | ||
target: nodeIds.process2, | ||
type: "animated", | ||
}, | ||
{ | ||
id: "edge6", | ||
source: nodeIds.output2, | ||
target: nodeIds.process2, | ||
type: "temporary", | ||
}, | ||
]; | ||
|
||
const nodeTypes = { | ||
workflow: ({ | ||
data, | ||
}: { | ||
data: { | ||
label: string; | ||
description: string; | ||
handles: { target: boolean; source: boolean }; | ||
content: string; | ||
footer: string; | ||
}; | ||
}) => ( | ||
<Node handles={data.handles}> | ||
<NodeHeader> | ||
<NodeTitle>{data.label}</NodeTitle> | ||
<NodeDescription>{data.description}</NodeDescription> | ||
</NodeHeader> | ||
<NodeContent> | ||
<p className="text-sm">{data.content}</p> | ||
</NodeContent> | ||
<NodeFooter> | ||
<p className="text-muted-foreground text-xs">{data.footer}</p> | ||
</NodeFooter> | ||
</Node> | ||
), | ||
}; | ||
|
||
const edgeTypes = { | ||
animated: Edge.Animated, | ||
temporary: Edge.Temporary, | ||
}; | ||
|
||
const Example = () => ( | ||
<div style={{ height: "400px", width: "100%" }}> | ||
<Canvas | ||
edges={edges} | ||
edgeTypes={edgeTypes} | ||
fitView | ||
nodes={nodes} | ||
nodeTypes={nodeTypes} | ||
/> | ||
</div> | ||
); | ||
|
||
export default Example; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,22 @@ | ||
import { Background, ReactFlow, type ReactFlowProps } from "@xyflow/react"; | ||
import type { ReactNode } from "react"; | ||
import "@xyflow/react/dist/style.css"; | ||
|
||
type CanvasProps = ReactFlowProps & { | ||
children?: ReactNode; | ||
}; | ||
|
||
export const Canvas = ({ children, ...props }: CanvasProps) => ( | ||
<ReactFlow | ||
deleteKeyCode={["Backspace", "Delete"]} | ||
fitView | ||
panOnDrag={false} | ||
panOnScroll | ||
selectionOnDrag={true} | ||
zoomOnDoubleClick={false} | ||
{...props} | ||
> | ||
<Background bgColor="var(--sidebar)" /> | ||
{children} | ||
</ReactFlow> | ||
); |
This file contains hidden or 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,28 @@ | ||
import type { ConnectionLineComponent } from "@xyflow/react"; | ||
|
||
const HALF = 0.5; | ||
|
||
export const Connection: ConnectionLineComponent = ({ | ||
fromX, | ||
fromY, | ||
toX, | ||
toY, | ||
}) => ( | ||
<g> | ||
<path | ||
className="animated" | ||
d={`M${fromX},${fromY} C ${fromX + (toX - fromX) * HALF},${fromY} ${fromX + (toX - fromX) * HALF},${toY} ${toX},${toY}`} | ||
fill="none" | ||
stroke="var(--color-ring)" | ||
strokeWidth={1} | ||
/> | ||
<circle | ||
cx={toX} | ||
cy={toY} | ||
fill="#fff" | ||
r={3} | ||
stroke="var(--color-ring)" | ||
strokeWidth={1} | ||
/> | ||
</g> | ||
); |
This file contains hidden or 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,18 @@ | ||
'use client'; | ||
|
||
import { cn } from '@/lib/utils'; | ||
import { Controls as ControlsPrimitive } from '@xyflow/react'; | ||
import type { ComponentProps } from 'react'; | ||
|
||
export type ControlsProps = ComponentProps<typeof ControlsPrimitive>; | ||
|
||
export const Controls = ({ className, ...props }: ControlsProps) => ( | ||
<ControlsPrimitive | ||
className={cn( | ||
'rounded-md border gap-px bg-card p-1 overflow-hidden shadow-none!', | ||
'[&>button]:rounded-md [&>button]:border-none', | ||
className, | ||
)} | ||
{...props} | ||
/> | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.