From b568eac77d847792f00e861f90637d947ed3226c Mon Sep 17 00:00:00 2001 From: yiling Date: Wed, 5 Aug 2026 14:44:30 +0800 Subject: [PATCH 1/2] feat(webui): render select options in field creation mode and pick random option color --- .../file/audio-timestamp-comment.spec.ts | 5 +- .../e2e/tests/file/txt-draw-comment.spec.ts | 10 +- packages/agent/src/activities/agent.test.ts | 4 +- packages/agent/src/activities/agent.ts | 14 +-- packages/webui/components/fields-manager.tsx | 11 +- .../webui/components/manage-fields-dialog.tsx | 107 ++++++++++++++++-- packages/webui/messages/en.json | 2 +- packages/webui/messages/zh.json | 2 +- .../description_optional_placeholder.d.ts | 2 +- .../description_optional_placeholder.js | 6 +- 10 files changed, 129 insertions(+), 34 deletions(-) diff --git a/apps/web/e2e/tests/file/audio-timestamp-comment.spec.ts b/apps/web/e2e/tests/file/audio-timestamp-comment.spec.ts index b79dcc34..65e8e9a9 100644 --- a/apps/web/e2e/tests/file/audio-timestamp-comment.spec.ts +++ b/apps/web/e2e/tests/file/audio-timestamp-comment.spec.ts @@ -2,10 +2,7 @@ import { expect, test } from '../../fixtures' test.use({ fileOptions: { mediaType: 'audio' } }) -test('upload an audio file, create a comment at a non-zero timestamp', async ({ - file, - prisma, -}) => { +test('upload an audio file, create a comment at a non-zero timestamp', async ({ file, prisma }) => { const { page, projectId, fileId } = file const commentText = `Audio timestamp comment ${Date.now()}` diff --git a/apps/web/e2e/tests/file/txt-draw-comment.spec.ts b/apps/web/e2e/tests/file/txt-draw-comment.spec.ts index fddcf46a..a0ed4dbb 100644 --- a/apps/web/e2e/tests/file/txt-draw-comment.spec.ts +++ b/apps/web/e2e/tests/file/txt-draw-comment.spec.ts @@ -20,11 +20,11 @@ test('upload a txt file, create a comment with draw', async ({ file, prisma }) = await page.goto(`/projects/${projectId}/files/${fileId}`) // Verify PDF viewer container or page is loaded - await expect( - page.locator('.pdf-viewer, canvas, [data-testid="pdf-viewer"]').first(), - ).toBeVisible({ - timeout: 30_000, - }) + await expect(page.locator('.pdf-viewer, canvas, [data-testid="pdf-viewer"]').first()).toBeVisible( + { + timeout: 30_000, + }, + ) // Toggle drawing mode const drawToggleBtn = page.getByTitle('Toggle Annotation') diff --git a/packages/agent/src/activities/agent.test.ts b/packages/agent/src/activities/agent.test.ts index 0da29dce..39a30b56 100644 --- a/packages/agent/src/activities/agent.test.ts +++ b/packages/agent/src/activities/agent.test.ts @@ -1731,9 +1731,7 @@ describe('Agent Database Activities Integration', () => { expect(source?.type).toBe('select') expect(source?.description).toBe('Generation source') expect(source?.options).toEqual([{ displayName: 'Gemini' }, { displayName: 'Seedance' }]) - expect( - res.fields.find((f: { name: string }) => f.name === 'Manual Notes'), - ).toBeUndefined() + expect(res.fields.find((f: { name: string }) => f.name === 'Manual Notes')).toBeUndefined() }) it('should resolve the project through the ancestor chain', async () => { diff --git a/packages/agent/src/activities/agent.ts b/packages/agent/src/activities/agent.ts index da2770d5..d95f3ceb 100644 --- a/packages/agent/src/activities/agent.ts +++ b/packages/agent/src/activities/agent.ts @@ -1,7 +1,7 @@ import { - type AgentMessage, - type AgentTool, - type SessionTreeEntry, + type AgentMessage, + type AgentTool, + type SessionTreeEntry, } from '@earendil-works/pi-agent-core' import { type ImageContent } from '@earendil-works/pi-ai' import { assetService } from '@shumai/core/src/asset/asset' @@ -19,10 +19,10 @@ import { generateKeyBetween } from 'jittered-fractional-indexing' import { ulid } from 'ulid' import { DatabaseSessionStorage } from '../database-session-storage' import { - createAgentSession, - fieldsToTypeBoxSchema, - type AutofillField, - type DbProviderInfo, + createAgentSession, + fieldsToTypeBoxSchema, + type AutofillField, + type DbProviderInfo, } from '../index' import { aiUsageService } from '@shumai/core/src/ai-usage/ai-usage' diff --git a/packages/webui/components/fields-manager.tsx b/packages/webui/components/fields-manager.tsx index 386cfa94..bd4433e7 100644 --- a/packages/webui/components/fields-manager.tsx +++ b/packages/webui/components/fields-manager.tsx @@ -71,6 +71,15 @@ export function getOptionStyle(color?: string) { color: color, } } + +export function getRandomUnusedColor(existingOptions: SelectOption[] = []): string { + const usedColors = new Set(existingOptions.map((o) => o.color?.toLowerCase()).filter(Boolean)) + const available = PREDEFINED_COLORS.filter((color) => !usedColors.has(color.toLowerCase())) + if (available.length > 0) { + return available[Math.floor(Math.random() * available.length)] + } + return PREDEFINED_COLORS[Math.floor(Math.random() * PREDEFINED_COLORS.length)] +} import { AlignLeft, Calendar, @@ -338,7 +347,7 @@ export function FieldsManager({ projectId, onManageFields, onSave }: FieldsManag const newOption: SelectOption = { id: ulid(), displayName: m.new_option(), - color: '#808080', + color: getRandomUnusedColor(newOptions), } setNewOptions([...newOptions, newOption]) }} diff --git a/packages/webui/components/manage-fields-dialog.tsx b/packages/webui/components/manage-fields-dialog.tsx index f05bdec8..ca870751 100644 --- a/packages/webui/components/manage-fields-dialog.tsx +++ b/packages/webui/components/manage-fields-dialog.tsx @@ -27,7 +27,12 @@ import { useMemo, useState, useEffect } from 'react' import { toast } from 'sonner' import { Popover, PopoverTrigger, PopoverContent } from '@/ui/components/ui/popover' import { m } from '@/ui/paraglide/messages.js' -import { FIELD_TYPE_ICONS, PREDEFINED_COLORS, COLOR_MAP } from './fields-manager' +import { + FIELD_TYPE_ICONS, + PREDEFINED_COLORS, + COLOR_MAP, + getRandomUnusedColor, +} from './fields-manager' import { Button } from '@/ui/components/ui/button' import { Dialog, DialogContent, DialogTitle } from '@/ui/components/ui/dialog' @@ -137,6 +142,7 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel const [newType, setNewType] = useState('') const [newAiAutofill, setNewAiAutofill] = useState(false) const [newDescription, setNewDescription] = useState('') + const [newOptions, setNewOptions] = useState([]) const $patchOrder = client.api.projects[':projectId'].fields.order.$patch const { mutate: updateFieldsOrder } = useMutation< @@ -268,6 +274,7 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel setNewType('') setNewAiAutofill(false) setNewDescription('') + setNewOptions([]) } const handleDragEnd = (event: DragEndEvent) => { @@ -294,12 +301,19 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel const handleSaveCreation = () => { if (!newName || !newType) return + const typeConfig = + newType === FieldType.select + ? { select: { options: newOptions } } + : newType === FieldType.selectMulti + ? { selectMulti: { options: newOptions } } + : {} createField({ param: { projectId: projectId }, json: { config: { name: newName, type: newType, + ...typeConfig, }, label: newName, scope: selectedGroup === SCOPE_GROUPS.PROJECT ? undefined : selectedGroup, @@ -363,7 +377,10 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel {Object.values(FieldType).map((type) => ( setNewType(type)} + onClick={() => { + setNewType(type) + setNewOptions([]) + }} className="capitalize" > {type.replace(/_/g, ' ')} @@ -384,6 +401,81 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel + + {(newType === FieldType.select || newType === FieldType.selectMulti) && ( +
+
+ + +
+
+ {newOptions.map((opt, idx) => ( +
+ { + const updated = [...newOptions] + updated[idx] = { ...opt, displayName: e.target.value } + setNewOptions(updated) + }} + placeholder={m.option_name_placeholder()} + /> + + +
+ + + +
+ ))} +
+ + )} ) } @@ -447,16 +539,15 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel variant="ghost" size="sm" onClick={() => { - // Logic to add option - const newOption = { - id: ulid(), - displayName: m.new_option(), - color: '#808080', - } const currentOptions = (selectedField.config?.type === 'select' ? editConfig.select?.options : editConfig.selectMulti?.options) || [] + const newOption = { + id: ulid(), + displayName: m.new_option(), + color: getRandomUnusedColor(currentOptions), + } const newOptions = [...currentOptions, newOption] setEditConfig({ diff --git a/packages/webui/messages/en.json b/packages/webui/messages/en.json index 95c1cc7e..cedcdee9 100644 --- a/packages/webui/messages/en.json +++ b/packages/webui/messages/en.json @@ -641,7 +641,7 @@ "field_name_placeholder": "e.g. Status", "field_type": "Field Type", "select_field_type": "Select field type", - "description_optional_placeholder": "Description (Optional)", + "description_optional_placeholder": "Description (Optional, used for AI autofill)", "ai_autofill": "AI Autofill", "select_field_to_edit": "Select a field to edit options", "type_label": "Type:", diff --git a/packages/webui/messages/zh.json b/packages/webui/messages/zh.json index eb0ef81f..8310dd19 100644 --- a/packages/webui/messages/zh.json +++ b/packages/webui/messages/zh.json @@ -641,7 +641,7 @@ "field_name_placeholder": "例如:状态", "field_type": "字段类型", "select_field_type": "选择字段类型", - "description_optional_placeholder": "描述(可选)", + "description_optional_placeholder": "描述(可选,用于 AI 自动填充)", "ai_autofill": "AI 自动填充", "select_field_to_edit": "选择一个字段以编辑选项", "type_label": "类型:", diff --git a/packages/webui/paraglide/messages/description_optional_placeholder.d.ts b/packages/webui/paraglide/messages/description_optional_placeholder.d.ts index 679f1218..eee55586 100644 --- a/packages/webui/paraglide/messages/description_optional_placeholder.d.ts +++ b/packages/webui/paraglide/messages/description_optional_placeholder.d.ts @@ -1,7 +1,7 @@ /** * | output | * | --- | -* | "Description (Optional)" | +* | "Description (Optional, used for AI autofill)" | * * @param {Description_Optional_PlaceholderInputs} inputs * @param {{ locale?: "en" | "zh" }} options diff --git a/packages/webui/paraglide/messages/description_optional_placeholder.js b/packages/webui/paraglide/messages/description_optional_placeholder.js index ad6182c8..793d1bc9 100644 --- a/packages/webui/paraglide/messages/description_optional_placeholder.js +++ b/packages/webui/paraglide/messages/description_optional_placeholder.js @@ -6,17 +6,17 @@ import { getLocale, experimentalStaticLocale } from '../runtime.js'; /** @typedef {{}} Description_Optional_PlaceholderInputs */ const en_description_optional_placeholder = /** @type {(inputs: Description_Optional_PlaceholderInputs) => LocalizedString} */ () => { - return /** @type {LocalizedString} */ (`Description (Optional)`) + return /** @type {LocalizedString} */ (`Description (Optional, used for AI autofill)`) }; const zh_description_optional_placeholder = /** @type {(inputs: Description_Optional_PlaceholderInputs) => LocalizedString} */ () => { - return /** @type {LocalizedString} */ (`描述(可选)`) + return /** @type {LocalizedString} */ (`描述(可选,用于 AI 自动填充)`) }; /** * | output | * | --- | -* | "Description (Optional)" | +* | "Description (Optional, used for AI autofill)" | * * @param {Description_Optional_PlaceholderInputs} inputs * @param {{ locale?: "en" | "zh" }} options From ac5970c03e9bab552be0cb1a40c9292c225b2716 Mon Sep 17 00:00:00 2001 From: yiling Date: Wed, 5 Aug 2026 14:50:52 +0800 Subject: [PATCH 2/2] docs(webui): update field description placeholder text --- packages/webui/messages/en.json | 2 +- packages/webui/messages/zh.json | 2 +- .../messages/description_optional_placeholder.d.ts | 2 +- .../paraglide/messages/description_optional_placeholder.js | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/webui/messages/en.json b/packages/webui/messages/en.json index cedcdee9..97c7c805 100644 --- a/packages/webui/messages/en.json +++ b/packages/webui/messages/en.json @@ -641,7 +641,7 @@ "field_name_placeholder": "e.g. Status", "field_type": "Field Type", "select_field_type": "Select field type", - "description_optional_placeholder": "Description (Optional, used for AI autofill)", + "description_optional_placeholder": "Optional, used for AI autofill", "ai_autofill": "AI Autofill", "select_field_to_edit": "Select a field to edit options", "type_label": "Type:", diff --git a/packages/webui/messages/zh.json b/packages/webui/messages/zh.json index 8310dd19..e02ae597 100644 --- a/packages/webui/messages/zh.json +++ b/packages/webui/messages/zh.json @@ -641,7 +641,7 @@ "field_name_placeholder": "例如:状态", "field_type": "字段类型", "select_field_type": "选择字段类型", - "description_optional_placeholder": "描述(可选,用于 AI 自动填充)", + "description_optional_placeholder": "可选,用于 AI 自动填充", "ai_autofill": "AI 自动填充", "select_field_to_edit": "选择一个字段以编辑选项", "type_label": "类型:", diff --git a/packages/webui/paraglide/messages/description_optional_placeholder.d.ts b/packages/webui/paraglide/messages/description_optional_placeholder.d.ts index eee55586..e17a0a16 100644 --- a/packages/webui/paraglide/messages/description_optional_placeholder.d.ts +++ b/packages/webui/paraglide/messages/description_optional_placeholder.d.ts @@ -1,7 +1,7 @@ /** * | output | * | --- | -* | "Description (Optional, used for AI autofill)" | +* | "Optional, used for AI autofill" | * * @param {Description_Optional_PlaceholderInputs} inputs * @param {{ locale?: "en" | "zh" }} options diff --git a/packages/webui/paraglide/messages/description_optional_placeholder.js b/packages/webui/paraglide/messages/description_optional_placeholder.js index 793d1bc9..f973d352 100644 --- a/packages/webui/paraglide/messages/description_optional_placeholder.js +++ b/packages/webui/paraglide/messages/description_optional_placeholder.js @@ -6,17 +6,17 @@ import { getLocale, experimentalStaticLocale } from '../runtime.js'; /** @typedef {{}} Description_Optional_PlaceholderInputs */ const en_description_optional_placeholder = /** @type {(inputs: Description_Optional_PlaceholderInputs) => LocalizedString} */ () => { - return /** @type {LocalizedString} */ (`Description (Optional, used for AI autofill)`) + return /** @type {LocalizedString} */ (`Optional, used for AI autofill`) }; const zh_description_optional_placeholder = /** @type {(inputs: Description_Optional_PlaceholderInputs) => LocalizedString} */ () => { - return /** @type {LocalizedString} */ (`描述(可选,用于 AI 自动填充)`) + return /** @type {LocalizedString} */ (`可选,用于 AI 自动填充`) }; /** * | output | * | --- | -* | "Description (Optional, used for AI autofill)" | +* | "Optional, used for AI autofill" | * * @param {Description_Optional_PlaceholderInputs} inputs * @param {{ locale?: "en" | "zh" }} options