feat(fields): add option color picker, normalize scopes, and add list type icons

This commit is contained in:
yiling
2026-06-12 11:32:40 +08:00
parent 66f2efd77f
commit 98bf05a616
2 changed files with 97 additions and 19 deletions
+37 -4
View File
@@ -18,11 +18,22 @@ import {
DropdownMenuItem,
DropdownMenuTrigger,
} from '@/ui/components/ui/dropdown-menu'
import { Popover, PopoverContent, PopoverTrigger } from '@/ui/components/ui/popover'
import { Input } from '@/ui/components/ui/input'
import { Label } from '@/ui/components/ui/label'
import { Switch } from '@/ui/components/ui/switch'
import { arrayMove } from '@/ui/lib/dnd-utils'
import { PointerActivationConstraints } from '@dnd-kit/dom'
export const PREDEFINED_COLORS = [
'#ef4444', // Red
'#f97316', // Orange
'#eab308', // Yellow
'#22c55e', // Green
'#3b82f6', // Blue
'#a855f7', // Purple
'#808080', // Gray
]
import {
AlignLeft,
Calendar,
@@ -305,10 +316,32 @@ export function FieldsManager({ projectId, onManageFields, onSave }: FieldsManag
placeholder="Option name"
className="h-8 flex-1"
/>
<div
className="w-6 h-6 rounded-full border shrink-0"
style={{ backgroundColor: opt.color }}
></div>
<Popover>
<PopoverTrigger asChild>
<button
type="button"
className="w-6 h-6 rounded-full border shrink-0 cursor-pointer focus:outline-none hover:scale-105 transition-transform"
style={{ backgroundColor: opt.color || '#808080' }}
/>
</PopoverTrigger>
<PopoverContent className="p-2 w-auto" align="end">
<div className="flex gap-1">
{PREDEFINED_COLORS.map((color) => (
<button
key={color}
type="button"
className="w-5 h-5 rounded-full border cursor-pointer hover:scale-110 transition-transform"
style={{ backgroundColor: color }}
onClick={() => {
const updated = [...newOptions]
updated[idx] = { ...opt, color }
setNewOptions(updated)
}}
/>
))}
</div>
</PopoverContent>
</Popover>
<Button
variant="ghost"
size="icon"
@@ -24,6 +24,8 @@ import {
} from 'lucide-react'
import { useMemo, useState, useEffect } from 'react'
import { toast } from 'sonner'
import { Popover, PopoverTrigger, PopoverContent } from '@/ui/components/ui/popover'
import { FIELD_TYPE_ICONS, PREDEFINED_COLORS } from './fields-manager'
import { Button } from '@/ui/components/ui/button'
import { Dialog, DialogContent, DialogTitle } from '@/ui/components/ui/dialog'
@@ -90,6 +92,8 @@ function SortableFieldRow({
disabled: !isSortable,
})
const Icon = field.config?.type ? FIELD_TYPE_ICONS[field.config.type as FieldType] : null
return (
<div
ref={ref}
@@ -105,9 +109,9 @@ function SortableFieldRow({
</div>
)}
{!isSortable && <div className="w-4" />} {/* Spacer */}
{field.aiAutofill && <Sparkles className="h-4 w-4 text-muted-foreground" />}
{Icon && <Icon className="h-4 w-4 text-muted-foreground shrink-0" />}
{field.aiAutofill && <Sparkles className="h-4 w-4 text-muted-foreground shrink-0" />}
<div className="flex-1 text-sm font-medium truncate">{field.config?.name}</div>
{/* Visual indicator for type or something? */}
</div>
)
}
@@ -209,11 +213,14 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
})
const groups = useMemo(() => {
// Determine available groups from fields or static list
// User said groups are scope field.
const presentScopes = Array.from(new Set(fields.map((f) => f.scope || 'project')))
// Ensure Project is always there for custom fields
if (!presentScopes.includes('project')) presentScopes.push('project')
// Normalize scopes to lowercase to match SCOPE_GROUPS definitions
const presentScopes = Array.from(
new Set(fields.map((f) => (f.scope || SCOPE_GROUPS.PROJECT).toLowerCase())),
)
// Ensure Project group is always present
if (!presentScopes.includes(SCOPE_GROUPS.PROJECT)) {
presentScopes.push(SCOPE_GROUPS.PROJECT)
}
return presentScopes.map((scope) => ({
id: scope,
@@ -223,7 +230,7 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
}, [fields])
const filteredFields = useMemo(() => {
return fields.filter((f) => (f.scope || SCOPE_GROUPS.PROJECT) === selectedGroup)
return fields.filter((f) => (f.scope || SCOPE_GROUPS.PROJECT).toLowerCase() === selectedGroup)
}, [fields, selectedGroup])
const selectedField = useMemo(
@@ -483,10 +490,46 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
})
}}
/>
<div
className="w-6 h-6 rounded-full border"
style={{ backgroundColor: opt.color }}
></div>
<Popover>
<PopoverTrigger asChild>
<button
type="button"
className="w-6 h-6 rounded-full border shrink-0 cursor-pointer focus:outline-none hover:scale-105 transition-transform"
style={{ backgroundColor: opt.color || '#808080' }}
disabled={isReadOnly}
/>
</PopoverTrigger>
{!isReadOnly && (
<PopoverContent className="p-2 w-auto" align="end">
<div className="flex gap-1">
{PREDEFINED_COLORS.map((color) => (
<button
key={color}
type="button"
className="w-5 h-5 rounded-full border cursor-pointer hover:scale-110 transition-transform"
style={{ backgroundColor: color }}
onClick={() => {
const newOpts = [
...((selectedField.config?.type === 'select'
? editConfig.select?.options
: editConfig.selectMulti?.options) || []),
]
newOpts[idx] = { ...opt, color }
setEditConfig({
...editConfig,
[selectedField.config?.type === 'select'
? 'select'
: 'selectMulti']: {
options: newOpts,
},
})
}}
/>
))}
</div>
</PopoverContent>
)}
</Popover>
<Button
variant="ghost"
size="icon"
@@ -564,9 +607,11 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
<span className="font-medium text-sm">
{groups.find((g) => g.id === selectedGroup)?.label}
</span>
<Button size="sm" variant="outline" className="h-8" onClick={handleCreateClick}>
New <Plus className="ml-1 h-3 w-3" />
</Button>
{selectedGroup === SCOPE_GROUPS.PROJECT && (
<Button size="sm" variant="outline" className="h-8" onClick={handleCreateClick}>
New <Plus className="ml-1 h-3 w-3" />
</Button>
)}
</div>
<div className="flex-1 overflow-y-auto p-2 space-y-1">
<DragDropProvider