mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-06 08:04:37 +00:00
feat(webui): use Shadcn Switch in toggle field and Rating component in search filter panel
This commit is contained in:
@@ -14,6 +14,7 @@ import type { SearchCondition, SearchConditionOperator } from '@shumai/dtos'
|
||||
import { type FieldInfo } from '@shumai/dtos'
|
||||
import { Check, ChevronDown, Trash2 } from 'lucide-react'
|
||||
import { getOptionStyle } from '../fields-manager'
|
||||
import RatingField from '../fields/rating-field'
|
||||
|
||||
interface FilterPanelProps {
|
||||
fields: FieldInfo[]
|
||||
@@ -46,6 +47,7 @@ export function FilterPanel({
|
||||
label: f.config?.name || f.description || 'Unknown',
|
||||
type: getFieldType(f),
|
||||
options: f.config?.select?.options || f.config?.selectMulti?.options,
|
||||
config: f.config,
|
||||
})),
|
||||
].filter((f) => !excludeFields?.includes(f.id))
|
||||
|
||||
@@ -189,7 +191,7 @@ function getFieldType(field: FieldInfo): string {
|
||||
if (field.config?.type === 'selectMulti') return 'selectMulti'
|
||||
if (field.config?.type === 'number') return 'number'
|
||||
if (field.config?.type === 'date') return 'date'
|
||||
if (field.config?.type === 'rating') return 'number'
|
||||
if (field.config?.type === 'rating') return 'rating'
|
||||
if (field.config?.type === 'toggle') return 'toggle'
|
||||
return 'text'
|
||||
}
|
||||
@@ -199,6 +201,7 @@ function getDefaultOperator(type: string): SearchConditionOperator {
|
||||
case 'selectMulti':
|
||||
return 'hasAny' as SearchConditionOperator
|
||||
case 'number':
|
||||
case 'rating':
|
||||
case 'date':
|
||||
return 'eq'
|
||||
default:
|
||||
@@ -233,6 +236,7 @@ function getOperators(field: { id: string; label: string; type: string }): {
|
||||
{ value: 'isNotEmpty' as SearchConditionOperator, label: 'is not empty' },
|
||||
]
|
||||
case 'number':
|
||||
case 'rating':
|
||||
return [
|
||||
{ value: 'eq' as SearchConditionOperator, label: '=' },
|
||||
{ value: 'neq' as SearchConditionOperator, label: '≠' },
|
||||
@@ -291,6 +295,7 @@ interface FilterField {
|
||||
label: string
|
||||
type: string
|
||||
options?: SelectOptionItem[]
|
||||
config?: FieldInfo['config']
|
||||
}
|
||||
|
||||
function isMultiSelectOperator(fieldType: string, operator: SearchConditionOperator): boolean {
|
||||
@@ -478,6 +483,16 @@ function ConditionValueInput({
|
||||
)
|
||||
}
|
||||
|
||||
if (field.type === 'rating') {
|
||||
return (
|
||||
<RatingField
|
||||
value={Number(value) || 0}
|
||||
config={field.config || { name: field.label, type: 'rating' }}
|
||||
onSave={onChange}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
if (field.type === 'toggle') {
|
||||
return (
|
||||
<Select
|
||||
|
||||
Reference in New Issue
Block a user