Skip to content

Self-improving AI Employees for everyone

refactor(ConditionalEdge): migrate edge label + add-button to Tailwind

trohitga2cee7b52181
diff --git a/client/src/components/ConditionalEdge.tsx b/client/src/components/ConditionalEdge.tsx
index 8d2b7cea..e465b53c 100644
--- a/client/src/components/ConditionalEdge.tsx
+++ b/client/src/components/ConditionalEdge.tsx
@@ -13,12 +13,12 @@ import {
EdgeLabelRenderer,
BaseEdge,
} from 'reactflow';
-import { useAppTheme } from '../hooks/useAppTheme';
+import { Maximize2 } from 'lucide-react';
+import { cn } from '@/lib/utils';
import { ConditionalEdgeData, formatConditionLabel } from '../types/EdgeCondition';
import EdgeConditionEditor from './EdgeConditionEditor';
interface ConditionalEdgeProps extends EdgeProps<ConditionalEdgeData> {
- /** Callback when condition is updated */
onConditionUpdate?: (
edgeId: string,
condition: ConditionalEdgeData['condition'],
@@ -40,17 +40,11 @@ const ConditionalEdge: React.FC<ConditionalEdgeProps> = ({
selected,
onConditionUpdate,
}) => {
- const theme = useAppTheme();
const [isEditorOpen, setIsEditorOpen] = useState(false);
- // Calculate edge path
const [edgePath, labelX, labelY] = getSmoothStepPath({
- sourceX,
- sourceY,
- sourcePosition,
- targetX,
- targetY,
- targetPosition,
+ sourceX, sourceY, sourcePosition,
+ targetX, targetY, targetPosition,
borderRadius: 10,
});
@@ -62,119 +56,65 @@ const ConditionalEdge: React.FC<ConditionalEdgeProps> = ({
setIsEditorOpen(true);
}, []);
- const handleEditorClose = useCallback(() => {
- setIsEditorOpen(false);
- }, []);
+ const handleEditorClose = useCallback(() => setIsEditorOpen(false), []);
const handleConditionSave = useCallback(
(condition: ConditionalEdgeData['condition'], label: string | undefined) => {
- if (onConditionUpdate) {
- onConditionUpdate(id, condition, label);
- }
+ if (onConditionUpdate) onConditionUpdate(id, condition, label);
},
[id, onConditionUpdate]
);
- // Label badge style
- const labelBadgeStyle: React.CSSProperties = {
- position: 'absolute',
- transform: 'translate(-50%, -50%)',
- pointerEvents: 'all',
- cursor: 'pointer',
- padding: `${theme.spacing.xs} ${theme.spacing.sm}`,
- borderRadius: theme.borderRadius.sm,
- fontSize: theme.fontSize.xs,
- fontWeight: theme.fontWeight.medium,
- fontFamily: 'system-ui, sans-serif',
- backgroundColor: hasCondition
- ? `${theme.dracula.cyan}20`
- : theme.colors.backgroundPanel,
- border: `1px solid ${hasCondition ? `${theme.dracula.cyan}60` : theme.colors.border}`,
- color: hasCondition ? theme.dracula.cyan : theme.colors.textSecondary,
- whiteSpace: 'nowrap',
- maxWidth: '150px',
- overflow: 'hidden',
- textOverflow: 'ellipsis',
- boxShadow: selected ? `0 0 6px ${theme.dracula.purple}` : 'none',
- transition: theme.transitions.fast,
- };
-
- // Add condition button (shown when no condition)
- const addButtonStyle: React.CSSProperties = {
- position: 'absolute',
- transform: 'translate(-50%, -50%)',
- pointerEvents: 'all',
- cursor: 'pointer',
- width: '20px',
- height: '20px',
- borderRadius: '50%',
- backgroundColor: theme.colors.backgroundPanel,
- border: `1px dashed ${theme.colors.border}`,
- color: theme.colors.textMuted,
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- fontSize: '14px',
- opacity: selected ? 1 : 0,
- transition: theme.transitions.fast,
- };
-
return (
<>
+ {/* BaseEdge stroke is the React Flow API contract — must be inline. */}
<BaseEdge
id={id}
path={edgePath}
markerEnd={markerEnd}
style={{
...style,
- stroke: hasCondition ? theme.dracula.cyan : undefined,
+ stroke: hasCondition ? 'hsl(var(--accent))' : undefined,
strokeWidth: hasCondition ? 2 : undefined,
strokeDasharray: hasCondition ? '5 3' : undefined,
}}
/>
<EdgeLabelRenderer>
- {/* Condition label or add button */}
+ {/* Position via inline left/top — coords are computed by React Flow. */}
{displayLabel ? (
<div
- style={{
- ...labelBadgeStyle,
- left: labelX,
- top: labelY,
- }}
+ style={{ left: labelX, top: labelY }}
onClick={handleLabelClick}
title={`Click to edit condition: ${displayLabel}`}
+ className={cn(
+ 'pointer-events-auto absolute -translate-x-1/2 -translate-y-1/2 max-w-[150px] cursor-pointer truncate rounded-sm border px-1.5 py-0.5 text-xs font-medium whitespace-nowrap transition-all',
+ hasCondition
+ ? 'border-accent bg-accent/20 text-accent'
+ : 'border-border bg-card text-muted-foreground',
+ selected && 'shadow-[0_0_6px_hsl(var(--node-agent))]'
+ )}
>
- <span style={{ marginRight: '4px' }}>
- <svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
- <path d="M16 3h5v5"/>
- <path d="M8 3H3v5"/>
- <path d="M21 3l-7 7"/>
- <path d="M3 3l7 7"/>
- <path d="M3 21l7-7"/>
- <path d="M21 21l-7-7"/>
- <path d="M16 21h5v-5"/>
- <path d="M8 21H3v-5"/>
- </svg>
+ <span className="mr-1 inline-flex">
+ <Maximize2 className="h-2.5 w-2.5" />
</span>
{displayLabel}
</div>
) : (
<div
- style={{
- ...addButtonStyle,
- left: labelX,
- top: labelY,
- }}
+ style={{ left: labelX, top: labelY }}
onClick={handleLabelClick}
title="Click to add condition"
+ className={cn(
+ 'pointer-events-auto absolute flex h-5 w-5 -translate-x-1/2 -translate-y-1/2 cursor-pointer items-center justify-center rounded-full border border-dashed border-border bg-card text-sm text-muted-foreground transition-opacity',
+ selected ? 'opacity-100' : 'opacity-0'
+ )}
>
+
</div>
)}
</EdgeLabelRenderer>
- {/* Condition Editor Modal */}
<EdgeConditionEditor
isOpen={isEditorOpen}
onClose={handleEditorClose}