mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-24 03:18:40 +00:00
refactor(fields): address popover code review comments on select fields
This commit is contained in:
@@ -21,6 +21,11 @@ const SelectField: React.FC<FieldProps<string>> = ({ value, config, onSave, read
|
||||
setIsEditing(false)
|
||||
}
|
||||
|
||||
const handleOpenChange = (open: boolean) => {
|
||||
if (readOnly) return
|
||||
setIsEditing(open)
|
||||
}
|
||||
|
||||
const renderOptionBadge = (option: SelectOption | undefined) => {
|
||||
if (!option) return <span className="text-gray-400 italic">Select an option</span>
|
||||
return (
|
||||
@@ -37,8 +42,8 @@ const SelectField: React.FC<FieldProps<string>> = ({ value, config, onSave, read
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative w-full">
|
||||
<Popover open={isEditing} onOpenChange={setIsEditing}>
|
||||
<div className="relative w-full" onClick={(e) => e.stopPropagation()}>
|
||||
<Popover open={!readOnly && isEditing} onOpenChange={handleOpenChange}>
|
||||
<PopoverTrigger asChild>
|
||||
<div
|
||||
onClick={handleStartEdit}
|
||||
@@ -53,36 +58,34 @@ const SelectField: React.FC<FieldProps<string>> = ({ value, config, onSave, read
|
||||
</div>
|
||||
</PopoverTrigger>
|
||||
|
||||
{isEditing && (
|
||||
<PopoverContent
|
||||
className="p-1 w-[--radix-popover-trigger-width] min-w-[150px] max-h-60 overflow-auto bg-white border border-gray-200 rounded-lg shadow-lg"
|
||||
align="start"
|
||||
<PopoverContent
|
||||
className="p-1 w-[--radix-popover-trigger-width] min-w-[150px] max-h-60 overflow-auto bg-white border border-gray-200 rounded-lg shadow-lg"
|
||||
align="start"
|
||||
>
|
||||
<div
|
||||
onClick={() => handleSelect('')}
|
||||
className="px-3 py-2 text-sm text-gray-500 hover:bg-gray-50 cursor-pointer flex items-center gap-2"
|
||||
>
|
||||
<X className="w-3 h-3" /> Clear
|
||||
</div>
|
||||
{selectConfig?.options?.map((option: SelectOption) => (
|
||||
<div
|
||||
onClick={() => handleSelect('')}
|
||||
className="px-3 py-2 text-sm text-gray-500 hover:bg-gray-50 cursor-pointer flex items-center gap-2"
|
||||
key={option.id}
|
||||
onClick={() => handleSelect(option.id)}
|
||||
className="px-3 py-2 hover:bg-gray-50 cursor-pointer flex items-center"
|
||||
>
|
||||
<X className="w-3 h-3" /> Clear
|
||||
</div>
|
||||
{selectConfig?.options?.map((option: SelectOption) => (
|
||||
<div
|
||||
key={option.id}
|
||||
onClick={() => handleSelect(option.id)}
|
||||
className="px-3 py-2 hover:bg-gray-50 cursor-pointer flex items-center"
|
||||
<span
|
||||
className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium"
|
||||
style={{
|
||||
backgroundColor: `${option.color}33`,
|
||||
color: option.color || undefined,
|
||||
}}
|
||||
>
|
||||
<span
|
||||
className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium"
|
||||
style={{
|
||||
backgroundColor: `${option.color}33`,
|
||||
color: option.color || undefined,
|
||||
}}
|
||||
>
|
||||
{option.displayName}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</PopoverContent>
|
||||
)}
|
||||
{option.displayName}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -102,6 +102,7 @@ const SelectMultiField: React.FC<FieldProps<string[]>> = ({
|
||||
const isOpen = (expanded && !isEditing) || isEditing
|
||||
|
||||
const handleOpenChange = (open: boolean) => {
|
||||
if (readOnly) return
|
||||
if (!open) {
|
||||
setExpanded(false)
|
||||
setIsEditing(false)
|
||||
@@ -109,8 +110,8 @@ const SelectMultiField: React.FC<FieldProps<string[]>> = ({
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative w-full">
|
||||
<Popover open={isOpen} onOpenChange={handleOpenChange}>
|
||||
<div className="relative w-full" onClick={(e) => e.stopPropagation()}>
|
||||
<Popover open={!readOnly && isOpen} onOpenChange={handleOpenChange}>
|
||||
<PopoverTrigger asChild>
|
||||
{/* Placeholder Display Mode */}
|
||||
<div
|
||||
@@ -148,36 +149,35 @@ const SelectMultiField: React.FC<FieldProps<string[]>> = ({
|
||||
</div>
|
||||
</PopoverTrigger>
|
||||
|
||||
{expanded && !isEditing && (
|
||||
<PopoverContent
|
||||
onClick={handleOverlayClick}
|
||||
className="p-1 w-[--radix-popover-trigger-width] min-w-[200px] flex flex-wrap gap-1 bg-white rounded border border-blue-500 shadow-lg min-h-[32px] h-auto cursor-pointer"
|
||||
align="start"
|
||||
>
|
||||
{selectedOptions.length === 0 && (
|
||||
<span className="text-gray-400 text-sm italic px-1 pt-0.5">Empty</span>
|
||||
)}
|
||||
{selectedOptions.map((option: SelectOption) => (
|
||||
<span
|
||||
key={option.id}
|
||||
className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium border border-transparent whitespace-nowrap h-[22px]"
|
||||
style={{
|
||||
backgroundColor: `${option.color}33`,
|
||||
color: option.color || undefined,
|
||||
}}
|
||||
>
|
||||
{option.displayName}
|
||||
</span>
|
||||
))}
|
||||
</PopoverContent>
|
||||
)}
|
||||
|
||||
{isEditing && (
|
||||
<PopoverContent
|
||||
className="p-1 w-64 bg-white border border-gray-200 rounded-lg shadow-xl max-h-60 overflow-auto"
|
||||
align="start"
|
||||
>
|
||||
{selectConfig?.options?.map((option: SelectOption) => {
|
||||
<PopoverContent
|
||||
className={`p-1 bg-white border rounded-lg shadow-xl max-h-60 overflow-auto ${
|
||||
expanded && !isEditing
|
||||
? 'w-[--radix-popover-trigger-width] min-w-[200px] flex flex-wrap gap-1 border-blue-500 min-h-[32px] h-auto cursor-pointer'
|
||||
: 'w-64 border-gray-200'
|
||||
}`}
|
||||
align="start"
|
||||
onClick={expanded && !isEditing ? handleOverlayClick : undefined}
|
||||
>
|
||||
{expanded && !isEditing ? (
|
||||
<>
|
||||
{selectedOptions.length === 0 && (
|
||||
<span className="text-gray-400 text-sm italic px-1 pt-0.5">Empty</span>
|
||||
)}
|
||||
{selectedOptions.map((option: SelectOption) => (
|
||||
<span
|
||||
key={option.id}
|
||||
className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium border border-transparent whitespace-nowrap h-[22px]"
|
||||
style={{
|
||||
backgroundColor: `${option.color}33`,
|
||||
color: option.color || undefined,
|
||||
}}
|
||||
>
|
||||
{option.displayName}
|
||||
</span>
|
||||
))}
|
||||
</>
|
||||
) : (
|
||||
selectConfig?.options?.map((option: SelectOption) => {
|
||||
const isSelected = (value || []).includes(option.id)
|
||||
return (
|
||||
<div
|
||||
@@ -197,9 +197,9 @@ const SelectMultiField: React.FC<FieldProps<string[]>> = ({
|
||||
{isSelected && <Check className="w-4 h-4 text-blue-500" />}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</PopoverContent>
|
||||
)}
|
||||
})
|
||||
)}
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -377,7 +377,7 @@ export function FileCard({
|
||||
<label className="text-xs text-muted-foreground tracking-wide">
|
||||
{field.config?.name}
|
||||
</label>
|
||||
<div className="min-h-[28px]" onClick={(e) => e.stopPropagation()}>
|
||||
<div className="min-h-[28px]">
|
||||
<FieldRenderer
|
||||
config={field.config}
|
||||
value={itemFieldValueMap[field.id!]?.value}
|
||||
|
||||
@@ -280,7 +280,6 @@ export function FileListItem({
|
||||
width: columnSizing?.[field.id!] || 150,
|
||||
minWidth: columnSizing?.[field.id!] || 150,
|
||||
}}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<FieldRenderer
|
||||
config={field.config}
|
||||
|
||||
Reference in New Issue
Block a user