forked from langflow-ai/langflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: handle rendering and filtering functionality (langflow-ai#3512
- Loading branch information
1 parent
8893283
commit 8cf7f1c
Showing
25 changed files
with
761 additions
and
322 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import useFlowStore from "@/stores/flowStore"; | ||
import { BaseEdge, EdgeProps, getBezierPath, Position } from "reactflow"; | ||
|
||
export function DefaultEdge({ | ||
sourceHandleId, | ||
source, | ||
sourceX, | ||
sourceY, | ||
target, | ||
targetHandleId, | ||
targetX, | ||
targetY, | ||
...props | ||
}: EdgeProps) { | ||
const getNode = useFlowStore((state) => state.getNode); | ||
|
||
const sourceNode = getNode(source); | ||
const targetNode = getNode(target); | ||
|
||
const sourceXNew = (sourceNode?.position.x ?? 0) + (sourceNode?.width ?? 0); | ||
const targetXNew = targetNode?.position.x ?? 0; | ||
|
||
const [edgePath] = getBezierPath({ | ||
sourceX: sourceXNew, | ||
sourceY, | ||
sourcePosition: Position.Right, | ||
targetPosition: Position.Left, | ||
targetX: targetXNew, | ||
targetY, | ||
}); | ||
|
||
return <BaseEdge path={edgePath} {...props} />; | ||
} |
83 changes: 59 additions & 24 deletions
83
src/frontend/src/CustomNodes/GenericNode/components/HandleTooltipComponent/index.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 |
---|---|---|
@@ -1,30 +1,65 @@ | ||
import { TOOLTIP_EMPTY } from "../../../../constants/constants"; | ||
import useFlowStore from "../../../../stores/flowStore"; | ||
import { useTypesStore } from "../../../../stores/typesStore"; | ||
import { NodeType } from "../../../../types/flow"; | ||
import { groupByFamily } from "../../../../utils/utils"; | ||
import TooltipRenderComponent from "../tooltipRenderComponent"; | ||
import { convertTestName } from "@/components/storeCardComponent/utils/convert-test-name"; | ||
|
||
export default function HandleTooltips({ | ||
left, | ||
export default function HandleTooltipComponent({ | ||
isInput, | ||
tooltipTitle, | ||
colors, | ||
isConnecting, | ||
isCompatible, | ||
isSameNode, | ||
}: { | ||
left: boolean; | ||
nodes: NodeType[]; | ||
isInput: boolean; | ||
colors: string[]; | ||
tooltipTitle: string; | ||
isConnecting: boolean; | ||
isCompatible: boolean; | ||
isSameNode: boolean; | ||
}) { | ||
const myData = useTypesStore((state) => state.data); | ||
const nodes = useFlowStore((state) => state.nodes); | ||
|
||
let groupedObj: any = groupByFamily(myData, tooltipTitle!, left, nodes!); | ||
|
||
if (groupedObj && groupedObj.length > 0) { | ||
//@ts-ignore | ||
return groupedObj.map((item, index) => { | ||
return <TooltipRenderComponent index={index} item={item} left={left} />; | ||
}); | ||
} else { | ||
//@ts-ignore | ||
return <span data-testid={`empty-tooltip-filter`}>{TOOLTIP_EMPTY}</span>; | ||
} | ||
const tooltips = tooltipTitle.split("\n"); | ||
const plural = tooltips.length > 1 ? "s" : ""; | ||
return ( | ||
<div className="py-1.5 font-medium text-muted-foreground"> | ||
{isSameNode ? ( | ||
"Can't connect to the same node" | ||
) : ( | ||
<div className="flex items-start gap-1.5"> | ||
{isConnecting ? ( | ||
isCompatible ? ( | ||
<span> | ||
<span className="font-semibold text-foreground">Connect</span>{" "} | ||
to | ||
</span> | ||
) : ( | ||
<span>Incompatible with</span> | ||
) | ||
) : ( | ||
<span className="text-foreground"> | ||
{isInput ? `Input${plural}` : `Output${plural}`}:{" "} | ||
</span> | ||
)} | ||
{tooltips.map((word, index) => ( | ||
<div | ||
className="rounded-sm px-1.5 text-background" | ||
style={{ backgroundColor: colors[index] }} | ||
data-testid={`${isInput ? "input" : "output"}-tooltip-${convertTestName(word)}`} | ||
> | ||
{word} | ||
</div> | ||
))} | ||
{isConnecting && <span>{isInput ? `input` : `output`}</span>} | ||
</div> | ||
)} | ||
{!isConnecting && ( | ||
<div className="mt-2 flex flex-col gap-0.5 text-xs"> | ||
<div> | ||
<b>Drag</b> to connect compatible {!isInput ? "inputs" : "outputs"} | ||
</div> | ||
<div> | ||
<b>Select</b> to filter compatible {!isInput ? "inputs" : "outputs"}{" "} | ||
and components | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} |
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
Oops, something went wrong.