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' : ''}`} >
!excludeFields?.includes(f.id)) @@ -77,6 +79,29 @@ export function FilterPanel({ } } + // Convert value format when switching between single/multi-select operators + if (key === 'operator') { + const field = allFields.find((f) => 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 +157,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,67 +280,141 @@ 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') { + return operator !== 'eq' + } + return false +} + +function MultiSelectValueInput({ + options, + selected, + onChange, +}: { + options: SelectOptionItem[] + selected: string[] + onChange: (val: string[]) => void +}) { + 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 ( + + + + + + {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 && } +
+ ) + })} +
+
+ ) +} 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 (field.type === 'selectMulti' && field.options) { - const selected = Array.isArray(value) ? value : [] - return ( - + {opt.displayName} -
+
))}