mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-22 14:38:24 +00:00
Merge pull request #96 from shumaiOne/feat/improve-fields-ui
feat(fields): improve fields popup options, group filter, and dropdown clipping
This commit is contained in:
@@ -248,6 +248,7 @@
|
||||
"sonner": "2.0.7",
|
||||
"tailwind-merge": "2.6.1",
|
||||
"tailwindcss-animate": "1.0.7",
|
||||
"ulid": "3.0.2",
|
||||
"use-image": "1.1.4",
|
||||
"vaul": "1.1.2",
|
||||
"video.js": "8.23.7",
|
||||
@@ -280,6 +281,7 @@
|
||||
"@temporalio/client": "1.17.2",
|
||||
"@temporalio/worker": "1.17.2",
|
||||
"@temporalio/workflow": "1.17.2",
|
||||
"ulid": "3.0.2",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
import { FieldType, type FieldInfo, type FieldInfo as MetadataFieldInfo } from '@shumai/dtos'
|
||||
import {
|
||||
FieldType,
|
||||
type FieldInfo,
|
||||
type FieldInfo as MetadataFieldInfo,
|
||||
type SelectOption,
|
||||
} from '@shumai/dtos'
|
||||
import { ulid } from 'ulid'
|
||||
import { client } from '@/ui/api/client'
|
||||
import { useFieldStore } from '@/ui/stores/fields'
|
||||
import { DragDropProvider, KeyboardSensor, PointerSensor, type DragEndEvent } from '@dnd-kit/react'
|
||||
import { useSortable } from '@dnd-kit/react/sortable'
|
||||
import { useMutation } from '@tanstack/react-query'
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { InferRequestType, InferResponseType } from 'hono/client'
|
||||
|
||||
import { Button } from '@/ui/components/ui/button'
|
||||
@@ -13,13 +19,86 @@ 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'
|
||||
import { ChevronDown, GripVertical, Plus, Search, Settings, Sparkles } from 'lucide-react'
|
||||
import { useMemo, useState } from 'react'
|
||||
|
||||
export const PREDEFINED_COLORS = ['red', 'orange', 'yellow', 'green', 'blue', 'purple', 'gray']
|
||||
|
||||
export const COLOR_MAP: Record<string, { bg: string; text: string; hex: string }> = {
|
||||
red: { bg: 'rgba(239, 68, 68, 0.15)', text: '#ef4444', hex: '#ef4444' },
|
||||
orange: { bg: 'rgba(249, 115, 22, 0.15)', text: '#f97316', hex: '#f97316' },
|
||||
yellow: { bg: 'rgba(234, 179, 8, 0.15)', text: '#ca8a04', hex: '#eab308' },
|
||||
green: { bg: 'rgba(34, 197, 94, 0.15)', text: '#16a34a', hex: '#22c55e' },
|
||||
blue: { bg: 'rgba(59, 130, 246, 0.15)', text: '#2563eb', hex: '#3b82f6' },
|
||||
purple: { bg: 'rgba(168, 85, 247, 0.15)', text: '#9333ea', hex: '#a855f7' },
|
||||
gray: { bg: 'rgba(128, 128, 128, 0.15)', text: '#4b5563', hex: '#808080' },
|
||||
system: { bg: 'rgba(128, 128, 128, 0.1)', text: '#6b7280', hex: '#808080' },
|
||||
}
|
||||
|
||||
export function getOptionStyle(color?: string) {
|
||||
if (!color) {
|
||||
return {
|
||||
backgroundColor: 'rgba(128, 128, 128, 0.1)',
|
||||
color: '#6b7280',
|
||||
}
|
||||
}
|
||||
|
||||
const normalized = color.toLowerCase()
|
||||
const mapped = COLOR_MAP[normalized]
|
||||
if (mapped) {
|
||||
return {
|
||||
backgroundColor: mapped.bg,
|
||||
color: mapped.text,
|
||||
}
|
||||
}
|
||||
|
||||
// Support hex colors (e.g. for existing custom fields)
|
||||
if (color.startsWith('#')) {
|
||||
return {
|
||||
backgroundColor: `${color}33`,
|
||||
color: color,
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback
|
||||
return {
|
||||
backgroundColor: 'rgba(128, 128, 128, 0.1)',
|
||||
color: color,
|
||||
}
|
||||
}
|
||||
import {
|
||||
AlignLeft,
|
||||
Calendar,
|
||||
ChevronDown,
|
||||
GripVertical,
|
||||
Hash,
|
||||
List,
|
||||
Plus,
|
||||
Search,
|
||||
Settings,
|
||||
Sparkles,
|
||||
Star,
|
||||
Tags,
|
||||
ToggleLeft,
|
||||
Type,
|
||||
X,
|
||||
} from 'lucide-react'
|
||||
import { useMemo, useState, useEffect } from 'react'
|
||||
|
||||
export const FIELD_TYPE_ICONS: Record<FieldType, React.ComponentType<{ className?: string }>> = {
|
||||
[FieldType.text]: Type,
|
||||
[FieldType.longText]: AlignLeft,
|
||||
[FieldType.select]: List,
|
||||
[FieldType.selectMulti]: Tags,
|
||||
[FieldType.rating]: Star,
|
||||
[FieldType.number]: Hash,
|
||||
[FieldType.toggle]: ToggleLeft,
|
||||
[FieldType.date]: Calendar,
|
||||
}
|
||||
|
||||
type SortableFieldItemProps = {
|
||||
field: FieldInfo
|
||||
@@ -33,14 +112,17 @@ function SortableFieldItem({ field, index, onVisibilityChange }: SortableFieldIt
|
||||
index,
|
||||
})
|
||||
|
||||
const Icon = field.config?.type ? FIELD_TYPE_ICONS[field.config.type as FieldType] : null
|
||||
|
||||
return (
|
||||
<div ref={ref} className="flex items-center justify-between p-2 rounded-md hover:bg-muted">
|
||||
<div className="flex items-center gap-2">
|
||||
<div ref={handleRef} className="cursor-grab">
|
||||
<GripVertical className="h-4 w-4 text-muted-foreground" />
|
||||
</div>
|
||||
{field.aiAutofill && <Sparkles className="h-4 w-4 text-muted-foreground" />}
|
||||
<span className="text-sm">{field.config?.name}</span>
|
||||
{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" />}
|
||||
<span className="text-sm truncate">{field.config?.name}</span>
|
||||
</div>
|
||||
<Switch
|
||||
checked={field.visible}
|
||||
@@ -64,6 +146,12 @@ export function FieldsManager({ projectId, onManageFields, onSave }: FieldsManag
|
||||
const [newFieldType, setNewFieldType] = useState<FieldType | ''>('')
|
||||
const [newAiAutofill, setNewAiAutofill] = useState(false)
|
||||
const [newDescription, setNewDescription] = useState('')
|
||||
const [newOptions, setNewOptions] = useState<SelectOption[]>([])
|
||||
|
||||
const queryClient = useQueryClient()
|
||||
useEffect(() => {
|
||||
queryClient.invalidateQueries({ queryKey: ['fields', projectId] })
|
||||
}, [projectId, queryClient])
|
||||
|
||||
const $patchOrder = client.api.projects[':projectId'].fields.order.$patch
|
||||
const { mutate: updateFieldsOrder } = useMutation<
|
||||
@@ -96,6 +184,7 @@ export function FieldsManager({ projectId, onManageFields, onSave }: FieldsManag
|
||||
const newFieldsList = [...fields, newField]
|
||||
updateFields(newFieldsList)
|
||||
setNewFieldName('')
|
||||
setNewOptions([])
|
||||
|
||||
updateFieldsOrder({
|
||||
param: { projectId: projectId },
|
||||
@@ -147,12 +236,19 @@ export function FieldsManager({ projectId, onManageFields, onSave }: FieldsManag
|
||||
|
||||
const handleCreateField = () => {
|
||||
if (!newFieldName || !newFieldType) return
|
||||
const typeConfig =
|
||||
newFieldType === FieldType.select
|
||||
? { select: { options: newOptions } }
|
||||
: newFieldType === FieldType.selectMulti
|
||||
? { selectMulti: { options: newOptions } }
|
||||
: {}
|
||||
createField({
|
||||
param: { projectId: projectId },
|
||||
json: {
|
||||
config: {
|
||||
name: newFieldName,
|
||||
type: newFieldType,
|
||||
...typeConfig,
|
||||
},
|
||||
label: newFieldName,
|
||||
aiAutofill: newAiAutofill,
|
||||
@@ -195,7 +291,10 @@ export function FieldsManager({ projectId, onManageFields, onSave }: FieldsManag
|
||||
{Object.values(FieldType).map((type) => (
|
||||
<DropdownMenuItem
|
||||
key={type}
|
||||
onClick={() => setNewFieldType(type)}
|
||||
onClick={() => {
|
||||
setNewFieldType(type)
|
||||
setNewOptions([])
|
||||
}}
|
||||
className="capitalize"
|
||||
>
|
||||
{type.replace(/_/g, ' ')}
|
||||
@@ -220,6 +319,84 @@ export function FieldsManager({ projectId, onManageFields, onSave }: FieldsManag
|
||||
<Label htmlFor="ai-autofill">AI Autofill</Label>
|
||||
</div>
|
||||
|
||||
{(newFieldType === FieldType.select || newFieldType === FieldType.selectMulti) && (
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label className="text-sm font-medium">Options</Label>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-8 px-2"
|
||||
onClick={() => {
|
||||
const newOption: SelectOption = {
|
||||
id: ulid(),
|
||||
displayName: 'New Option',
|
||||
color: '#808080',
|
||||
}
|
||||
setNewOptions([...newOptions, newOption])
|
||||
}}
|
||||
>
|
||||
<Plus className="h-4 w-4 mr-1" /> Add Option
|
||||
</Button>
|
||||
</div>
|
||||
<div className="space-y-2 max-h-40 overflow-y-auto pr-1">
|
||||
{newOptions.map((opt, idx) => (
|
||||
<div key={opt.id} className="flex items-center gap-2">
|
||||
<Input
|
||||
value={opt.displayName}
|
||||
onChange={(e) => {
|
||||
const updated = [...newOptions]
|
||||
updated[idx] = { ...opt, displayName: e.target.value }
|
||||
setNewOptions(updated)
|
||||
}}
|
||||
placeholder="Option name"
|
||||
className="h-8 flex-1"
|
||||
/>
|
||||
<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:
|
||||
COLOR_MAP[opt.color || '']?.hex || 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_MAP[color]?.hex || color }}
|
||||
onClick={() => {
|
||||
const updated = [...newOptions]
|
||||
updated[idx] = { ...opt, color }
|
||||
setNewOptions(updated)
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 shrink-0 text-destructive hover:text-destructive hover:bg-destructive/10"
|
||||
onClick={() => {
|
||||
setNewOptions(newOptions.filter((_, i) => i !== idx))
|
||||
}}
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex gap-2 pt-2">
|
||||
<Button
|
||||
variant="secondary"
|
||||
@@ -230,6 +407,7 @@ export function FieldsManager({ projectId, onManageFields, onSave }: FieldsManag
|
||||
setNewFieldType('')
|
||||
setNewAiAutofill(false)
|
||||
setNewDescription('')
|
||||
setNewOptions([])
|
||||
}}
|
||||
>
|
||||
Cancel
|
||||
|
||||
@@ -1,28 +1,16 @@
|
||||
import type { SelectOption } from '@shumai/dtos'
|
||||
import { ChevronDown, X } from 'lucide-react'
|
||||
import React, { useEffect, useRef, useState } from 'react'
|
||||
import React, { useState } from 'react'
|
||||
import type { FieldProps } from './field-types'
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '@/ui/components/ui/popover'
|
||||
import { getOptionStyle } from '../fields-manager'
|
||||
|
||||
const SelectField: React.FC<FieldProps<string>> = ({ value, config, onSave, readOnly }) => {
|
||||
const selectConfig = config?.select
|
||||
const [isEditing, setIsEditing] = useState(false)
|
||||
const containerRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
const selectedOption = selectConfig?.options?.find((opt: SelectOption) => opt.id === value)
|
||||
|
||||
// Click outside handler
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
if (containerRef.current && !containerRef.current.contains(event.target as Node)) {
|
||||
if (isEditing) {
|
||||
setIsEditing(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
document.addEventListener('mousedown', handleClickOutside)
|
||||
return () => document.removeEventListener('mousedown', handleClickOutside)
|
||||
}, [isEditing])
|
||||
|
||||
const handleStartEdit = () => {
|
||||
if (!readOnly) {
|
||||
setIsEditing(true)
|
||||
@@ -34,15 +22,17 @@ 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 (
|
||||
<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,
|
||||
}} // 33 is approx 20% opacity hex
|
||||
style={getOptionStyle(option.color)}
|
||||
>
|
||||
{option.displayName}
|
||||
</span>
|
||||
@@ -50,21 +40,26 @@ const SelectField: React.FC<FieldProps<string>> = ({ value, config, onSave, read
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative w-full" ref={containerRef}>
|
||||
<div
|
||||
onClick={handleStartEdit}
|
||||
className={`flex items-center justify-between w-full min-h-[28px] px-2 py-1 rounded border border-transparent transition-colors ${
|
||||
!readOnly ? 'cursor-pointer hover:bg-gray-100 hover:border-gray-200 group' : ''
|
||||
}`}
|
||||
>
|
||||
{renderOptionBadge(selectedOption)}
|
||||
{!readOnly && (
|
||||
<ChevronDown className="w-4 h-4 text-gray-400 opacity-0 group-hover:opacity-100" />
|
||||
)}
|
||||
</div>
|
||||
<div className="relative w-full" onClick={(e) => e.stopPropagation()}>
|
||||
<Popover open={!readOnly && isEditing} onOpenChange={handleOpenChange}>
|
||||
<PopoverTrigger asChild>
|
||||
<div
|
||||
onClick={handleStartEdit}
|
||||
className={`flex items-center justify-between w-full min-h-[28px] px-2 py-1 rounded border border-transparent transition-colors ${
|
||||
!readOnly ? 'cursor-pointer hover:bg-gray-100 hover:border-gray-200 group' : ''
|
||||
}`}
|
||||
>
|
||||
{renderOptionBadge(selectedOption)}
|
||||
{!readOnly && (
|
||||
<ChevronDown className="w-4 h-4 text-gray-400 opacity-0 group-hover:opacity-100" />
|
||||
)}
|
||||
</div>
|
||||
</PopoverTrigger>
|
||||
|
||||
{isEditing && (
|
||||
<div className="absolute z-50 top-full left-0 mt-1 w-full min-w-[150px] bg-white border border-gray-200 rounded-lg shadow-lg py-1 max-h-60 overflow-auto">
|
||||
<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"
|
||||
@@ -79,17 +74,14 @@ const SelectField: React.FC<FieldProps<string>> = ({ value, config, onSave, read
|
||||
>
|
||||
<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,
|
||||
}}
|
||||
style={getOptionStyle(option.color)}
|
||||
>
|
||||
{option.displayName}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { Check } from 'lucide-react'
|
||||
import React, { useEffect, useLayoutEffect, useRef, useState } from 'react'
|
||||
import React, { useLayoutEffect, useRef, useState } from 'react'
|
||||
import type { FieldProps } from './field-types'
|
||||
import type { SelectOption } from '@shumai/dtos'
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '@/ui/components/ui/popover'
|
||||
import { getOptionStyle } from '../fields-manager'
|
||||
|
||||
const SelectMultiField: React.FC<FieldProps<string[]>> = ({
|
||||
value = [],
|
||||
@@ -11,7 +13,6 @@ const SelectMultiField: React.FC<FieldProps<string[]>> = ({
|
||||
}) => {
|
||||
const selectConfig = config?.selectMulti
|
||||
const containerRef = useRef<HTMLDivElement>(null)
|
||||
const dropdownRef = useRef<HTMLDivElement>(null)
|
||||
const [isEditing, setIsEditing] = useState(false)
|
||||
const [expanded, setExpanded] = useState(false)
|
||||
const [visibleCount, setVisibleCount] = useState(value.length)
|
||||
@@ -63,28 +64,6 @@ const SelectMultiField: React.FC<FieldProps<string[]>> = ({
|
||||
}
|
||||
}, [selectedOptions, isEditing, expanded, value])
|
||||
|
||||
// Click outside to close dropdown or expanded view
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
// Check if click is outside both the main container and the dropdown
|
||||
const isOutsideDropdown =
|
||||
!dropdownRef.current || !dropdownRef.current.contains(event.target as Node)
|
||||
const isOutsideContainer =
|
||||
!containerRef.current || !containerRef.current.contains(event.target as Node)
|
||||
|
||||
if (isOutsideDropdown && isOutsideContainer) {
|
||||
if (isEditing) {
|
||||
setIsEditing(false)
|
||||
}
|
||||
if (expanded) {
|
||||
setExpanded(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
document.addEventListener('mousedown', handleClickOutside)
|
||||
return () => document.removeEventListener('mousedown', handleClickOutside)
|
||||
}, [isEditing, expanded])
|
||||
|
||||
const toggleOption = (optionId: string) => {
|
||||
const currentVal = value || []
|
||||
let newVal
|
||||
@@ -121,99 +100,99 @@ const SelectMultiField: React.FC<FieldProps<string[]>> = ({
|
||||
}
|
||||
|
||||
const hiddenCount = selectedOptions.length - visibleCount
|
||||
const isOpen = (expanded && !isEditing) || isEditing
|
||||
|
||||
const handleOpenChange = (open: boolean) => {
|
||||
if (readOnly) return
|
||||
if (!open) {
|
||||
setExpanded(false)
|
||||
setIsEditing(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative w-full">
|
||||
{/* Placeholder Display Mode */}
|
||||
<div
|
||||
ref={containerRef}
|
||||
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'
|
||||
: ''
|
||||
}`}
|
||||
>
|
||||
{selectedOptions.length === 0 && (
|
||||
<span className="text-gray-400 text-sm italic px-1 pt-0.5">Empty</span>
|
||||
)}
|
||||
|
||||
{/* Render visible items */}
|
||||
{selectedOptions.slice(0, visibleCount).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,
|
||||
}}
|
||||
<div className="relative w-full" onClick={(e) => e.stopPropagation()}>
|
||||
<Popover open={!readOnly && isOpen} onOpenChange={handleOpenChange}>
|
||||
<PopoverTrigger asChild>
|
||||
{/* Placeholder Display Mode */}
|
||||
<div
|
||||
ref={containerRef}
|
||||
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'
|
||||
: ''
|
||||
}`}
|
||||
>
|
||||
{option.displayName}
|
||||
</span>
|
||||
))}
|
||||
{selectedOptions.length === 0 && (
|
||||
<span className="text-gray-400 text-sm italic px-1 pt-0.5">Empty</span>
|
||||
)}
|
||||
|
||||
{hiddenCount > 0 && (
|
||||
<span className="inline-flex items-center px-1.5 py-0.5 rounded-full text-xs font-medium bg-gray-200 text-gray-600 h-[22px]">
|
||||
+{hiddenCount}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Expanded Overlay Mode */}
|
||||
{expanded && !isEditing && (
|
||||
<div
|
||||
onClick={handleOverlayClick}
|
||||
className={`absolute top-0 left-0 w-full px-1 py-1 flex flex-wrap gap-1 bg-white rounded border border-blue-500 shadow-lg z-50 min-h-[32px] h-auto ${
|
||||
!readOnly ? 'cursor-pointer' : ''
|
||||
}`}
|
||||
>
|
||||
{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>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Edit Mode Dropdown */}
|
||||
{isEditing && (
|
||||
<div
|
||||
ref={dropdownRef}
|
||||
className="absolute z-50 top-full left-0 mt-1 w-64 bg-white border border-gray-200 rounded-lg shadow-xl max-h-60 overflow-auto"
|
||||
>
|
||||
{selectConfig?.options?.map((option: SelectOption) => {
|
||||
const isSelected = (value || []).includes(option.id)
|
||||
return (
|
||||
<div
|
||||
{/* Render visible items */}
|
||||
{selectedOptions.slice(0, visibleCount).map((option: SelectOption) => (
|
||||
<span
|
||||
key={option.id}
|
||||
onClick={() => toggleOption(option.id)}
|
||||
className="px-3 py-2 hover:bg-gray-50 cursor-pointer flex items-center justify-between"
|
||||
className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium border border-transparent whitespace-nowrap h-[22px]"
|
||||
style={getOptionStyle(option.color)}
|
||||
>
|
||||
{option.displayName}
|
||||
</span>
|
||||
))}
|
||||
|
||||
{hiddenCount > 0 && (
|
||||
<span className="inline-flex items-center px-1.5 py-0.5 rounded-full text-xs font-medium bg-gray-200 text-gray-600 h-[22px]">
|
||||
+{hiddenCount}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</PopoverTrigger>
|
||||
|
||||
<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
|
||||
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,
|
||||
}}
|
||||
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={getOptionStyle(option.color)}
|
||||
>
|
||||
{option.displayName}
|
||||
</span>
|
||||
{isSelected && <Check className="w-4 h-4 text-blue-500" />}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
))}
|
||||
</>
|
||||
) : (
|
||||
selectConfig?.options?.map((option: SelectOption) => {
|
||||
const isSelected = (value || []).includes(option.id)
|
||||
return (
|
||||
<div
|
||||
key={option.id}
|
||||
onClick={() => toggleOption(option.id)}
|
||||
className="px-3 py-2 hover:bg-gray-50 cursor-pointer flex items-center justify-between"
|
||||
>
|
||||
<span
|
||||
className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium"
|
||||
style={getOptionStyle(option.color)}
|
||||
>
|
||||
{option.displayName}
|
||||
</span>
|
||||
{isSelected && <Check className="w-4 h-4 text-blue-500" />}
|
||||
</div>
|
||||
)
|
||||
})
|
||||
)}
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import type { SearchCondition, SearchSort } from '@shumai/dtos'
|
||||
import type { ShareLinkInfo } from '@shumai/dtos'
|
||||
import type { CreateUploadTaskRequest } from '@shumai/dtos'
|
||||
import { formatSize } from '@/ui/lib/format'
|
||||
import { ulid } from 'ulid'
|
||||
import { usePermissions } from '@/ui/hooks/use-permissions'
|
||||
import { useFieldStore } from '@/ui/stores/fields'
|
||||
import { useUploadStore } from '@/ui/stores/upload'
|
||||
@@ -692,7 +693,7 @@ export function FileBrowser({
|
||||
const parentDir = {
|
||||
name: dir,
|
||||
type: 'folder' as const,
|
||||
id: crypto.randomUUID(),
|
||||
id: ulid(),
|
||||
children: newDir,
|
||||
size: 0,
|
||||
}
|
||||
@@ -703,7 +704,7 @@ export function FileBrowser({
|
||||
currentLevel = directories.get(currentPath)!
|
||||
}
|
||||
}
|
||||
const fileWithId = { file, id: crypto.randomUUID() }
|
||||
const fileWithId = { file, id: ulid() }
|
||||
fileWithIds.push(fileWithId)
|
||||
currentLevel.push({
|
||||
name: fileName,
|
||||
|
||||
@@ -23,7 +23,8 @@ import type { DragState } from '../dnd-types'
|
||||
import FieldRenderer from '../field-renderer'
|
||||
import { FilePreview } from './file-preview'
|
||||
|
||||
import { type FieldInfo as MetadataFieldInfo } from '@shumai/dtos'
|
||||
import { type FieldInfo as MetadataFieldInfo, FieldType } from '@shumai/dtos'
|
||||
import { FIELD_TYPE_ICONS } from '../fields-manager'
|
||||
|
||||
interface FileCardProps {
|
||||
teamId?: string
|
||||
@@ -372,21 +373,27 @@ export function FileCard({
|
||||
</div>
|
||||
{fields && fields.length > 0 && (
|
||||
<div className="space-y-2 border-t p-3 mx-2">
|
||||
{fields.map((field) => (
|
||||
<div key={field.id} className="space-y-1">
|
||||
<label className="text-xs text-muted-foreground tracking-wide">
|
||||
{field.config?.name}
|
||||
</label>
|
||||
<div className="min-h-[28px]">
|
||||
<FieldRenderer
|
||||
config={field.config}
|
||||
value={itemFieldValueMap[field.id!]?.value}
|
||||
onSave={canEdit ? (val) => onSaveField(field.id!, val) : undefined}
|
||||
readOnly={field.readOnly || !canEdit}
|
||||
/>
|
||||
{fields.map((field) => {
|
||||
const Icon = field.config?.type
|
||||
? FIELD_TYPE_ICONS[field.config.type as FieldType]
|
||||
: null
|
||||
return (
|
||||
<div key={field.id} className="space-y-1">
|
||||
<label className="text-xs text-muted-foreground tracking-wide flex items-center gap-1">
|
||||
{Icon && <Icon className="h-3.5 w-3.5 text-muted-foreground shrink-0" />}
|
||||
<span>{field.config?.name}</span>
|
||||
</label>
|
||||
<div className="min-h-[28px]">
|
||||
<FieldRenderer
|
||||
config={field.config}
|
||||
value={itemFieldValueMap[field.id!]?.value}
|
||||
onSave={canEdit ? (val) => onSaveField(field.id!, val) : undefined}
|
||||
readOnly={field.readOnly || !canEdit}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
import type { AssetInfo } from '@shumai/dtos'
|
||||
import type { FieldInfo } from '@shumai/dtos'
|
||||
import type { SearchSort } from '@shumai/dtos'
|
||||
import { FieldType } from '@shumai/dtos'
|
||||
import { FIELD_TYPE_ICONS } from '../fields-manager'
|
||||
import { useDroppable } from '@dnd-kit/react'
|
||||
import { flexRender, getCoreRowModel, useReactTable, type ColumnDef } from '@tanstack/react-table'
|
||||
import { useVirtualizer } from '@tanstack/react-virtual'
|
||||
@@ -198,9 +200,15 @@ export function FileBrowserListView({
|
||||
]
|
||||
|
||||
displayedFields.forEach((field) => {
|
||||
const Icon = field.config?.type ? FIELD_TYPE_ICONS[field.config.type as FieldType] : null
|
||||
cols.push({
|
||||
id: field.id,
|
||||
header: field.config?.name || field.id,
|
||||
header: () => (
|
||||
<div className="flex items-center gap-1.5 truncate">
|
||||
{Icon && <Icon className="h-3.5 w-3.5 text-muted-foreground shrink-0" />}
|
||||
<span className="truncate">{field.config?.name || field.id}</span>
|
||||
</div>
|
||||
),
|
||||
size: 150,
|
||||
minSize: 100,
|
||||
})
|
||||
|
||||
@@ -48,7 +48,7 @@ export default function FileSystemManager({
|
||||
const navigate = useNavigate()
|
||||
const queryClient = useQueryClient()
|
||||
const { canEdit } = usePermissions(projectId)
|
||||
const { loadedProjectId, setFields } = useFieldStore()
|
||||
const { setFields } = useFieldStore()
|
||||
const $patchMetadata = client.api.files[':fileId'].metadata.$patch
|
||||
const { mutate: patchMetadata } = useMutation<
|
||||
InferResponseType<typeof $patchMetadata>,
|
||||
@@ -75,10 +75,10 @@ export default function FileSystemManager({
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (fields && projectId !== loadedProjectId) {
|
||||
if (fields) {
|
||||
setFields(fields as unknown as MetadataFieldInfo[], projectId)
|
||||
}
|
||||
}, [fields, projectId, loadedProjectId, setFields])
|
||||
}, [fields, projectId, setFields])
|
||||
|
||||
const isRecentlyDeleted = assetId === 'recently-deleted'
|
||||
const [selectedItem, setSelectedItem] = useState<AssetInfo | null>(null)
|
||||
|
||||
@@ -4,8 +4,9 @@ import {
|
||||
FieldType,
|
||||
type SelectOption,
|
||||
} from '@shumai/dtos'
|
||||
import { ulid } from 'ulid'
|
||||
import { client } from '@/ui/api/client'
|
||||
import { useMutation } from '@tanstack/react-query'
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { InferRequestType, InferResponseType } from 'hono/client'
|
||||
import { useFieldStore } from '@/ui/stores/fields'
|
||||
import { DragDropProvider, KeyboardSensor, PointerSensor, type DragEndEvent } from '@dnd-kit/react'
|
||||
@@ -22,7 +23,10 @@ import {
|
||||
Sparkles,
|
||||
X,
|
||||
} from 'lucide-react'
|
||||
import { useMemo, useState } from '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, COLOR_MAP } from './fields-manager'
|
||||
|
||||
import { Button } from '@/ui/components/ui/button'
|
||||
import { Dialog, DialogContent, DialogTitle } from '@/ui/components/ui/dialog'
|
||||
@@ -89,6 +93,8 @@ function SortableFieldRow({
|
||||
disabled: !isSortable,
|
||||
})
|
||||
|
||||
const Icon = field.config?.type ? FIELD_TYPE_ICONS[field.config.type as FieldType] : null
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
@@ -104,9 +110,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>
|
||||
)
|
||||
}
|
||||
@@ -117,6 +123,13 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
|
||||
const [selectedFieldId, setSelectedFieldId] = useState<string | null>(null)
|
||||
const [isCreating, setIsCreating] = useState(false)
|
||||
|
||||
const queryClient = useQueryClient()
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
queryClient.invalidateQueries({ queryKey: ['fields', projectId] })
|
||||
}
|
||||
}, [open, projectId, queryClient])
|
||||
|
||||
// Editor State
|
||||
const [editLabel, setEditLabel] = useState('')
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
@@ -159,6 +172,7 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
|
||||
setIsCreating(false)
|
||||
setSelectedFieldId(data.id!)
|
||||
resetEditor(data)
|
||||
toast.success('Field created successfully')
|
||||
},
|
||||
})
|
||||
const $put = client.api.fields[':fieldId'].$put
|
||||
@@ -177,6 +191,7 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
|
||||
f.id === data.id ? { ...f, ...(data as MetadataFieldInfo) } : f,
|
||||
)
|
||||
updateFields(newFields)
|
||||
toast.success('Field updated successfully')
|
||||
},
|
||||
})
|
||||
const $delete = client.api.fields[':fieldId'].$delete
|
||||
@@ -194,15 +209,19 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
|
||||
const newFields = fields.filter((f) => f.id !== variables.param.fieldId)
|
||||
updateFields(newFields)
|
||||
setSelectedFieldId(null)
|
||||
toast.success('Field deleted successfully')
|
||||
},
|
||||
})
|
||||
|
||||
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,
|
||||
@@ -211,6 +230,10 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
|
||||
}))
|
||||
}, [fields])
|
||||
|
||||
const filteredFields = useMemo(() => {
|
||||
return fields.filter((f) => (f.scope || SCOPE_GROUPS.PROJECT).toLowerCase() === selectedGroup)
|
||||
}, [fields, selectedGroup])
|
||||
|
||||
const selectedField = useMemo(
|
||||
() => fields.find((f) => f.id === selectedFieldId),
|
||||
[fields, selectedFieldId],
|
||||
@@ -423,7 +446,7 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
|
||||
onClick={() => {
|
||||
// Logic to add option
|
||||
const newOption = {
|
||||
id: crypto.randomUUID(),
|
||||
id: ulid(),
|
||||
displayName: 'New Option',
|
||||
color: '#808080',
|
||||
}
|
||||
@@ -468,10 +491,49 @@ 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:
|
||||
COLOR_MAP[opt.color || '']?.hex || 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_MAP[color]?.hex || 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"
|
||||
@@ -497,7 +559,7 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!isReadOnly && (
|
||||
{!isReadOnly && selectedField.scope?.toLowerCase() !== 'system' && (
|
||||
<div className="pt-4 flex justify-between">
|
||||
<Button
|
||||
variant="outline"
|
||||
@@ -544,14 +606,16 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
|
||||
</div>
|
||||
|
||||
{/* Middle Column: Field List */}
|
||||
<div className="w-100 border-r flex flex-col">
|
||||
<div className="w-64 border-r flex flex-col">
|
||||
<div className="p-4 border-b flex items-center justify-between bg-background h-[57px]">
|
||||
<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
|
||||
@@ -565,7 +629,7 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
|
||||
]}
|
||||
onDragEnd={handleDragEnd}
|
||||
>
|
||||
{fields.map((field, index) => (
|
||||
{filteredFields.map((field, index) => (
|
||||
<SortableFieldRow
|
||||
key={field.id}
|
||||
field={field}
|
||||
@@ -576,7 +640,7 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
|
||||
/>
|
||||
))}
|
||||
</DragDropProvider>
|
||||
{fields.length === 0 && (
|
||||
{filteredFields.length === 0 && (
|
||||
<div className="text-center text-muted-foreground text-sm py-8">
|
||||
No fields found
|
||||
</div>
|
||||
@@ -585,7 +649,7 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
|
||||
</div>
|
||||
|
||||
{/* Right Column: Config */}
|
||||
<div className="w-100 bg-background flex flex-col">
|
||||
<div className="flex-1 bg-background flex flex-col">
|
||||
<div className="flex-1 overflow-y-auto p-6">{renderConfigEditor()}</div>
|
||||
{(isCreating || (selectedField && !selectedField.readOnly)) && (
|
||||
<div className="p-4 border-t flex justify-end gap-2 bg-muted/10">
|
||||
|
||||
@@ -82,7 +82,8 @@
|
||||
"zod": "4.4.3",
|
||||
"date-fns": "4.4.0",
|
||||
"hono": "4.12.23",
|
||||
"@shumai/dtos": "workspace:*"
|
||||
"@shumai/dtos": "workspace:*",
|
||||
"ulid": "3.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/postcss": "4.3.0",
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"@shumai/core": "workspace:*",
|
||||
"@temporalio/client": "1.17.2",
|
||||
"@temporalio/workflow": "1.17.2",
|
||||
"@temporalio/worker": "1.17.2"
|
||||
"@temporalio/worker": "1.17.2",
|
||||
"ulid": "3.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { prisma, registerWorkflowTrigger, WorkflowTask } from '@shumai/db'
|
||||
import path from 'path'
|
||||
import { ulid } from 'ulid'
|
||||
import * as taskActivities from './activities/task'
|
||||
import { Executor } from './executor'
|
||||
import { LocalExecutor } from './local-executor'
|
||||
@@ -73,8 +74,7 @@ export class WorkflowService {
|
||||
const activities = (globalThis as any).__localActivities
|
||||
|
||||
// For agent_queue and transcode_queue, use worker-specific unique queues
|
||||
const crypto = await import('crypto')
|
||||
const workerId = crypto.randomUUID()
|
||||
const workerId = ulid()
|
||||
const workerSpecificQueue = `${queue}-${workerId}`
|
||||
|
||||
console.log(`Starting Temporal workers for domain: ${queue}`)
|
||||
|
||||
Reference in New Issue
Block a user