Fully autonomous AI Agents system capable of performing complex penetration testing tasks
Go ai-agentsai-security-toolanthropicautonomous-agentsgolanggptgraphqlmulti-agent-systemoffensive-securityopen-sourceopenaipenetration-testingpenetration-testing-toolsreactsecurity-automationsecurity-testingsecurity-toolsself-hosted
refactor(frontend): inline useControllable into autocomplete.tsx
Sergey Kozyrenko829271e7e4ed
diff --git a/frontend/src/components/ui/autocomplete.tsx b/frontend/src/components/ui/autocomplete.tsxindex 7d48dfbf..799ae1e7 100644--- a/frontend/src/components/ui/autocomplete.tsx+++ b/frontend/src/components/ui/autocomplete.tsx@@ -12,9 +12,39 @@ import {} from '@/components/ui/command';import { Input } from '@/components/ui/input';import { Popover, PopoverAnchor } from '@/components/ui/popover';-import { useControllable } from '@/hooks/use-controllable';+import { useLatestRef } from '@/hooks/use-latest-ref';import { cn } from '@/lib/utils';+/**+ * Radix-style controllable state. When `controlled` is `undefined` the hook+ * owns the state; otherwise the parent does and we forward updates via+ * `onChange`. `onChange` always fires so fully-controlled consumers can+ * observe every set (e.g. for logging).+ *+ * Mirrors `@radix-ui/react-use-controllable-state` without pulling in the+ * dependency for a couple of state slots.+ */+const useControllable = <T,>(controlled: T | undefined, defaultValue: T, onChange?: (value: T) => void) => {+ const [internal, setInternal] = React.useState<T>(defaultValue);+ const isControlled = controlled !== undefined;+ const value = isControlled ? (controlled as T) : internal;++ const onChangeRef = useLatestRef(onChange);++ const set = React.useCallback(+ (next: T) => {+ if (!isControlled) {+ setInternal(next);+ }++ onChangeRef.current?.(next);+ },+ [isControlled, onChangeRef],+ );++ return [value, set] as const;+};+/*** Free-text input with a popover dropdown of substring-filtered suggestions.*diff --git a/frontend/src/hooks/use-controllable.ts b/frontend/src/hooks/use-controllable.tsdeleted file mode 100644index 90279515..00000000--- a/frontend/src/hooks/use-controllable.ts+++ /dev/null@@ -1,33 +0,0 @@-import { useCallback, useState } from 'react';--import { useLatestRef } from '@/hooks/use-latest-ref';--/**- * Radix-style controllable state. When `controlled` is `undefined` the hook- * owns the state; otherwise the parent does and we forward updates via- * `onChange`. `onChange` always fires so fully-controlled consumers can- * observe every set (e.g. for logging).- *- * Mirrors `@radix-ui/react-use-controllable-state` without pulling in the- * dependency for a couple of state slots.- */-export const useControllable = <T>(controlled: T | undefined, defaultValue: T, onChange?: (value: T) => void) => {- const [internal, setInternal] = useState<T>(defaultValue);- const isControlled = controlled !== undefined;- const value = isControlled ? (controlled as T) : internal;-- const onChangeRef = useLatestRef(onChange);-- const set = useCallback(- (next: T) => {- if (!isControlled) {- setInternal(next);- }-- onChangeRef.current?.(next);- },- [isControlled, onChangeRef],- );-- return [value, set] as const;-};