fix(webui): resolve cmdk filtering issue preventing search history display

- Fix AsyncSelect component where cmdk's internal filtering was hiding search history items
- Change CommandItem value logic: use empty string when searchTerm is empty to match cmdk's filtering behavior
- Ensure search history displays correctly on initial load regardless of current queryLabel value
- Maintain proper selected state indication and all existing functionality
- Preserve normal search behavior when user types in search input

Fixes issue where dropdown only showed "*" and current queryLabel instead of full search history from localStorage.
This commit is contained in:
yangdx 2025-09-20 14:35:41 +08:00
parent da30529585
commit 55b4716bac

View file

@ -248,21 +248,18 @@ export function AsyncSelect<T>({
</CommandEmpty> </CommandEmpty>
))} ))}
<CommandGroup> <CommandGroup>
{options.map((option, index) => { {options.map((option) => {
const optionValue = getOptionValue(option); const optionValue = getOptionValue(option);
// Use index as a safe value that won't be trimmed by cmdk // Fix cmdk filtering issue: use empty string when search is empty
const safeValue = `option-${index}-${optionValue.length}`; // This ensures all items are shown when searchTerm is empty
const itemValue = searchTerm.trim() === '' ? '' : optionValue;
return ( return (
<CommandItem <CommandItem
key={optionValue} key={optionValue}
value={safeValue} value={itemValue}
onSelect={(selectedSafeValue) => { onSelect={() => {
// Extract the original value from the safe value handleSelect(optionValue);
const selectedIndex = parseInt(selectedSafeValue.split('-')[1]);
const originalValue = getOptionValue(options[selectedIndex]);
console.log(`CommandItem onSelect: safeValue='${selectedSafeValue}', originalValue='${originalValue}' (length: ${originalValue.length})`);
handleSelect(originalValue);
}} }}
className="truncate" className="truncate"
> >