mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-01 13:34:33 +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",
|
"sonner": "2.0.7",
|
||||||
"tailwind-merge": "2.6.1",
|
"tailwind-merge": "2.6.1",
|
||||||
"tailwindcss-animate": "1.0.7",
|
"tailwindcss-animate": "1.0.7",
|
||||||
|
"ulid": "3.0.2",
|
||||||
"use-image": "1.1.4",
|
"use-image": "1.1.4",
|
||||||
"vaul": "1.1.2",
|
"vaul": "1.1.2",
|
||||||
"video.js": "8.23.7",
|
"video.js": "8.23.7",
|
||||||
@@ -280,6 +281,7 @@
|
|||||||
"@temporalio/client": "1.17.2",
|
"@temporalio/client": "1.17.2",
|
||||||
"@temporalio/worker": "1.17.2",
|
"@temporalio/worker": "1.17.2",
|
||||||
"@temporalio/workflow": "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 { client } from '@/ui/api/client'
|
||||||
import { useFieldStore } from '@/ui/stores/fields'
|
import { useFieldStore } from '@/ui/stores/fields'
|
||||||
import { DragDropProvider, KeyboardSensor, PointerSensor, type DragEndEvent } from '@dnd-kit/react'
|
import { DragDropProvider, KeyboardSensor, PointerSensor, type DragEndEvent } from '@dnd-kit/react'
|
||||||
import { useSortable } from '@dnd-kit/react/sortable'
|
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 { InferRequestType, InferResponseType } from 'hono/client'
|
||||||
|
|
||||||
import { Button } from '@/ui/components/ui/button'
|
import { Button } from '@/ui/components/ui/button'
|
||||||
@@ -13,13 +19,86 @@ 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'
|
||||||
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 = {
|
type SortableFieldItemProps = {
|
||||||
field: FieldInfo
|
field: FieldInfo
|
||||||
@@ -33,14 +112,17 @@ function SortableFieldItem({ field, index, onVisibilityChange }: SortableFieldIt
|
|||||||
index,
|
index,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const Icon = field.config?.type ? FIELD_TYPE_ICONS[field.config.type as FieldType] : null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={ref} className="flex items-center justify-between p-2 rounded-md hover:bg-muted">
|
<div ref={ref} className="flex items-center justify-between p-2 rounded-md hover:bg-muted">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<div ref={handleRef} className="cursor-grab">
|
<div ref={handleRef} className="cursor-grab">
|
||||||
<GripVertical className="h-4 w-4 text-muted-foreground" />
|
<GripVertical className="h-4 w-4 text-muted-foreground" />
|
||||||
</div>
|
</div>
|
||||||
{field.aiAutofill && <Sparkles className="h-4 w-4 text-muted-foreground" />}
|
{Icon && <Icon className="h-4 w-4 text-muted-foreground shrink-0" />}
|
||||||
<span className="text-sm">{field.config?.name}</span>
|
{field.aiAutofill && <Sparkles className="h-4 w-4 text-muted-foreground shrink-0" />}
|
||||||
|
<span className="text-sm truncate">{field.config?.name}</span>
|
||||||
</div>
|
</div>
|
||||||
<Switch
|
<Switch
|
||||||
checked={field.visible}
|
checked={field.visible}
|
||||||
@@ -64,6 +146,12 @@ export function FieldsManager({ projectId, onManageFields, onSave }: FieldsManag
|
|||||||
const [newFieldType, setNewFieldType] = useState<FieldType | ''>('')
|
const [newFieldType, setNewFieldType] = useState<FieldType | ''>('')
|
||||||
const [newAiAutofill, setNewAiAutofill] = useState(false)
|
const [newAiAutofill, setNewAiAutofill] = useState(false)
|
||||||
const [newDescription, setNewDescription] = useState('')
|
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 $patchOrder = client.api.projects[':projectId'].fields.order.$patch
|
||||||
const { mutate: updateFieldsOrder } = useMutation<
|
const { mutate: updateFieldsOrder } = useMutation<
|
||||||
@@ -96,6 +184,7 @@ export function FieldsManager({ projectId, onManageFields, onSave }: FieldsManag
|
|||||||
const newFieldsList = [...fields, newField]
|
const newFieldsList = [...fields, newField]
|
||||||
updateFields(newFieldsList)
|
updateFields(newFieldsList)
|
||||||
setNewFieldName('')
|
setNewFieldName('')
|
||||||
|
setNewOptions([])
|
||||||
|
|
||||||
updateFieldsOrder({
|
updateFieldsOrder({
|
||||||
param: { projectId: projectId },
|
param: { projectId: projectId },
|
||||||
@@ -147,12 +236,19 @@ export function FieldsManager({ projectId, onManageFields, onSave }: FieldsManag
|
|||||||
|
|
||||||
const handleCreateField = () => {
|
const handleCreateField = () => {
|
||||||
if (!newFieldName || !newFieldType) return
|
if (!newFieldName || !newFieldType) return
|
||||||
|
const typeConfig =
|
||||||
|
newFieldType === FieldType.select
|
||||||
|
? { select: { options: newOptions } }
|
||||||
|
: newFieldType === FieldType.selectMulti
|
||||||
|
? { selectMulti: { options: newOptions } }
|
||||||
|
: {}
|
||||||
createField({
|
createField({
|
||||||
param: { projectId: projectId },
|
param: { projectId: projectId },
|
||||||
json: {
|
json: {
|
||||||
config: {
|
config: {
|
||||||
name: newFieldName,
|
name: newFieldName,
|
||||||
type: newFieldType,
|
type: newFieldType,
|
||||||
|
...typeConfig,
|
||||||
},
|
},
|
||||||
label: newFieldName,
|
label: newFieldName,
|
||||||
aiAutofill: newAiAutofill,
|
aiAutofill: newAiAutofill,
|
||||||
@@ -195,7 +291,10 @@ export function FieldsManager({ projectId, onManageFields, onSave }: FieldsManag
|
|||||||
{Object.values(FieldType).map((type) => (
|
{Object.values(FieldType).map((type) => (
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
key={type}
|
key={type}
|
||||||
onClick={() => setNewFieldType(type)}
|
onClick={() => {
|
||||||
|
setNewFieldType(type)
|
||||||
|
setNewOptions([])
|
||||||
|
}}
|
||||||
className="capitalize"
|
className="capitalize"
|
||||||
>
|
>
|
||||||
{type.replace(/_/g, ' ')}
|
{type.replace(/_/g, ' ')}
|
||||||
@@ -220,6 +319,84 @@ export function FieldsManager({ projectId, onManageFields, onSave }: FieldsManag
|
|||||||
<Label htmlFor="ai-autofill">AI Autofill</Label>
|
<Label htmlFor="ai-autofill">AI Autofill</Label>
|
||||||
</div>
|
</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">
|
<div className="flex gap-2 pt-2">
|
||||||
<Button
|
<Button
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
@@ -230,6 +407,7 @@ export function FieldsManager({ projectId, onManageFields, onSave }: FieldsManag
|
|||||||
setNewFieldType('')
|
setNewFieldType('')
|
||||||
setNewAiAutofill(false)
|
setNewAiAutofill(false)
|
||||||
setNewDescription('')
|
setNewDescription('')
|
||||||
|
setNewOptions([])
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Cancel
|
Cancel
|
||||||
|
|||||||
@@ -1,28 +1,16 @@
|
|||||||
import type { SelectOption } from '@shumai/dtos'
|
import type { SelectOption } from '@shumai/dtos'
|
||||||
import { ChevronDown, X } from 'lucide-react'
|
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 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 SelectField: React.FC<FieldProps<string>> = ({ value, config, onSave, readOnly }) => {
|
||||||
const selectConfig = config?.select
|
const selectConfig = config?.select
|
||||||
const [isEditing, setIsEditing] = useState(false)
|
const [isEditing, setIsEditing] = useState(false)
|
||||||
const containerRef = useRef<HTMLDivElement>(null)
|
|
||||||
|
|
||||||
const selectedOption = selectConfig?.options?.find((opt: SelectOption) => opt.id === value)
|
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 = () => {
|
const handleStartEdit = () => {
|
||||||
if (!readOnly) {
|
if (!readOnly) {
|
||||||
setIsEditing(true)
|
setIsEditing(true)
|
||||||
@@ -34,15 +22,17 @@ const SelectField: React.FC<FieldProps<string>> = ({ value, config, onSave, read
|
|||||||
setIsEditing(false)
|
setIsEditing(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleOpenChange = (open: boolean) => {
|
||||||
|
if (readOnly) return
|
||||||
|
setIsEditing(open)
|
||||||
|
}
|
||||||
|
|
||||||
const renderOptionBadge = (option: SelectOption | undefined) => {
|
const renderOptionBadge = (option: SelectOption | undefined) => {
|
||||||
if (!option) return <span className="text-gray-400 italic">Select an option</span>
|
if (!option) return <span className="text-gray-400 italic">Select an option</span>
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium"
|
className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium"
|
||||||
style={{
|
style={getOptionStyle(option.color)}
|
||||||
backgroundColor: `${option.color}33`,
|
|
||||||
color: option.color || undefined,
|
|
||||||
}} // 33 is approx 20% opacity hex
|
|
||||||
>
|
>
|
||||||
{option.displayName}
|
{option.displayName}
|
||||||
</span>
|
</span>
|
||||||
@@ -50,21 +40,26 @@ const SelectField: React.FC<FieldProps<string>> = ({ value, config, onSave, read
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative w-full" ref={containerRef}>
|
<div className="relative w-full" onClick={(e) => e.stopPropagation()}>
|
||||||
<div
|
<Popover open={!readOnly && isEditing} onOpenChange={handleOpenChange}>
|
||||||
onClick={handleStartEdit}
|
<PopoverTrigger asChild>
|
||||||
className={`flex items-center justify-between w-full min-h-[28px] px-2 py-1 rounded border border-transparent transition-colors ${
|
<div
|
||||||
!readOnly ? 'cursor-pointer hover:bg-gray-100 hover:border-gray-200 group' : ''
|
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" />
|
{renderOptionBadge(selectedOption)}
|
||||||
)}
|
{!readOnly && (
|
||||||
</div>
|
<ChevronDown className="w-4 h-4 text-gray-400 opacity-0 group-hover:opacity-100" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</PopoverTrigger>
|
||||||
|
|
||||||
{isEditing && (
|
<PopoverContent
|
||||||
<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">
|
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
|
<div
|
||||||
onClick={() => handleSelect('')}
|
onClick={() => handleSelect('')}
|
||||||
className="px-3 py-2 text-sm text-gray-500 hover:bg-gray-50 cursor-pointer flex items-center gap-2"
|
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
|
<span
|
||||||
className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium"
|
className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium"
|
||||||
style={{
|
style={getOptionStyle(option.color)}
|
||||||
backgroundColor: `${option.color}33`,
|
|
||||||
color: option.color || undefined,
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{option.displayName}
|
{option.displayName}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</PopoverContent>
|
||||||
)}
|
</Popover>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import { Check } from 'lucide-react'
|
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 { FieldProps } from './field-types'
|
||||||
import type { SelectOption } from '@shumai/dtos'
|
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[]>> = ({
|
const SelectMultiField: React.FC<FieldProps<string[]>> = ({
|
||||||
value = [],
|
value = [],
|
||||||
@@ -11,7 +13,6 @@ const SelectMultiField: React.FC<FieldProps<string[]>> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const selectConfig = config?.selectMulti
|
const selectConfig = config?.selectMulti
|
||||||
const containerRef = useRef<HTMLDivElement>(null)
|
const containerRef = useRef<HTMLDivElement>(null)
|
||||||
const dropdownRef = useRef<HTMLDivElement>(null)
|
|
||||||
const [isEditing, setIsEditing] = useState(false)
|
const [isEditing, setIsEditing] = useState(false)
|
||||||
const [expanded, setExpanded] = useState(false)
|
const [expanded, setExpanded] = useState(false)
|
||||||
const [visibleCount, setVisibleCount] = useState(value.length)
|
const [visibleCount, setVisibleCount] = useState(value.length)
|
||||||
@@ -63,28 +64,6 @@ const SelectMultiField: React.FC<FieldProps<string[]>> = ({
|
|||||||
}
|
}
|
||||||
}, [selectedOptions, isEditing, expanded, value])
|
}, [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 toggleOption = (optionId: string) => {
|
||||||
const currentVal = value || []
|
const currentVal = value || []
|
||||||
let newVal
|
let newVal
|
||||||
@@ -121,99 +100,99 @@ const SelectMultiField: React.FC<FieldProps<string[]>> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const hiddenCount = selectedOptions.length - visibleCount
|
const hiddenCount = selectedOptions.length - visibleCount
|
||||||
|
const isOpen = (expanded && !isEditing) || isEditing
|
||||||
|
|
||||||
|
const handleOpenChange = (open: boolean) => {
|
||||||
|
if (readOnly) return
|
||||||
|
if (!open) {
|
||||||
|
setExpanded(false)
|
||||||
|
setIsEditing(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative w-full">
|
<div className="relative w-full" onClick={(e) => e.stopPropagation()}>
|
||||||
{/* Placeholder Display Mode */}
|
<Popover open={!readOnly && isOpen} onOpenChange={handleOpenChange}>
|
||||||
<div
|
<PopoverTrigger asChild>
|
||||||
ref={containerRef}
|
{/* Placeholder Display Mode */}
|
||||||
onClick={handlePlaceholderClick}
|
<div
|
||||||
className={`w-full px-1 py-1 flex flex-wrap gap-1 rounded border border-transparent transition-all box-border h-[32px] overflow-hidden ${
|
ref={containerRef}
|
||||||
!readOnly || hiddenCount > 0
|
onClick={handlePlaceholderClick}
|
||||||
? 'cursor-pointer hover:bg-gray-100 hover:border-gray-200'
|
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,
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{option.displayName}
|
{selectedOptions.length === 0 && (
|
||||||
</span>
|
<span className="text-gray-400 text-sm italic px-1 pt-0.5">Empty</span>
|
||||||
))}
|
)}
|
||||||
|
|
||||||
{hiddenCount > 0 && (
|
{/* Render visible items */}
|
||||||
<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]">
|
{selectedOptions.slice(0, visibleCount).map((option: SelectOption) => (
|
||||||
+{hiddenCount}
|
<span
|
||||||
</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
|
|
||||||
key={option.id}
|
key={option.id}
|
||||||
onClick={() => toggleOption(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]"
|
||||||
className="px-3 py-2 hover:bg-gray-50 cursor-pointer flex items-center justify-between"
|
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
|
<span
|
||||||
className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium"
|
key={option.id}
|
||||||
style={{
|
className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium border border-transparent whitespace-nowrap h-[22px]"
|
||||||
backgroundColor: `${option.color}33`,
|
style={getOptionStyle(option.color)}
|
||||||
color: option.color || undefined,
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{option.displayName}
|
{option.displayName}
|
||||||
</span>
|
</span>
|
||||||
{isSelected && <Check className="w-4 h-4 text-blue-500" />}
|
))}
|
||||||
</div>
|
</>
|
||||||
)
|
) : (
|
||||||
})}
|
selectConfig?.options?.map((option: SelectOption) => {
|
||||||
</div>
|
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>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import type { SearchCondition, SearchSort } from '@shumai/dtos'
|
|||||||
import type { ShareLinkInfo } from '@shumai/dtos'
|
import type { ShareLinkInfo } from '@shumai/dtos'
|
||||||
import type { CreateUploadTaskRequest } from '@shumai/dtos'
|
import type { CreateUploadTaskRequest } from '@shumai/dtos'
|
||||||
import { formatSize } from '@/ui/lib/format'
|
import { formatSize } from '@/ui/lib/format'
|
||||||
|
import { ulid } from 'ulid'
|
||||||
import { usePermissions } from '@/ui/hooks/use-permissions'
|
import { usePermissions } from '@/ui/hooks/use-permissions'
|
||||||
import { useFieldStore } from '@/ui/stores/fields'
|
import { useFieldStore } from '@/ui/stores/fields'
|
||||||
import { useUploadStore } from '@/ui/stores/upload'
|
import { useUploadStore } from '@/ui/stores/upload'
|
||||||
@@ -692,7 +693,7 @@ export function FileBrowser({
|
|||||||
const parentDir = {
|
const parentDir = {
|
||||||
name: dir,
|
name: dir,
|
||||||
type: 'folder' as const,
|
type: 'folder' as const,
|
||||||
id: crypto.randomUUID(),
|
id: ulid(),
|
||||||
children: newDir,
|
children: newDir,
|
||||||
size: 0,
|
size: 0,
|
||||||
}
|
}
|
||||||
@@ -703,7 +704,7 @@ export function FileBrowser({
|
|||||||
currentLevel = directories.get(currentPath)!
|
currentLevel = directories.get(currentPath)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const fileWithId = { file, id: crypto.randomUUID() }
|
const fileWithId = { file, id: ulid() }
|
||||||
fileWithIds.push(fileWithId)
|
fileWithIds.push(fileWithId)
|
||||||
currentLevel.push({
|
currentLevel.push({
|
||||||
name: fileName,
|
name: fileName,
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ import type { DragState } from '../dnd-types'
|
|||||||
import FieldRenderer from '../field-renderer'
|
import FieldRenderer from '../field-renderer'
|
||||||
import { FilePreview } from './file-preview'
|
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 {
|
interface FileCardProps {
|
||||||
teamId?: string
|
teamId?: string
|
||||||
@@ -372,21 +373,27 @@ export function FileCard({
|
|||||||
</div>
|
</div>
|
||||||
{fields && fields.length > 0 && (
|
{fields && fields.length > 0 && (
|
||||||
<div className="space-y-2 border-t p-3 mx-2">
|
<div className="space-y-2 border-t p-3 mx-2">
|
||||||
{fields.map((field) => (
|
{fields.map((field) => {
|
||||||
<div key={field.id} className="space-y-1">
|
const Icon = field.config?.type
|
||||||
<label className="text-xs text-muted-foreground tracking-wide">
|
? FIELD_TYPE_ICONS[field.config.type as FieldType]
|
||||||
{field.config?.name}
|
: null
|
||||||
</label>
|
return (
|
||||||
<div className="min-h-[28px]">
|
<div key={field.id} className="space-y-1">
|
||||||
<FieldRenderer
|
<label className="text-xs text-muted-foreground tracking-wide flex items-center gap-1">
|
||||||
config={field.config}
|
{Icon && <Icon className="h-3.5 w-3.5 text-muted-foreground shrink-0" />}
|
||||||
value={itemFieldValueMap[field.id!]?.value}
|
<span>{field.config?.name}</span>
|
||||||
onSave={canEdit ? (val) => onSaveField(field.id!, val) : undefined}
|
</label>
|
||||||
readOnly={field.readOnly || !canEdit}
|
<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>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
import type { AssetInfo } from '@shumai/dtos'
|
import type { AssetInfo } from '@shumai/dtos'
|
||||||
import type { FieldInfo } from '@shumai/dtos'
|
import type { FieldInfo } from '@shumai/dtos'
|
||||||
import type { SearchSort } 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 { useDroppable } from '@dnd-kit/react'
|
||||||
import { flexRender, getCoreRowModel, useReactTable, type ColumnDef } from '@tanstack/react-table'
|
import { flexRender, getCoreRowModel, useReactTable, type ColumnDef } from '@tanstack/react-table'
|
||||||
import { useVirtualizer } from '@tanstack/react-virtual'
|
import { useVirtualizer } from '@tanstack/react-virtual'
|
||||||
@@ -198,9 +200,15 @@ export function FileBrowserListView({
|
|||||||
]
|
]
|
||||||
|
|
||||||
displayedFields.forEach((field) => {
|
displayedFields.forEach((field) => {
|
||||||
|
const Icon = field.config?.type ? FIELD_TYPE_ICONS[field.config.type as FieldType] : null
|
||||||
cols.push({
|
cols.push({
|
||||||
id: field.id,
|
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,
|
size: 150,
|
||||||
minSize: 100,
|
minSize: 100,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ export default function FileSystemManager({
|
|||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const { canEdit } = usePermissions(projectId)
|
const { canEdit } = usePermissions(projectId)
|
||||||
const { loadedProjectId, setFields } = useFieldStore()
|
const { setFields } = useFieldStore()
|
||||||
const $patchMetadata = client.api.files[':fileId'].metadata.$patch
|
const $patchMetadata = client.api.files[':fileId'].metadata.$patch
|
||||||
const { mutate: patchMetadata } = useMutation<
|
const { mutate: patchMetadata } = useMutation<
|
||||||
InferResponseType<typeof $patchMetadata>,
|
InferResponseType<typeof $patchMetadata>,
|
||||||
@@ -75,10 +75,10 @@ export default function FileSystemManager({
|
|||||||
})
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (fields && projectId !== loadedProjectId) {
|
if (fields) {
|
||||||
setFields(fields as unknown as MetadataFieldInfo[], projectId)
|
setFields(fields as unknown as MetadataFieldInfo[], projectId)
|
||||||
}
|
}
|
||||||
}, [fields, projectId, loadedProjectId, setFields])
|
}, [fields, projectId, setFields])
|
||||||
|
|
||||||
const isRecentlyDeleted = assetId === 'recently-deleted'
|
const isRecentlyDeleted = assetId === 'recently-deleted'
|
||||||
const [selectedItem, setSelectedItem] = useState<AssetInfo | null>(null)
|
const [selectedItem, setSelectedItem] = useState<AssetInfo | null>(null)
|
||||||
|
|||||||
@@ -4,8 +4,9 @@ import {
|
|||||||
FieldType,
|
FieldType,
|
||||||
type SelectOption,
|
type SelectOption,
|
||||||
} from '@shumai/dtos'
|
} from '@shumai/dtos'
|
||||||
|
import { ulid } from 'ulid'
|
||||||
import { client } from '@/ui/api/client'
|
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 { InferRequestType, InferResponseType } from 'hono/client'
|
||||||
import { useFieldStore } from '@/ui/stores/fields'
|
import { useFieldStore } from '@/ui/stores/fields'
|
||||||
import { DragDropProvider, KeyboardSensor, PointerSensor, type DragEndEvent } from '@dnd-kit/react'
|
import { DragDropProvider, KeyboardSensor, PointerSensor, type DragEndEvent } from '@dnd-kit/react'
|
||||||
@@ -22,7 +23,10 @@ import {
|
|||||||
Sparkles,
|
Sparkles,
|
||||||
X,
|
X,
|
||||||
} from 'lucide-react'
|
} 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 { Button } from '@/ui/components/ui/button'
|
||||||
import { Dialog, DialogContent, DialogTitle } from '@/ui/components/ui/dialog'
|
import { Dialog, DialogContent, DialogTitle } from '@/ui/components/ui/dialog'
|
||||||
@@ -89,6 +93,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}
|
||||||
@@ -104,9 +110,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>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -117,6 +123,13 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
|
|||||||
const [selectedFieldId, setSelectedFieldId] = useState<string | null>(null)
|
const [selectedFieldId, setSelectedFieldId] = useState<string | null>(null)
|
||||||
const [isCreating, setIsCreating] = useState(false)
|
const [isCreating, setIsCreating] = useState(false)
|
||||||
|
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
useEffect(() => {
|
||||||
|
if (open) {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['fields', projectId] })
|
||||||
|
}
|
||||||
|
}, [open, projectId, queryClient])
|
||||||
|
|
||||||
// Editor State
|
// Editor State
|
||||||
const [editLabel, setEditLabel] = useState('')
|
const [editLabel, setEditLabel] = useState('')
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
@@ -159,6 +172,7 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
|
|||||||
setIsCreating(false)
|
setIsCreating(false)
|
||||||
setSelectedFieldId(data.id!)
|
setSelectedFieldId(data.id!)
|
||||||
resetEditor(data)
|
resetEditor(data)
|
||||||
|
toast.success('Field created successfully')
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
const $put = client.api.fields[':fieldId'].$put
|
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,
|
f.id === data.id ? { ...f, ...(data as MetadataFieldInfo) } : f,
|
||||||
)
|
)
|
||||||
updateFields(newFields)
|
updateFields(newFields)
|
||||||
|
toast.success('Field updated successfully')
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
const $delete = client.api.fields[':fieldId'].$delete
|
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)
|
const newFields = fields.filter((f) => f.id !== variables.param.fieldId)
|
||||||
updateFields(newFields)
|
updateFields(newFields)
|
||||||
setSelectedFieldId(null)
|
setSelectedFieldId(null)
|
||||||
|
toast.success('Field deleted successfully')
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
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,
|
||||||
@@ -211,6 +230,10 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
|
|||||||
}))
|
}))
|
||||||
}, [fields])
|
}, [fields])
|
||||||
|
|
||||||
|
const filteredFields = useMemo(() => {
|
||||||
|
return fields.filter((f) => (f.scope || SCOPE_GROUPS.PROJECT).toLowerCase() === selectedGroup)
|
||||||
|
}, [fields, selectedGroup])
|
||||||
|
|
||||||
const selectedField = useMemo(
|
const selectedField = useMemo(
|
||||||
() => fields.find((f) => f.id === selectedFieldId),
|
() => fields.find((f) => f.id === selectedFieldId),
|
||||||
[fields, selectedFieldId],
|
[fields, selectedFieldId],
|
||||||
@@ -423,7 +446,7 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
// Logic to add option
|
// Logic to add option
|
||||||
const newOption = {
|
const newOption = {
|
||||||
id: crypto.randomUUID(),
|
id: ulid(),
|
||||||
displayName: 'New Option',
|
displayName: 'New Option',
|
||||||
color: '#808080',
|
color: '#808080',
|
||||||
}
|
}
|
||||||
@@ -468,10 +491,49 @@ 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:
|
||||||
|
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
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="icon"
|
size="icon"
|
||||||
@@ -497,7 +559,7 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!isReadOnly && (
|
{!isReadOnly && selectedField.scope?.toLowerCase() !== 'system' && (
|
||||||
<div className="pt-4 flex justify-between">
|
<div className="pt-4 flex justify-between">
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
@@ -544,14 +606,16 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Middle Column: Field List */}
|
{/* 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]">
|
<div className="p-4 border-b flex items-center justify-between bg-background h-[57px]">
|
||||||
<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
|
||||||
@@ -565,7 +629,7 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
|
|||||||
]}
|
]}
|
||||||
onDragEnd={handleDragEnd}
|
onDragEnd={handleDragEnd}
|
||||||
>
|
>
|
||||||
{fields.map((field, index) => (
|
{filteredFields.map((field, index) => (
|
||||||
<SortableFieldRow
|
<SortableFieldRow
|
||||||
key={field.id}
|
key={field.id}
|
||||||
field={field}
|
field={field}
|
||||||
@@ -576,7 +640,7 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
|
|||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</DragDropProvider>
|
</DragDropProvider>
|
||||||
{fields.length === 0 && (
|
{filteredFields.length === 0 && (
|
||||||
<div className="text-center text-muted-foreground text-sm py-8">
|
<div className="text-center text-muted-foreground text-sm py-8">
|
||||||
No fields found
|
No fields found
|
||||||
</div>
|
</div>
|
||||||
@@ -585,7 +649,7 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Right Column: Config */}
|
{/* 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>
|
<div className="flex-1 overflow-y-auto p-6">{renderConfigEditor()}</div>
|
||||||
{(isCreating || (selectedField && !selectedField.readOnly)) && (
|
{(isCreating || (selectedField && !selectedField.readOnly)) && (
|
||||||
<div className="p-4 border-t flex justify-end gap-2 bg-muted/10">
|
<div className="p-4 border-t flex justify-end gap-2 bg-muted/10">
|
||||||
|
|||||||
@@ -82,7 +82,8 @@
|
|||||||
"zod": "4.4.3",
|
"zod": "4.4.3",
|
||||||
"date-fns": "4.4.0",
|
"date-fns": "4.4.0",
|
||||||
"hono": "4.12.23",
|
"hono": "4.12.23",
|
||||||
"@shumai/dtos": "workspace:*"
|
"@shumai/dtos": "workspace:*",
|
||||||
|
"ulid": "3.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tailwindcss/postcss": "4.3.0",
|
"@tailwindcss/postcss": "4.3.0",
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
"@shumai/core": "workspace:*",
|
"@shumai/core": "workspace:*",
|
||||||
"@temporalio/client": "1.17.2",
|
"@temporalio/client": "1.17.2",
|
||||||
"@temporalio/workflow": "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 { prisma, registerWorkflowTrigger, WorkflowTask } from '@shumai/db'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
import { ulid } from 'ulid'
|
||||||
import * as taskActivities from './activities/task'
|
import * as taskActivities from './activities/task'
|
||||||
import { Executor } from './executor'
|
import { Executor } from './executor'
|
||||||
import { LocalExecutor } from './local-executor'
|
import { LocalExecutor } from './local-executor'
|
||||||
@@ -73,8 +74,7 @@ export class WorkflowService {
|
|||||||
const activities = (globalThis as any).__localActivities
|
const activities = (globalThis as any).__localActivities
|
||||||
|
|
||||||
// For agent_queue and transcode_queue, use worker-specific unique queues
|
// For agent_queue and transcode_queue, use worker-specific unique queues
|
||||||
const crypto = await import('crypto')
|
const workerId = ulid()
|
||||||
const workerId = crypto.randomUUID()
|
|
||||||
const workerSpecificQueue = `${queue}-${workerId}`
|
const workerSpecificQueue = `${queue}-${workerId}`
|
||||||
|
|
||||||
console.log(`Starting Temporal workers for domain: ${queue}`)
|
console.log(`Starting Temporal workers for domain: ${queue}`)
|
||||||
|
|||||||
Reference in New Issue
Block a user