import { memo } from "react"; import type { NodeProps, Node } from "@xyflow/react"; import { getLayerColor } from "./LayerLegend"; export interface ContainerNodeData extends Record { containerId: string; name: string; childCount: number; strategy: "folder" | "community"; colorIndex: number; isExpanded: boolean; hasSearchHits: boolean; searchHitCount?: number; isDiffAffected: boolean; isFocusedViaChild: boolean; onToggle: (containerId: string) => void; } export type ContainerFlowNode = Node; function ContainerNodeComponent({ data, width, height }: NodeProps) { const color = getLayerColor(data.colorIndex); const borderColor = data.isDiffAffected ? "var(--color-diff-changed)" : data.isExpanded || data.isFocusedViaChild ? "rgba(212,165,116,0.6)" : "rgba(212,165,116,0.25)"; const borderWidth = data.isExpanded || data.isFocusedViaChild ? 1.5 : 1; const labelDimmed = data.name === "~"; const labelText = labelDimmed ? "(root)" : data.name; const handleToggle = (e: React.SyntheticEvent) => { e.stopPropagation(); data.onToggle(data.containerId); }; return (
{ if (e.key === "Enter" || e.key === " ") { e.preventDefault(); handleToggle(e); } }} >
{data.isExpanded && ▾} {labelText} {data.searchHitCount != null && data.searchHitCount > 0 && ( {data.searchHitCount} hit{data.searchHitCount !== 1 ? "s" : ""} )} {data.childCount}
); } const ContainerNode = memo(ContainerNodeComponent); ContainerNode.displayName = "ContainerNode"; export default ContainerNode;