Skip to content

Commit

Permalink
feat(ui): Add link to open child workflow from builder node (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
daryllimyt authored Nov 14, 2024
1 parent 4b95e6d commit f7468b3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions frontend/src/components/workbench/canvas/action-node.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import React, { useCallback } from "react"
import Link from "next/link"
import { useWorkflowBuilder } from "@/providers/builder"
import {
ChevronDownIcon,
CircleCheckBigIcon,
LayoutListIcon,
SquareArrowOutUpRightIcon,
Trash2Icon,
} from "lucide-react"
import { Node, NodeProps, useEdges } from "reactflow"

import { useAction } from "@/lib/hooks"
import { cn, slugify } from "@/lib/utils"
import { CHILD_WORKFLOW_ACTION_TYPE } from "@/lib/workflow"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import {
Card,
Expand Down Expand Up @@ -86,6 +90,8 @@ export default React.memo(function ActionNode({
// Add this to track incoming edges
const edges = useEdges()
const incomingEdges = edges.filter((edge) => edge.target === id)
const isChildWorkflow = action?.type === CHILD_WORKFLOW_ACTION_TYPE
const childWorkflowId = action?.inputs?.workflow_id

// Create a skeleton loading state within the card frame
const renderContent = () => {
Expand Down Expand Up @@ -178,6 +184,24 @@ export default React.memo(function ActionNode({
)}
<span className="text-xs capitalize">{isConfiguredMessage}</span>
</div>
{isChildWorkflow && (
<div className="flex justify-end">
<Badge variant="outline" className="text-foreground/70">
{childWorkflowId ? (
<Link
href={`/workspaces/${workspaceId}/workflows/${childWorkflowId}`}
>
<div className="flex items-center gap-1">
<span className="font-normal">Open workflow</span>
<SquareArrowOutUpRightIcon className="size-3" />
</div>
</Link>
) : (
<span className="font-normal">Missing workflow ID</span>
)}
</Badge>
</div>
)}
</div>
</CardContent>
</>
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { ReactFlowInstance } from "reactflow"

import { isEphemeral } from "@/components/workbench/canvas/canvas"

export const CHILD_WORKFLOW_ACTION_TYPE = "core.workflow.execute" as const

/**
* Prune the graph object to remove ephemeral nodes and edges.
* @param reactFlowInstance - The React Flow instance.
Expand Down

0 comments on commit f7468b3

Please sign in to comment.