import React, { useState, useRef, useEffect } from 'react'; import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@/components/ui/command"; import { PlusCircle, Database, Tag } from "lucide-react"; import { useToast } from "@/hooks/use-toast"; import { useQuery } from '@tanstack/react-query'; import { LdapConnection } from '@shared/schema'; interface VariableSelectorProps { onSelectVariable: (variable: string) => void; connections: number[]; isForOU?: boolean; } // Common LDAP attributes that might be useful as variables const COMMON_ATTRIBUTES = [ { value: 'sAMAccountName', label: 'sAMAccountName', description: 'Account name (username)' }, { value: 'givenName', label: 'givenName', description: 'First name' }, { value: 'sn', label: 'sn', description: 'Last name (surname)' }, { value: 'displayName', label: 'displayName', description: 'Display name' }, { value: 'mail', label: 'mail', description: 'Email address' }, { value: 'department', label: 'department', description: 'Department' }, { value: 'company', label: 'company', description: 'Company' }, { value: 'title', label: 'title', description: 'Job title' }, { value: 'manager', label: 'manager', description: 'Manager DN' }, { value: 'employeeID', label: 'employeeID', description: 'Employee ID' }, { value: 'memberOf', label: 'memberOf', description: 'Group memberships' }, { value: 'objectSid', label: 'objectSid', description: 'Security identifier' }, { value: 'whenCreated', label: 'whenCreated', description: 'Creation date' }, { value: 'physicalDeliveryOfficeName', label: 'physicalDeliveryOfficeName', description: 'Office' }, { value: 'streetAddress', label: 'streetAddress', description: 'Street address' }, { value: 'l', label: 'l', description: 'City' }, { value: 'st', label: 'st', description: 'State/province' }, { value: 'postalCode', label: 'postalCode', description: 'Postal code' }, { value: 'c', label: 'c', description: 'Country code' }, { value: 'telephoneNumber', label: 'telephoneNumber', description: 'Phone number' }, { value: 'mobile', label: 'mobile', description: 'Mobile number' }, { value: 'ipPhone', label: 'ipPhone', description: 'IP phone' }, ]; const VariableSelector: React.FC = ({ onSelectVariable, connections }) => { const [isOpen, setIsOpen] = useState(false); const [customAttribute, setCustomAttribute] = useState(''); const { toast } = useToast(); const inputRef = useRef(null); const handleSelect = (attribute: string) => { onSelectVariable(attribute); setIsOpen(false); }; const handleAddCustomAttribute = () => { if (!customAttribute.trim()) { toast({ title: "Invalid attribute", description: "Please enter an attribute name", variant: "destructive" }); return; } onSelectVariable(customAttribute.trim()); setCustomAttribute(''); setIsOpen(false); }; return ( No attributes found
setCustomAttribute(e.target.value)} placeholder="Enter attribute name" className="flex-1 h-8" />
{COMMON_ATTRIBUTES.map((attribute) => ( handleSelect(attribute.value)} className="flex items-center" >

{attribute.label}

{attribute.description}

))}
); }; export default VariableSelector;