mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-05 15:44:28 +00:00
feat(fields): add option color picker, normalize scopes, and add list type icons
This commit is contained in:
@@ -18,11 +18,22 @@ import {
|
|||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from '@/ui/components/ui/dropdown-menu'
|
} from '@/ui/components/ui/dropdown-menu'
|
||||||
|
import { Popover, PopoverContent, PopoverTrigger } from '@/ui/components/ui/popover'
|
||||||
import { Input } from '@/ui/components/ui/input'
|
import { Input } from '@/ui/components/ui/input'
|
||||||
import { Label } from '@/ui/components/ui/label'
|
import { Label } from '@/ui/components/ui/label'
|
||||||
import { Switch } from '@/ui/components/ui/switch'
|
import { Switch } from '@/ui/components/ui/switch'
|
||||||
import { arrayMove } from '@/ui/lib/dnd-utils'
|
import { arrayMove } from '@/ui/lib/dnd-utils'
|
||||||
import { PointerActivationConstraints } from '@dnd-kit/dom'
|
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 {
|
import {
|
||||||
AlignLeft,
|
AlignLeft,
|
||||||
Calendar,
|
Calendar,
|
||||||
@@ -305,10 +316,32 @@ export function FieldsManager({ projectId, onManageFields, onSave }: FieldsManag
|
|||||||
placeholder="Option name"
|
placeholder="Option name"
|
||||||
className="h-8 flex-1"
|
className="h-8 flex-1"
|
||||||
/>
|
/>
|
||||||
<div
|
<Popover>
|
||||||
className="w-6 h-6 rounded-full border shrink-0"
|
<PopoverTrigger asChild>
|
||||||
style={{ backgroundColor: opt.color }}
|
<button
|
||||||
></div>
|
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
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="icon"
|
size="icon"
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ import {
|
|||||||
} from 'lucide-react'
|
} from 'lucide-react'
|
||||||
import { useMemo, useState, useEffect } from 'react'
|
import { useMemo, useState, useEffect } from 'react'
|
||||||
import { toast } from 'sonner'
|
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 { Button } from '@/ui/components/ui/button'
|
||||||
import { Dialog, DialogContent, DialogTitle } from '@/ui/components/ui/dialog'
|
import { Dialog, DialogContent, DialogTitle } from '@/ui/components/ui/dialog'
|
||||||
@@ -90,6 +92,8 @@ function SortableFieldRow({
|
|||||||
disabled: !isSortable,
|
disabled: !isSortable,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const Icon = field.config?.type ? FIELD_TYPE_ICONS[field.config.type as FieldType] : null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={ref}
|
ref={ref}
|
||||||
@@ -105,9 +109,9 @@ function SortableFieldRow({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{!isSortable && <div className="w-4" />} {/* Spacer */}
|
{!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>
|
<div className="flex-1 text-sm font-medium truncate">{field.config?.name}</div>
|
||||||
{/* Visual indicator for type or something? */}
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -209,11 +213,14 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
|
|||||||
})
|
})
|
||||||
|
|
||||||
const groups = useMemo(() => {
|
const groups = useMemo(() => {
|
||||||
// Determine available groups from fields or static list
|
// Normalize scopes to lowercase to match SCOPE_GROUPS definitions
|
||||||
// User said groups are scope field.
|
const presentScopes = Array.from(
|
||||||
const presentScopes = Array.from(new Set(fields.map((f) => f.scope || 'project')))
|
new Set(fields.map((f) => (f.scope || SCOPE_GROUPS.PROJECT).toLowerCase())),
|
||||||
// Ensure Project is always there for custom fields
|
)
|
||||||
if (!presentScopes.includes('project')) presentScopes.push('project')
|
// Ensure Project group is always present
|
||||||
|
if (!presentScopes.includes(SCOPE_GROUPS.PROJECT)) {
|
||||||
|
presentScopes.push(SCOPE_GROUPS.PROJECT)
|
||||||
|
}
|
||||||
|
|
||||||
return presentScopes.map((scope) => ({
|
return presentScopes.map((scope) => ({
|
||||||
id: scope,
|
id: scope,
|
||||||
@@ -223,7 +230,7 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
|
|||||||
}, [fields])
|
}, [fields])
|
||||||
|
|
||||||
const filteredFields = useMemo(() => {
|
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])
|
}, [fields, selectedGroup])
|
||||||
|
|
||||||
const selectedField = useMemo(
|
const selectedField = useMemo(
|
||||||
@@ -483,10 +490,46 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
|
|||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<div
|
<Popover>
|
||||||
className="w-6 h-6 rounded-full border"
|
<PopoverTrigger asChild>
|
||||||
style={{ backgroundColor: opt.color }}
|
<button
|
||||||
></div>
|
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
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="icon"
|
size="icon"
|
||||||
@@ -564,9 +607,11 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
|
|||||||
<span className="font-medium text-sm">
|
<span className="font-medium text-sm">
|
||||||
{groups.find((g) => g.id === selectedGroup)?.label}
|
{groups.find((g) => g.id === selectedGroup)?.label}
|
||||||
</span>
|
</span>
|
||||||
<Button size="sm" variant="outline" className="h-8" onClick={handleCreateClick}>
|
{selectedGroup === SCOPE_GROUPS.PROJECT && (
|
||||||
New <Plus className="ml-1 h-3 w-3" />
|
<Button size="sm" variant="outline" className="h-8" onClick={handleCreateClick}>
|
||||||
</Button>
|
New <Plus className="ml-1 h-3 w-3" />
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="flex-1 overflow-y-auto p-2 space-y-1">
|
<div className="flex-1 overflow-y-auto p-2 space-y-1">
|
||||||
<DragDropProvider
|
<DragDropProvider
|
||||||
|
|||||||
Reference in New Issue
Block a user