-
Notifications
You must be signed in to change notification settings - Fork 619
webhook multiselect topic #7818
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,13 +10,14 @@ interface SignatureOption { | |
|
|
||
| interface SignatureSelectorProps { | ||
| options: SignatureOption[]; | ||
| value: string; | ||
| onChange: (val: string) => void; | ||
| value: string | string[]; | ||
| onChange: (val: string | string[]) => void; | ||
| setAbi?: (abi: string) => void; | ||
| placeholder?: string; | ||
| disabled?: boolean; | ||
| secondaryTextFormatter?: (sig: SignatureOption) => string; | ||
| className?: string; | ||
| multiSelect?: boolean; | ||
| } | ||
|
|
||
| export function SignatureSelector({ | ||
|
|
@@ -28,6 +29,7 @@ export function SignatureSelector({ | |
| disabled, | ||
| secondaryTextFormatter, | ||
| className, | ||
| multiSelect = false, | ||
| }: SignatureSelectorProps) { | ||
| const [searchValue, setSearchValue] = useState(""); | ||
| const inputRef = useRef<HTMLInputElement>(null); | ||
|
|
@@ -42,38 +44,96 @@ export function SignatureSelector({ | |
| })); | ||
| }, [options, secondaryTextFormatter]); | ||
|
|
||
| // Check if the current value is a custom value (not in options) | ||
| const isCustomValue = value && !options.some((opt) => opt.value === value); | ||
| // Handle both single and multi-select values | ||
| const currentValues = useMemo((): string[] => { | ||
| if (multiSelect) { | ||
| if (Array.isArray(value)) { | ||
| return value.filter( | ||
| (val): val is string => | ||
| val !== undefined && val !== null && val !== "", | ||
| ); | ||
| } else { | ||
| return value ? [value] : []; | ||
| } | ||
| } else { | ||
| if (Array.isArray(value)) { | ||
| return value.length > 0 && value[0] ? [value[0]] : []; | ||
| } else { | ||
| return value ? [value] : []; | ||
| } | ||
| } | ||
| }, [value, multiSelect]); | ||
|
|
||
| // Check if the current values include custom values (not in options) | ||
| const customValues = useMemo((): string[] => { | ||
| return currentValues.filter( | ||
| (val): val is string => | ||
| val !== undefined && | ||
| val !== null && | ||
| val !== "" && | ||
| !options.some((opt) => opt.value === val), | ||
| ); | ||
| }, [currentValues, options]); | ||
|
|
||
| // Add the custom value as an option if needed | ||
| // Add the custom values as options if needed | ||
| const allOptions = useMemo(() => { | ||
| if (isCustomValue && value) { | ||
| return [...formattedOptions, { label: value, value }]; | ||
| } | ||
| return formattedOptions; | ||
| }, [formattedOptions, isCustomValue, value]); | ||
| const customOptions = customValues.map((val) => ({ | ||
| label: val, | ||
| value: val, | ||
| })); | ||
| return [...formattedOptions, ...customOptions]; | ||
| }, [formattedOptions, customValues]); | ||
|
|
||
| // Single-select MultiSelect wrapper | ||
| // Multi-select or single-select MultiSelect wrapper | ||
| const handleSelectedValuesChange = useCallback( | ||
| (selected: string[]) => { | ||
| // Always use the last selected value for single-select behavior | ||
| const selectedValue = | ||
| selected.length > 0 ? (selected[selected.length - 1] ?? "") : ""; | ||
| onChange(selectedValue); | ||
| const found = options.find((opt) => opt.value === selectedValue); | ||
| if (setAbi) { | ||
| setAbi(found?.abi || ""); | ||
| if (multiSelect) { | ||
| // Multi-select behavior | ||
| onChange(selected); | ||
| // For multi-select, we'll use the ABI from the first selected option that has one | ||
| const firstOptionWithAbi = selected.find((selectedValue) => { | ||
| const found = options.find((opt) => opt.value === selectedValue); | ||
| return found?.abi; | ||
| }); | ||
| if (setAbi && firstOptionWithAbi) { | ||
| const found = options.find((opt) => opt.value === firstOptionWithAbi); | ||
| setAbi(found?.abi || ""); | ||
| } | ||
| } else { | ||
| // Single-select behavior (maintain backward compatibility) | ||
| const selectedValue = | ||
| selected.length > 0 ? (selected[selected.length - 1] ?? "") : ""; | ||
| onChange(selectedValue); | ||
| const found = options.find((opt) => opt.value === selectedValue); | ||
| if (setAbi) { | ||
| setAbi(found?.abi || ""); | ||
| } | ||
| } | ||
| setSearchValue(""); | ||
| }, | ||
| [onChange, setAbi, options], | ||
| [onChange, setAbi, options, multiSelect], | ||
| ); | ||
nischitpra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Handle custom value entry | ||
| const handleInputKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => { | ||
| if (event.key === "Enter" && searchValue.trim()) { | ||
| if (!options.some((opt) => opt.value === searchValue.trim())) { | ||
| onChange(searchValue.trim()); | ||
| if (multiSelect) { | ||
| // Add to existing values for multi-select | ||
| const currentArray = Array.isArray(value) | ||
| ? value | ||
| : value | ||
| ? [value] | ||
| : []; | ||
| const filteredArray = currentArray.filter( | ||
| (val): val is string => val !== undefined && val !== null, | ||
| ); | ||
| const newValues = [...filteredArray, searchValue.trim()]; | ||
| onChange(newValues); | ||
| } else { | ||
|
Comment on lines
+123
to
+133
Contributor
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. Also de-duplicate when adding custom values The manual-input path appends 🤖 Prompt for AI Agents |
||
| // Replace value for single-select | ||
| onChange(searchValue.trim()); | ||
| } | ||
| if (setAbi) setAbi(""); | ||
| setSearchValue(""); | ||
| // Optionally blur input | ||
|
|
@@ -106,7 +166,7 @@ export function SignatureSelector({ | |
| customSearchInput={customSearchInput} | ||
| customTrigger={null} | ||
| disabled={disabled} | ||
| maxCount={1} | ||
| maxCount={multiSelect ? 100 : 1} | ||
| onSelectedValuesChange={handleSelectedValuesChange} | ||
| options={allOptions} | ||
| overrideSearchFn={(option, searchTerm) => | ||
|
|
@@ -116,11 +176,13 @@ export function SignatureSelector({ | |
| placeholder={placeholder} | ||
| renderOption={(option) => <span>{option.label}</span>} | ||
| searchPlaceholder={placeholder} | ||
| selectedValues={value ? [value] : []} | ||
| selectedValues={currentValues} | ||
| /> | ||
| {isCustomValue && ( | ||
| {customValues.length > 0 && ( | ||
| <div className="mt-2 rounded border border-warning-200 bg-warning-50 px-2 py-1 text-warning-700 text-xs"> | ||
| You entered a custom signature. Please provide the ABI below. | ||
| {multiSelect | ||
| ? `You entered ${customValues.length} custom signature${customValues.length > 1 ? "s" : ""}. Please provide the ABI below.` | ||
| : "You entered a custom signature. Please provide the ABI below."} | ||
| </div> | ||
| )} | ||
| </div> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.