-
Notifications
You must be signed in to change notification settings - Fork 4
ENG-1378 automatic source appending for evd incorrectly pre pends #788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,10 @@ | ||
| import React, { useState, useCallback, useMemo, useRef, useEffect } from "react"; | ||
| import React, { | ||
| useState, | ||
| useCallback, | ||
| useMemo, | ||
| useRef, | ||
| useEffect, | ||
| } from "react"; | ||
| import { | ||
| Button, | ||
| TextArea, | ||
|
|
@@ -14,27 +20,22 @@ import { Result } from "~/utils/types"; | |
| type FuzzySelectInputProps<T extends Result = Result> = { | ||
| value?: T; | ||
| setValue: (q: T) => void; | ||
| onLockedChange?: (isLocked: boolean) => void; | ||
| mode: "create" | "edit"; | ||
| initialUid: string; | ||
| options?: T[]; | ||
| placeholder?: string; | ||
| autoFocus?: boolean; | ||
| initialIsLocked?: boolean; | ||
| isLocked: boolean; | ||
| }; | ||
|
|
||
| const FuzzySelectInput = <T extends Result = Result>({ | ||
| value, | ||
| setValue, | ||
| onLockedChange, | ||
| mode, | ||
| initialUid, | ||
| options = [], | ||
| placeholder = "Enter value", | ||
| autoFocus, | ||
| initialIsLocked, | ||
| isLocked, | ||
| }: FuzzySelectInputProps<T>) => { | ||
| const [isLocked, setIsLocked] = useState(initialIsLocked || false); | ||
| const [query, setQuery] = useState<string>(() => value?.text || ""); | ||
| const [isOpen, setIsOpen] = useState(false); | ||
| const [activeIndex, setActiveIndex] = useState(0); | ||
|
|
@@ -52,28 +53,31 @@ const FuzzySelectInput = <T extends Result = Result>({ | |
|
|
||
| const handleSelect = useCallback( | ||
| (item: T) => { | ||
| if (mode === "create" && item.uid && item.uid !== initialUid) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I think we need another variable to detect if we're creating nodes in canvas.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch. Re-added |
||
| setIsLocked(true); | ||
| setQuery(item.text); | ||
| setValue(item); | ||
| setIsOpen(false); | ||
| onLockedChange?.(true); | ||
| } else { | ||
| setQuery(item.text); | ||
| setValue(item); | ||
| setIsOpen(false); | ||
| setQuery(item.text); | ||
| setValue(item); | ||
| setIsOpen(false); | ||
|
|
||
| if (!(mode === "create" && item.uid)) { | ||
| requestAnimationFrame(() => inputRef.current?.focus()); | ||
| } | ||
| }, | ||
| [mode, initialUid, setValue, onLockedChange], | ||
| [mode, setValue], | ||
| ); | ||
|
|
||
| const handleClear = useCallback(() => { | ||
| setIsLocked(false); | ||
| setQuery(""); | ||
| setValue({ ...value, text: "", uid: "" } as T); | ||
| onLockedChange?.(false); | ||
| }, [value, setValue, onLockedChange]); | ||
| }, [value, setValue]); | ||
|
|
||
| const handleInputChange = useCallback( | ||
| (text: string) => { | ||
| setQuery(text); | ||
| if (mode === "create" && !isLocked) { | ||
| setValue({ text, uid: "" } as T); | ||
| } | ||
| }, | ||
| [mode, isLocked, setValue], | ||
| ); | ||
|
|
||
| const handleKeyDown = useCallback( | ||
| (e: React.KeyboardEvent<HTMLInputElement>) => { | ||
|
|
@@ -100,10 +104,9 @@ const FuzzySelectInput = <T extends Result = Result>({ | |
| ); | ||
|
|
||
| useEffect(() => { | ||
| if (mode === "create" && !isLocked) { | ||
| setValue({ text: query, uid: "" } as T); | ||
| } | ||
| }, [query, mode, isLocked, setValue]); | ||
| if (isLocked) return; | ||
| setQuery(value?.text ?? ""); | ||
| }, [isLocked, value?.text]); | ||
|
|
||
| useEffect(() => { | ||
| if (isFocused && filteredItems.length > 0 && query) { | ||
|
|
@@ -206,7 +209,7 @@ const FuzzySelectInput = <T extends Result = Result>({ | |
| inputRef={inputRef} | ||
| className="w-full" | ||
| value={query} | ||
| onChange={(e) => setQuery(e.target.value)} | ||
| onChange={(e) => handleInputChange(e.target.value)} | ||
| onKeyDown={handleKeyDown} | ||
| autoFocus={autoFocus} | ||
| placeholder={placeholder} | ||
|
|
@@ -223,4 +226,4 @@ const FuzzySelectInput = <T extends Result = Result>({ | |
| ); | ||
| }; | ||
|
|
||
| export default FuzzySelectInput; | ||
| export default FuzzySelectInput; | ||

Uh oh!
There was an error while loading. Please reload this page.