From 66f2efd77fb6cc1799ba826fb2de3584675ce017 Mon Sep 17 00:00:00 2001 From: yiling Date: Fri, 12 Jun 2026 11:11:00 +0800 Subject: [PATCH] feat(fields): improve fields popup options, group filter, and dropdown clipping --- packages/webui/components/fields-manager.tsx | 120 +++++++++- .../webui/components/fields/select-field.tsx | 92 ++++---- .../components/fields/select-multi-field.tsx | 205 ++++++++---------- .../webui/components/file-system-manager.tsx | 6 +- .../webui/components/manage-fields-dialog.tsx | 23 +- 5 files changed, 274 insertions(+), 172 deletions(-) diff --git a/packages/webui/components/fields-manager.tsx b/packages/webui/components/fields-manager.tsx index 901751c2..dfca6651 100644 --- a/packages/webui/components/fields-manager.tsx +++ b/packages/webui/components/fields-manager.tsx @@ -1,9 +1,14 @@ -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 { 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' @@ -18,8 +23,35 @@ 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' +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.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 +65,17 @@ function SortableFieldItem({ field, index, onVisibilityChange }: SortableFieldIt index, }) + const Icon = field.config?.type ? FIELD_TYPE_ICONS[field.config.type as FieldType] : null + return (
- {field.aiAutofill && } - {field.config?.name} + {Icon && } + {field.aiAutofill && } + {field.config?.name}
('') const [newAiAutofill, setNewAiAutofill] = useState(false) const [newDescription, setNewDescription] = useState('') + const [newOptions, setNewOptions] = useState([]) + + 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 +137,7 @@ export function FieldsManager({ projectId, onManageFields, onSave }: FieldsManag const newFieldsList = [...fields, newField] updateFields(newFieldsList) setNewFieldName('') + setNewOptions([]) updateFieldsOrder({ param: { projectId: projectId }, @@ -147,12 +189,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 +244,10 @@ export function FieldsManager({ projectId, onManageFields, onSave }: FieldsManag {Object.values(FieldType).map((type) => ( setNewFieldType(type)} + onClick={() => { + setNewFieldType(type) + setNewOptions([]) + }} className="capitalize" > {type.replace(/_/g, ' ')} @@ -220,6 +272,59 @@ export function FieldsManager({ projectId, onManageFields, onSave }: FieldsManag
+ {(newFieldType === FieldType.select || newFieldType === FieldType.selectMulti) && ( +
+
+ + +
+
+ {newOptions.map((opt, idx) => ( +
+ { + const updated = [...newOptions] + updated[idx] = { ...opt, displayName: e.target.value } + setNewOptions(updated) + }} + placeholder="Option name" + className="h-8 flex-1" + /> +
+ +
+ ))} +
+
+ )} +