conditional inside conditional (#4362)
This commit is contained in:
@@ -11,14 +11,6 @@ import { WorkflowBlockNode } from "../nodes";
|
|||||||
import { WorkflowBlockIcon } from "../nodes/WorkflowBlockIcon";
|
import { WorkflowBlockIcon } from "../nodes/WorkflowBlockIcon";
|
||||||
import { AddNodeProps } from "../Workspace";
|
import { AddNodeProps } from "../Workspace";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { useNodes } from "@xyflow/react";
|
|
||||||
import { AppNode } from "../nodes";
|
|
||||||
import {
|
|
||||||
Tooltip,
|
|
||||||
TooltipContent,
|
|
||||||
TooltipProvider,
|
|
||||||
TooltipTrigger,
|
|
||||||
} from "@/components/ui/tooltip";
|
|
||||||
|
|
||||||
const enableCodeBlock =
|
const enableCodeBlock =
|
||||||
import.meta.env.VITE_ENABLE_CODE_BLOCK?.toLowerCase() === "true";
|
import.meta.env.VITE_ENABLE_CODE_BLOCK?.toLowerCase() === "true";
|
||||||
@@ -287,7 +279,6 @@ function WorkflowNodeLibraryPanel({
|
|||||||
onNodeClick,
|
onNodeClick,
|
||||||
first,
|
first,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const nodes = useNodes() as Array<AppNode>;
|
|
||||||
const workflowPanelData = useWorkflowPanelStore(
|
const workflowPanelData = useWorkflowPanelStore(
|
||||||
(state) => state.workflowPanelState.data,
|
(state) => state.workflowPanelState.data,
|
||||||
);
|
);
|
||||||
@@ -300,27 +291,6 @@ function WorkflowNodeLibraryPanel({
|
|||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
// Determine parent context to check if certain blocks should be disabled
|
|
||||||
const parentNode = workflowPanelData?.parent
|
|
||||||
? nodes.find((n) => n.id === workflowPanelData.parent)
|
|
||||||
: null;
|
|
||||||
const parentType = parentNode?.type;
|
|
||||||
|
|
||||||
// Check if a node type should be disabled based on parent context
|
|
||||||
const isBlockDisabled = (
|
|
||||||
nodeType: NonNullable<WorkflowBlockNode["type"]>,
|
|
||||||
): { disabled: boolean; reason: string } => {
|
|
||||||
// Disable conditional inside conditional
|
|
||||||
if (nodeType === "conditional" && parentType === "conditional") {
|
|
||||||
return {
|
|
||||||
disabled: true,
|
|
||||||
reason:
|
|
||||||
"We're working on supporting nested conditionals. Soon you'll be able to use this feature!",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return { disabled: false, reason: "" };
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Focus the input when the panel becomes active
|
// Focus the input when the panel becomes active
|
||||||
if (workflowPanelActive && inputRef.current) {
|
if (workflowPanelActive && inputRef.current) {
|
||||||
@@ -416,17 +386,11 @@ function WorkflowNodeLibraryPanel({
|
|||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
{filteredItems.length > 0 ? (
|
{filteredItems.length > 0 ? (
|
||||||
filteredItems.map((item) => {
|
filteredItems.map((item) => {
|
||||||
const { disabled, reason } = isBlockDisabled(item.nodeType);
|
|
||||||
const itemContent = (
|
const itemContent = (
|
||||||
<div
|
<div
|
||||||
key={item.nodeType}
|
key={item.nodeType}
|
||||||
className={`flex items-center justify-between rounded-sm bg-slate-elevation4 p-4 ${
|
className={`flex items-center justify-between rounded-sm bg-slate-elevation4 p-4 ${"cursor-pointer hover:bg-slate-elevation5"}`}
|
||||||
disabled
|
|
||||||
? "cursor-not-allowed opacity-50"
|
|
||||||
: "cursor-pointer hover:bg-slate-elevation5"
|
|
||||||
}`}
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (disabled) return;
|
|
||||||
onNodeClick({
|
onNodeClick({
|
||||||
nodeType: item.nodeType,
|
nodeType: item.nodeType,
|
||||||
next: workflowPanelData?.next ?? null,
|
next: workflowPanelData?.next ?? null,
|
||||||
@@ -457,20 +421,6 @@ function WorkflowNodeLibraryPanel({
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
// Wrap with tooltip if disabled
|
|
||||||
if (disabled) {
|
|
||||||
return (
|
|
||||||
<TooltipProvider key={item.nodeType}>
|
|
||||||
<Tooltip>
|
|
||||||
<TooltipTrigger asChild>{itemContent}</TooltipTrigger>
|
|
||||||
<TooltipContent side="right">
|
|
||||||
<p className="max-w-xs">{reason}</p>
|
|
||||||
</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
</TooltipProvider>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return itemContent;
|
return itemContent;
|
||||||
})
|
})
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -1925,6 +1925,11 @@ function findNextBlockLabel(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If this node itself is a conditional, prefer its own merge label
|
||||||
|
if (currentNode.type === "conditional") {
|
||||||
|
return currentNode.data.mergeLabel ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
const conditionalNodeId = currentNode.data.conditionalNodeId;
|
const conditionalNodeId = currentNode.data.conditionalNodeId;
|
||||||
if (!conditionalNodeId) {
|
if (!conditionalNodeId) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user