From 60d469c91be3597126a9dcbcb92f726bccbdafe5 Mon Sep 17 00:00:00 2001 From: yiling Date: Thu, 18 Jun 2026 23:03:57 +0800 Subject: [PATCH 1/4] fix(webui): use system colors for fields and improve search filter select options --- .../webui/components/fields/date-field.tsx | 38 +++-- .../components/fields/long-text-field.tsx | 12 +- .../webui/components/fields/number-field.tsx | 8 +- .../webui/components/fields/rating-field.tsx | 2 +- .../webui/components/fields/select-field.tsx | 12 +- .../components/fields/select-multi-field.tsx | 18 +-- .../webui/components/fields/text-field.tsx | 8 +- .../webui/components/fields/toggle-field.tsx | 6 +- .../webui/components/search/filter-panel.tsx | 153 +++++++++++++----- 9 files changed, 165 insertions(+), 92 deletions(-) diff --git a/packages/webui/components/fields/date-field.tsx b/packages/webui/components/fields/date-field.tsx index 787e64be..56be93e3 100644 --- a/packages/webui/components/fields/date-field.tsx +++ b/packages/webui/components/fields/date-field.tsx @@ -119,31 +119,35 @@ const DateField: React.FC> = ({ value, config, onSave, readOn if (isEditing) { return (
-
- {value ? getDisplayValue(value) : Select date...} +
+ {value ? ( + getDisplayValue(value) + ) : ( + Select date... + )}
-
+
{/* Date Picker */}
{/* Replaced subMonths with addMonths(-1) */} {format(viewDate, 'MMMM yyyy')}
-
+
{['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'].map((d) => (
{d}
))} @@ -166,8 +170,10 @@ const DateField: React.FC> = ({ value, config, onSave, readOn diff --git a/packages/webui/components/fields/select-field.tsx b/packages/webui/components/fields/select-field.tsx index 42dd8126..347329a9 100644 --- a/packages/webui/components/fields/select-field.tsx +++ b/packages/webui/components/fields/select-field.tsx @@ -28,7 +28,7 @@ const SelectField: React.FC> = ({ value, config, onSave, read } const renderOptionBadge = (option: SelectOption | undefined) => { - if (!option) return Select an option + if (!option) return Select an option return ( > = ({ value, config, onSave, read
{renderOptionBadge(selectedOption)} {!readOnly && ( - + )}
handleSelect('')} - className="px-3 py-2 text-sm text-gray-500 hover:bg-gray-50 cursor-pointer flex items-center gap-2" + className="px-3 py-2 text-sm text-muted-foreground hover:bg-accent cursor-pointer flex items-center gap-2" > Clear
@@ -70,7 +70,7 @@ const SelectField: React.FC> = ({ value, config, onSave, read
handleSelect(option.id)} - className="px-3 py-2 hover:bg-gray-50 cursor-pointer flex items-center" + className="px-3 py-2 hover:bg-accent cursor-pointer flex items-center" > > = ({ onClick={handlePlaceholderClick} className={`w-full px-1 py-1 flex flex-wrap gap-1 rounded border border-transparent transition-all box-border h-[32px] overflow-hidden ${ !readOnly || hiddenCount > 0 - ? 'cursor-pointer hover:bg-gray-100 hover:border-gray-200' + ? 'cursor-pointer hover:bg-accent hover:border-border' : '' }`} > {selectedOptions.length === 0 && ( - Empty + Empty )} {/* Render visible items */} @@ -140,7 +140,7 @@ const SelectMultiField: React.FC> = ({ ))} {hiddenCount > 0 && ( - + +{hiddenCount} )} @@ -148,10 +148,10 @@ const SelectMultiField: React.FC> = ({ > = ({ {expanded && !isEditing ? ( <> {selectedOptions.length === 0 && ( - Empty + Empty )} {selectedOptions.map((option: SelectOption) => ( > = ({
toggleOption(option.id)} - className="px-3 py-2 hover:bg-gray-50 cursor-pointer flex items-center justify-between" + className="px-3 py-2 hover:bg-accent cursor-pointer flex items-center justify-between" > > = ({ > {option.displayName} - {isSelected && } + {isSelected && }
) }) diff --git a/packages/webui/components/fields/text-field.tsx b/packages/webui/components/fields/text-field.tsx index 39e5d726..6ee03481 100644 --- a/packages/webui/components/fields/text-field.tsx +++ b/packages/webui/components/fields/text-field.tsx @@ -43,7 +43,7 @@ const TextField: React.FC> = ({ value, onSave, readOnly }) => onChange={(e) => setLocalValue(e.target.value)} onBlur={handleBlur} onKeyDown={handleKeyDown} - className="w-full px-2 py-1 border border-blue-500 rounded bg-white text-sm outline-none shadow-sm" + className="w-full px-2 py-1 border border-ring rounded bg-background text-sm outline-none shadow-sm" /> ) } @@ -51,11 +51,11 @@ const TextField: React.FC> = ({ value, onSave, readOnly }) => return (
- {value || Empty} + {value || Empty}
) } diff --git a/packages/webui/components/fields/toggle-field.tsx b/packages/webui/components/fields/toggle-field.tsx index 666349b3..68a08158 100644 --- a/packages/webui/components/fields/toggle-field.tsx +++ b/packages/webui/components/fields/toggle-field.tsx @@ -24,12 +24,12 @@ const ToggleField: React.FC = ({ value, onSave, readOnly }) => { className={`flex items-center h-[28px] w-full ${!readOnly ? 'cursor-pointer' : ''}`} >
f.id === newConditions[index].field) + if (field && (field.type === 'select' || field.type === 'selectMulti')) { + const oldOperator = conditions[index].operator + const newOperator = value as SearchConditionOperator + const wasMulti = isMultiSelectOperator(field.type, oldOperator) + const isMulti = isMultiSelectOperator(field.type, newOperator) + + if (wasMulti && !isMulti) { + // Multi -> Single: take first item or empty string + const arr = Array.isArray(newConditions[index].value) + ? (newConditions[index].value as string[]) + : [] + newConditions[index].value = arr[0] || '' + } else if (!wasMulti && isMulti) { + // Single -> Multi: wrap in array if non-empty + const str = newConditions[index].value as string + newConditions[index].value = str ? [str] : [] + } + } + } + onChange(newConditions) } @@ -132,6 +166,7 @@ export function FilterPanel({ {condition.operator !== 'isEmpty' && condition.operator !== 'isNotEmpty' && ( f.id === condition.field)} + operator={condition.operator} value={condition.value} onChange={(val) => handleConditionChange(index, 'value', val)} /> @@ -254,28 +289,97 @@ function getOperators(field: { id: string; label: string; type: string }): { } } -// eslint-disable-next-line @typescript-eslint/no-explicit-any -type FieldType = any +interface SelectOptionItem { + id: string + displayName: string + color?: string +} + +interface FilterField { + id: string + label: string + type: string + options?: SelectOptionItem[] +} + +function isMultiSelectOperator(fieldType: string, operator: SearchConditionOperator): boolean { + if (fieldType === 'select') { + return operator === 'in' || operator === 'notIn' + } + if (fieldType === 'selectMulti') { + // All selectMulti operators that take values are multi-select + return true + } + return false +} + +function MultiSelectValueInput({ + options, + selected, + onChange, +}: { + options: SelectOptionItem[] + selected: string[] + onChange: (val: string[]) => void +}) { + const anchorRef = useComboboxAnchor() + const comboboxOptions = options.map((opt) => ({ value: opt.id, label: opt.displayName })) + + return ( + + + {selected.map((val) => { + const opt = options.find((o) => o.id === val) + return {opt?.displayName || val} + })} + + + + + No options found + {comboboxOptions.map((opt) => ( + + {opt.label} + + ))} + + + + ) +} function ConditionValueInput({ field, + operator, value, onChange, }: { - field: FieldType + field: FilterField | undefined + operator: SearchConditionOperator value: unknown onChange: (val: unknown) => void }) { if (!field) return - if (field.type === 'select' && field.options) { + if ((field.type === 'select' || field.type === 'selectMulti') && field.options) { + if (isMultiSelectOperator(field.type, operator)) { + const selected = Array.isArray(value) ? (value as string[]) : [] + return ( + onChange(val)} + /> + ) + } + // Single-select return ( { - if (selected.includes(val)) { - onChange(selected.filter((v) => v !== val)) - } else { - onChange([...selected, val]) - } - }} - > - - 0 ? `${selected.length} selected` : 'Select options'} - /> - - - {field.options.map((opt: FieldType) => ( - -
- - {opt.displayName} -
-
- ))} -
- - ) - } - if (field.type === 'date') { const relativeDates = [ { value: 'today', label: 'Today' }, From 5065346e8ac99549e553263566590dff045c3049 Mon Sep 17 00:00:00 2001 From: yiling Date: Thu, 18 Jun 2026 23:13:51 +0800 Subject: [PATCH 2/4] fix(webui): support fallback options for selectMulti fields in filter panel --- packages/webui/components/search/filter-panel.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/webui/components/search/filter-panel.tsx b/packages/webui/components/search/filter-panel.tsx index 3e0ef6c6..0c0c8176 100644 --- a/packages/webui/components/search/filter-panel.tsx +++ b/packages/webui/components/search/filter-panel.tsx @@ -1,8 +1,4 @@ -import type { SearchCondition, SearchConditionOperator } from '@shumai/dtos' -import { type FieldInfo } from '@shumai/dtos' import { Button } from '@/ui/components/ui/button' -import { DebouncedInput } from '@/ui/components/ui/debounced-input' -import { Input } from '@/ui/components/ui/input' import { Combobox, ComboboxChip, @@ -14,6 +10,8 @@ import { ComboboxList, useComboboxAnchor, } from '@/ui/components/ui/combobox' +import { DebouncedInput } from '@/ui/components/ui/debounced-input' +import { Input } from '@/ui/components/ui/input' import { Select, SelectContent, @@ -22,6 +20,8 @@ import { SelectValue, } from '@/ui/components/ui/select' import { cn } from '@/ui/lib/utils' +import type { SearchCondition, SearchConditionOperator } from '@shumai/dtos' +import { type FieldInfo } from '@shumai/dtos' import { Trash2 } from 'lucide-react' interface FilterPanelProps { @@ -54,7 +54,7 @@ export function FilterPanel({ id: f.id!, label: f.config?.name || f.description || 'Unknown', type: getFieldType(f), - options: f.config?.select?.options, + options: f.config?.select?.options || f.config?.selectMulti?.options, })), ].filter((f) => !excludeFields?.includes(f.id)) From 5d7ea7d11862516d72e3dd596de436cb0e03062f Mon Sep 17 00:00:00 2001 From: yiling Date: Thu, 18 Jun 2026 23:18:17 +0800 Subject: [PATCH 3/4] 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} - - ))} - - -
+ + ) } From 46c975836add607991917282248c72b237f64ba6 Mon Sep 17 00:00:00 2001 From: yiling Date: Thu, 18 Jun 2026 23:22:36 +0800 Subject: [PATCH 4/4] fix(webui): render selectMulti 'is exactly' operator as single-select --- packages/webui/components/search/filter-panel.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/webui/components/search/filter-panel.tsx b/packages/webui/components/search/filter-panel.tsx index ced53217..5d51427d 100644 --- a/packages/webui/components/search/filter-panel.tsx +++ b/packages/webui/components/search/filter-panel.tsx @@ -298,8 +298,7 @@ function isMultiSelectOperator(fieldType: string, operator: SearchConditionOpera return operator === 'in' || operator === 'notIn' } if (fieldType === 'selectMulti') { - // All selectMulti operators that take values are multi-select - return true + return operator !== 'eq' } return false } @@ -410,7 +409,12 @@ function ConditionValueInput({ {field.options.map((opt) => ( - {opt.displayName} + + {opt.displayName} + ))}