MCPcopy Create free account
hub / github.com/Roy3838/Observer / SensorDropdownButton

Function SensorDropdownButton

app/src/components/EditAgent/EditAgentModal.tsx:99–159  ·  view source on GitHub ↗
({
  icon: Icon,
  label,
  colorClass,
  agents,
  onSelect
}: {
  icon: React.ElementType;
  label: string;
  colorClass?: string;
  agents: { id: string; name: string }[];
  onSelect: (agentId: string) => void;
})

Source from the content-addressed store, hash-verified

97
98// --- NEW HELPER COMPONENT: Sensor Dropdown Button ---
99const SensorDropdownButton = ({
100 icon: Icon,
101 label,
102 colorClass,
103 agents,
104 onSelect
105}: {
106 icon: React.ElementType;
107 label: string;
108 colorClass?: string;
109 agents: { id: string; name: string }[];
110 onSelect: (agentId: string) => void;
111}) => {
112 const [isOpen, setIsOpen] = useState(false);
113 const dropdownRef = useRef<HTMLDivElement>(null);
114
115 // Close dropdown when clicking outside
116 useEffect(() => {
117 const handleClickOutside = (event: MouseEvent) => {
118 if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {
119 setIsOpen(false);
120 }
121 };
122 if (isOpen) {
123 document.addEventListener('mousedown', handleClickOutside);
124 return () => document.removeEventListener('mousedown', handleClickOutside);
125 }
126 }, [isOpen]);
127
128 if (agents.length === 0) return null;
129
130 return (
131 <div ref={dropdownRef} className="relative flex-grow md:flex-grow-0">
132 <button
133 onClick={() => setIsOpen(!isOpen)}
134 className={`w-full flex items-center justify-center space-x-2 px-3 py-2 bg-gray-100 hover:bg-gray-200 rounded-lg transition-colors ${colorClass || 'text-gray-700'}`}
135 >
136 <Icon className="h-5 w-5" />
137 <span className="text-sm font-medium">{label}</span>
138 <ChevronDown className={`h-4 w-4 transition-transform ${isOpen ? 'rotate-180' : ''}`} />
139 </button>
140
141 {isOpen && (
142 <div className="absolute z-30 mt-1 w-full min-w-[200px] max-h-60 bg-white border border-gray-300 rounded-md shadow-lg overflow-y-auto">
143 {agents.map((agent) => (
144 <button
145 key={agent.id}
146 onClick={() => {
147 onSelect(agent.id);
148 setIsOpen(false);
149 }}
150 className="w-full text-left px-3 py-2 text-sm hover:bg-gray-100 transition-colors"
151 >
152 {agent.name}
153 </button>
154 ))}
155 </div>
156 )}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected