From 5d7ea7d11862516d72e3dd596de436cb0e03062f Mon Sep 17 00:00:00 2001 From: yiling Date: Thu, 18 Jun 2026 23:18:17 +0800 Subject: [PATCH] refactor(webui): use Popover instead of Combobox for search dialog MultiSelect --- .../webui/components/search/filter-panel.tsx | 93 ++++++++++++------- 1 file changed, 61 insertions(+), 32 deletions(-) diff --git a/packages/webui/components/search/filter-panel.tsx b/packages/webui/components/search/filter-panel.tsx index 0c0c8176..ced53217 100644 --- a/packages/webui/components/search/filter-panel.tsx +++ b/packages/webui/components/search/filter-panel.tsx @@ -1,17 +1,7 @@ import { Button } from '@/ui/components/ui/button' -import { - Combobox, - ComboboxChip, - ComboboxChips, - ComboboxChipsInput, - ComboboxContent, - ComboboxEmpty, - ComboboxItem, - ComboboxList, - useComboboxAnchor, -} from '@/ui/components/ui/combobox' import { DebouncedInput } from '@/ui/components/ui/debounced-input' import { Input } from '@/ui/components/ui/input' +import { Popover, PopoverContent, PopoverTrigger } from '@/ui/components/ui/popover' import { Select, SelectContent, @@ -22,7 +12,8 @@ import { import { cn } from '@/ui/lib/utils' import type { SearchCondition, SearchConditionOperator } from '@shumai/dtos' import { type FieldInfo } from '@shumai/dtos' -import { Trash2 } from 'lucide-react' +import { Check, ChevronDown, Trash2 } from 'lucide-react' +import { getOptionStyle } from '../fields-manager' interface FilterPanelProps { fields: FieldInfo[] @@ -322,29 +313,67 @@ function MultiSelectValueInput({ selected: string[] onChange: (val: string[]) => void }) { - const anchorRef = useComboboxAnchor() - const comboboxOptions = options.map((opt) => ({ value: opt.id, label: opt.displayName })) + const selectedOptions = options.filter((opt) => selected.includes(opt.id)) + + const toggleOption = (optionId: string) => { + let newVal + if (selected.includes(optionId)) { + newVal = selected.filter((id) => id !== optionId) + } else { + newVal = [...selected, optionId] + } + onChange(newVal) + } return ( - - - {selected.map((val) => { - const opt = options.find((o) => o.id === val) - return {opt?.displayName || val} + + + + + + {options.map((option) => { + const isSelected = selected.includes(option.id) + return ( +
toggleOption(option.id)} + className="px-3 py-2 hover:bg-accent cursor-pointer flex items-center justify-between rounded-sm" + > + + {option.displayName} + + {isSelected && } +
+ ) })} - -
- - - No options found - {comboboxOptions.map((opt) => ( - - {opt.label} - - ))} - - -
+ + ) }