mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-02 22:14:50 +00:00
Compare commits
4
Commits
d87fe43b0f
...
c2af7494ec
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2af7494ec | ||
|
|
b7d2748b00 | ||
|
|
3467c0d92b | ||
|
|
22fede0290 |
@@ -8,8 +8,24 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
|
||||
### Added
|
||||
|
||||
### Fixed
|
||||
|
||||
### Changed
|
||||
|
||||
## [0.6.1] - 2026-10-24
|
||||
|
||||
### Added
|
||||
|
||||
* **dashboard**: Add Workflow Tasks section to the Team Dashboard allowing team owners to monitor background workflow jobs, inspect execution payloads and outputs, and stop in-flight tasks
|
||||
|
||||
### Fixed
|
||||
|
||||
* **metadata**: Fix an issue where clicking to edit a metadata field on a card or list row inadvertently selected the file, and prevent expanded text overlays or date pickers from being clipped by container borders
|
||||
|
||||
### Changed
|
||||
|
||||
* **deps**: Upgrade Bun to 1.4.4
|
||||
|
||||
## [0.6.0] - 2026-10-20
|
||||
|
||||
### Added
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<a href="https://hub.docker.com/r/shumaione/shumai"><img alt="Docker pulls" src="https://img.shields.io/docker/pulls/shumaione/shumai" /></a>
|
||||
<a href="https://github.com/shumaiOne/shumai/releases"><img alt="GitHub latest release" src="https://img.shields.io/github/v/release/shumaiOne/shumai" /></a>
|
||||
<a href="LICENSE"><img alt="License" src="https://img.shields.io/badge/license-MIT-blue" /></a>
|
||||
<a target="_blank" href="https://deepwiki.com/shumaiOne/shumai"><img alt="Ask DeepWiki" src="https://deepwiki.com/badge.svg" /></a>
|
||||
<a target="_blank" href="https://deepwiki.com/shumaiOne/shumai"><img alt="Ask DeepWiki" src="https://img.shields.io/badge/Ask-DeepWiki-6E56CF" /></a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
|
||||
+36
-1
@@ -12,7 +12,7 @@
|
||||
<a href="https://hub.docker.com/r/shumaione/shumai"><img alt="Docker pulls" src="https://img.shields.io/docker/pulls/shumaione/shumai" /></a>
|
||||
<a href="https://github.com/shumaiOne/shumai/releases"><img alt="GitHub latest release" src="https://img.shields.io/github/v/release/shumaiOne/shumai" /></a>
|
||||
<a href="LICENSE"><img alt="License" src="https://img.shields.io/badge/license-MIT-blue" /></a>
|
||||
<a target="_blank" href="https://deepwiki.com/shumaiOne/shumai"><img alt="Ask DeepWiki" src="https://deepwiki.com/badge.svg" /></a>
|
||||
<a target="_blank" href="https://deepwiki.com/shumaiOne/shumai"><img alt="Ask DeepWiki" src="https://img.shields.io/badge/Ask-DeepWiki-6E56CF" /></a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
@@ -165,6 +165,41 @@ https://gh-proxy.com/https://raw.githubusercontent.com/shumaiOne/shumai/main/REA
|
||||
|
||||
5. 打开浏览器,访问 `http://localhost:3000` 即可开始使用(若是远程部署,请访问 `http://<您的服务器IP>:3000`)。
|
||||
|
||||
#### **扩展转码 Worker(并行处理)**
|
||||
|
||||
默认情况下,Docker Compose 部署会按顺序逐个处理视频转码任务。这是出于系统设计考虑,因为视频转码属于计算密集型任务,容易耗尽可用的 CPU 或 GPU 资源。
|
||||
|
||||
但在批量上传(例如一次性上传 100+ 个视频)或处理需要耗费数小时的大型摄像机原始素材时,长时间的转码任务可能会阻塞后续文件的处理。此时,您可以通过增加额外的机器来横向扩展转码吞吐量。每台机器依然按顺序执行任务,但增加 worker 实例能够显著提升整体的并行处理能力。
|
||||
|
||||
Shumai 提供了独立的转码 Worker 镜像(支持 Docker Hub 与阿里云镜像源):
|
||||
|
||||
1. **连接准备**:启动一台临时机器,确保其能够正常访问您的 PostgreSQL 数据库和存储后端(例如 S3 或共享存储)。
|
||||
2. **启动 Worker**:配置相同的数据库与存储连接凭据并运行容器:
|
||||
|
||||
**阿里云镜像(国内推荐):**
|
||||
```bash
|
||||
docker run -d --name shumai_transcode_worker \
|
||||
-e DATABASE_URL="postgres://shumai:shumai_password@<postgres-host>:5432/shumai_db?sslmode=disable" \
|
||||
-e STORAGE_BACKEND="s3" \
|
||||
-e S3_BUCKET="your-bucket-name" \
|
||||
-e AWS_ENDPOINT_URL_S3="https://s3.us-east-1.amazonaws.com" \
|
||||
-e S3_ACCESS_KEY_ID="your-access-key-id" \
|
||||
-e S3_SECRET_ACCESS_KEY="your-secret-access-key" \
|
||||
crpi-000nkafzu6xvpwsc.cn-hongkong.personal.cr.aliyuncs.com/shumai-one/shumai-transcode:latest
|
||||
```
|
||||
|
||||
*如使用 Docker Hub,镜像为 [`shumaione/shumai-transcode:latest`](https://hub.docker.com/r/shumaione/shumai-transcode)。*
|
||||
|
||||
Worker 启动后会自动接入任务队列,并与主实例并行消费并处理积压的转码任务。
|
||||
|
||||
3. **随时停止**:当转码队列处理完毕(或不再需要额外的算力)时,只需停止或移除 Worker 容器:
|
||||
|
||||
```bash
|
||||
docker stop shumai_transcode_worker
|
||||
```
|
||||
|
||||
主 Shumai 服务的运行不会受到任何影响,亦无停机时间。
|
||||
|
||||
### 方案二:源码编译运行(开发环境)
|
||||
|
||||
如果您希望在本地参与 Shumai 的开发,请按以下步骤配置开发环境:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/agent-app",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"bin": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/cli",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"bin": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/premiere-uxp",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"private": true,
|
||||
"type": "commonjs",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/transcode-app",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"bin": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/web-app",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
},
|
||||
"apps/agent": {
|
||||
"name": "@shumai/agent-app",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"bin": {
|
||||
"shumai-agent": "./src/index.ts",
|
||||
},
|
||||
@@ -44,7 +44,7 @@
|
||||
},
|
||||
"apps/cli": {
|
||||
"name": "@shumai/cli",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"bin": {
|
||||
"shumai-cli": "./src/index.ts",
|
||||
},
|
||||
@@ -59,7 +59,7 @@
|
||||
},
|
||||
"apps/premiere-uxp": {
|
||||
"name": "@shumai/premiere-uxp",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"dependencies": {
|
||||
"@shumai/api": "workspace:*",
|
||||
"@shumai/dtos": "workspace:*",
|
||||
@@ -113,7 +113,7 @@
|
||||
},
|
||||
"apps/transcode": {
|
||||
"name": "@shumai/transcode-app",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"bin": {
|
||||
"shumai-transcode": "./src/index.ts",
|
||||
},
|
||||
@@ -125,7 +125,7 @@
|
||||
},
|
||||
"apps/web": {
|
||||
"name": "@shumai/web-app",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"dependencies": {
|
||||
"@shumai/agent": "workspace:*",
|
||||
"@shumai/api": "workspace:*",
|
||||
@@ -145,7 +145,7 @@
|
||||
},
|
||||
"packages/agent": {
|
||||
"name": "@shumai/agent",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"dependencies": {
|
||||
"@anthropic-ai/sandbox-runtime": "0.0.74",
|
||||
"@earendil-works/pi-agent-core": "0.82.1",
|
||||
@@ -168,7 +168,7 @@
|
||||
},
|
||||
"packages/api": {
|
||||
"name": "@shumai/api",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"dependencies": {
|
||||
"@hono/zod-validator": "0.7.6",
|
||||
"@shumai/core": "workspace:*",
|
||||
@@ -182,7 +182,7 @@
|
||||
},
|
||||
"packages/core": {
|
||||
"name": "@shumai/core",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"dependencies": {
|
||||
"@ai-sdk/alibaba": "2.0.38",
|
||||
"@ai-sdk/amazon-bedrock": "5.0.67",
|
||||
@@ -243,7 +243,7 @@
|
||||
},
|
||||
"packages/db": {
|
||||
"name": "@shumai/db",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"dependencies": {
|
||||
"@earendil-works/pi-agent-core": "0.82.1",
|
||||
"@prisma/adapter-pg": "7.10.0",
|
||||
@@ -259,7 +259,7 @@
|
||||
},
|
||||
"packages/dtos": {
|
||||
"name": "@shumai/dtos",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"dependencies": {
|
||||
"@earendil-works/pi-agent-core": "0.82.1",
|
||||
"zod": "4.5.4",
|
||||
@@ -267,7 +267,7 @@
|
||||
},
|
||||
"packages/e2e": {
|
||||
"name": "@shumai/e2e",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"dependencies": {
|
||||
"@earendil-works/pi-agent-core": "0.82.1",
|
||||
"@google/genai": "2.28.0",
|
||||
@@ -282,11 +282,11 @@
|
||||
},
|
||||
"packages/tableprinter": {
|
||||
"name": "@shumai/tableprinter",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
},
|
||||
"packages/transcode": {
|
||||
"name": "@shumai/transcode",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"dependencies": {
|
||||
"@shumai/core": "workspace:*",
|
||||
"@shumai/db": "workspace:*",
|
||||
@@ -297,7 +297,7 @@
|
||||
},
|
||||
"packages/webui": {
|
||||
"name": "@shumai/webui",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"dependencies": {
|
||||
"@base-ui/react": "1.7.0",
|
||||
"@dnd-kit/abstract": "0.5.0",
|
||||
@@ -399,7 +399,7 @@
|
||||
},
|
||||
"packages/workflow-core": {
|
||||
"name": "@shumai/workflow-core",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"dependencies": {
|
||||
"@dbos-inc/dbos-sdk": "5.2.11",
|
||||
"@shumai/core": "workspace:*",
|
||||
|
||||
@@ -15,7 +15,7 @@ services:
|
||||
retries: 5
|
||||
|
||||
embedding-server:
|
||||
image: shumaione/embedding-server:latest
|
||||
image: crpi-000nkafzu6xvpwsc.cn-hongkong.personal.cr.aliyuncs.com/shumai-one/embedding-server:latest
|
||||
container_name: shumai_embedding
|
||||
restart: unless-stopped
|
||||
|
||||
|
||||
@@ -15,12 +15,12 @@ services:
|
||||
retries: 5
|
||||
|
||||
embedding-server:
|
||||
image: shumaione/embedding-server:latest
|
||||
image: crpi-000nkafzu6xvpwsc.cn-hongkong.personal.cr.aliyuncs.com/shumai-one/embedding-server:latest
|
||||
container_name: shumai_embedding
|
||||
restart: unless-stopped
|
||||
|
||||
turntable-renderer:
|
||||
image: shumaione/turntable-renderer:latest
|
||||
image: crpi-000nkafzu6xvpwsc.cn-hongkong.personal.cr.aliyuncs.com/shumai-one/turntable-renderer:latest
|
||||
container_name: shumai_turntable
|
||||
restart: unless-stopped
|
||||
|
||||
|
||||
@@ -3,6 +3,22 @@ title: "Changelog"
|
||||
description: "Recent updates, new features, and improvements in Shumai"
|
||||
---
|
||||
|
||||
<Update label="v0.6.1" description="October 24, 2026">
|
||||
|
||||
### Added
|
||||
|
||||
* **dashboard**: Add Workflow Tasks section to the Team Dashboard allowing team owners to monitor background workflow jobs, inspect execution payloads and outputs, and stop in-flight tasks
|
||||
|
||||
### Fixed
|
||||
|
||||
* **metadata**: Fix an issue where clicking to edit a metadata field on a card or list row inadvertently selected the file, and prevent expanded text overlays or date pickers from being clipped by container borders
|
||||
|
||||
### Changed
|
||||
|
||||
* **deps**: Upgrade Bun to 1.4.4
|
||||
|
||||
</Update>
|
||||
|
||||
<Update label="v0.6.0" description="October 20, 2026">
|
||||
|
||||
### Added
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "shumai",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"repository": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/agent",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/api",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/core",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/db",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/dtos",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/e2e",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/tableprinter",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/transcode",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
|
||||
import React from 'react'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import DateField from './date-field'
|
||||
|
||||
describe('DateField Component', () => {
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
const dummyConfig = {
|
||||
name: 'Due Date',
|
||||
type: 'date' as const,
|
||||
date: {
|
||||
displayFormat: 'iso' as const,
|
||||
includeTime: false,
|
||||
},
|
||||
}
|
||||
|
||||
const dummyConfigWithTime = {
|
||||
name: 'Event Time',
|
||||
type: 'date' as const,
|
||||
date: {
|
||||
displayFormat: 'iso' as const,
|
||||
includeTime: true,
|
||||
timeFormat: 'twenty_four_hour' as const,
|
||||
},
|
||||
}
|
||||
|
||||
it('renders Empty state when value is empty', () => {
|
||||
render(<DateField value="" config={dummyConfig} onSave={vi.fn()} />)
|
||||
expect(screen.getByText('Empty')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('renders formatted date when value is present', () => {
|
||||
render(<DateField value="2026-06-15T00:00:00.000Z" config={dummyConfig} onSave={vi.fn()} />)
|
||||
expect(screen.getByText(/2026-06-15/)).toBeTruthy()
|
||||
})
|
||||
|
||||
it('opens calendar popover on click and calls onSave when selecting a day', () => {
|
||||
const onSave = vi.fn()
|
||||
render(<DateField value="2026-06-15T00:00:00.000Z" config={dummyConfig} onSave={onSave} />)
|
||||
|
||||
// Click trigger to open popover
|
||||
const trigger = screen.getByText(/2026-06-15/)
|
||||
fireEvent.click(trigger)
|
||||
|
||||
// Month heading should be present
|
||||
expect(screen.getByText(/June 2026/i)).toBeTruthy()
|
||||
|
||||
// Day 20 button should be clickable
|
||||
const day20 = screen.getByRole('button', { name: '20' })
|
||||
fireEvent.click(day20)
|
||||
|
||||
expect(onSave).toHaveBeenCalled()
|
||||
const savedArg = onSave.mock.calls[0][0]
|
||||
expect(new Date(savedArg).getDate()).toBe(20)
|
||||
})
|
||||
|
||||
it('supports time picker when includeTime is true', () => {
|
||||
const onSave = vi.fn()
|
||||
render(
|
||||
<DateField value="2026-06-15T10:00:00.000Z" config={dummyConfigWithTime} onSave={onSave} />,
|
||||
)
|
||||
|
||||
const trigger = screen.getByText(/2026-06-15/)
|
||||
fireEvent.click(trigger)
|
||||
|
||||
// "Time" section should be visible
|
||||
expect(screen.getByText(/Time/)).toBeTruthy()
|
||||
|
||||
// Select hour '14'
|
||||
const hour14 = screen.getByTestId('hour-14')
|
||||
fireEvent.click(hour14)
|
||||
|
||||
expect(onSave).toHaveBeenCalled()
|
||||
const savedArg = onSave.mock.calls[0][0]
|
||||
expect(new Date(savedArg).getHours()).toBe(14)
|
||||
})
|
||||
|
||||
it('does not open popover in readOnly mode', () => {
|
||||
const onSave = vi.fn()
|
||||
render(
|
||||
<DateField value="2026-06-15T00:00:00.000Z" config={dummyConfig} onSave={onSave} readOnly />,
|
||||
)
|
||||
|
||||
const trigger = screen.getByText(/2026-06-15/)
|
||||
fireEvent.click(trigger)
|
||||
|
||||
expect(screen.queryByText(/June 2026/i)).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -12,16 +12,15 @@ import {
|
||||
isValid,
|
||||
} from 'date-fns'
|
||||
import { ChevronLeft, ChevronRight, Clock } from 'lucide-react'
|
||||
import React, { useEffect, useRef, useState } from 'react'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import type { FieldProps } from './field-types'
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '@/ui/components/ui/popover'
|
||||
|
||||
const DateField: React.FC<FieldProps<string>> = ({ value, config, onSave, readOnly }) => {
|
||||
const dateConfig = config?.date
|
||||
const [isEditing, setIsEditing] = useState(false)
|
||||
const containerRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
// Parse value or default to today
|
||||
// Replaced parseISO with new Date() to avoid import errors
|
||||
const parsedDate = value ? new Date(value) : new Date()
|
||||
const safeDate = isValid(parsedDate) ? parsedDate : new Date()
|
||||
|
||||
@@ -35,25 +34,17 @@ const DateField: React.FC<FieldProps<string>> = ({ value, config, onSave, readOn
|
||||
}
|
||||
}, [isEditing, value])
|
||||
|
||||
// Click outside to close
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
const handleOpenChange = (open: boolean) => {
|
||||
if (readOnly) return
|
||||
setIsEditing(open)
|
||||
}
|
||||
|
||||
const getDisplayValue = (isoString: string) => {
|
||||
if (!isoString) return ''
|
||||
const date = new Date(isoString)
|
||||
@@ -81,17 +72,14 @@ const DateField: React.FC<FieldProps<string>> = ({ value, config, onSave, readOn
|
||||
}
|
||||
|
||||
// Calendar Logic
|
||||
// Replaced startOfMonth with native Date manipulation
|
||||
const monthStart = new Date(viewDate.getFullYear(), viewDate.getMonth(), 1)
|
||||
const monthEnd = endOfMonth(viewDate)
|
||||
const daysInMonth = eachDayOfInterval({ start: monthStart, end: monthEnd })
|
||||
const startDayOfWeek = getDay(monthStart) // 0 = Sunday
|
||||
|
||||
const handleDateClick = (day: Date) => {
|
||||
// Preserve time from current value if exists
|
||||
const newDate = new Date(day)
|
||||
if (dateConfig?.includeTime) {
|
||||
// Replaced setHours/setMinutes with native methods
|
||||
newDate.setHours(getHours(safeDate))
|
||||
newDate.setMinutes(getMinutes(safeDate))
|
||||
}
|
||||
@@ -116,23 +104,36 @@ const DateField: React.FC<FieldProps<string>> = ({ value, config, onSave, readOn
|
||||
const hours = Array.from({ length: 24 }, (_, i) => i)
|
||||
const minutes = Array.from({ length: 12 }, (_, i) => i * 5) // 0, 5, 10...
|
||||
|
||||
if (isEditing) {
|
||||
return (
|
||||
<div className="relative w-full" ref={containerRef}>
|
||||
<div className="w-full px-2 py-1 border border-ring rounded bg-background text-sm shadow-sm min-h-[28px] flex items-center">
|
||||
{value ? (
|
||||
getDisplayValue(value)
|
||||
) : (
|
||||
<span className="text-muted-foreground">Select date...</span>
|
||||
)}
|
||||
</div>
|
||||
return (
|
||||
<div className="relative w-full" onClick={(e) => e.stopPropagation()}>
|
||||
<Popover open={!readOnly && isEditing} onOpenChange={handleOpenChange}>
|
||||
<PopoverTrigger asChild>
|
||||
<div
|
||||
onClick={handleStartEdit}
|
||||
className={`w-full min-h-[28px] px-2 py-1 text-sm text-foreground rounded truncate border transition-colors ${
|
||||
isEditing ? 'border-ring bg-background shadow-sm' : 'border-transparent'
|
||||
} ${!readOnly ? 'cursor-pointer hover:bg-accent hover:border-border' : ''}`}
|
||||
>
|
||||
{value ? (
|
||||
getDisplayValue(value)
|
||||
) : (
|
||||
<span className="text-muted-foreground italic">Empty</span>
|
||||
)}
|
||||
</div>
|
||||
</PopoverTrigger>
|
||||
|
||||
<div className="absolute z-50 top-full left-0 mt-1 bg-popover border border-border rounded-lg shadow-xl flex flex-col md:flex-row overflow-hidden min-w-[280px]">
|
||||
<PopoverContent
|
||||
side="bottom"
|
||||
align="start"
|
||||
sideOffset={4}
|
||||
className="p-0 w-auto bg-popover border border-border rounded-lg shadow-xl flex flex-col md:flex-row overflow-hidden"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{/* Date Picker */}
|
||||
<div className="p-4 w-64">
|
||||
<div className="flex justify-between items-center mb-4">
|
||||
{/* Replaced subMonths with addMonths(-1) */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setViewDate(addMonths(viewDate, -1))}
|
||||
className="p-1 hover:bg-accent rounded"
|
||||
>
|
||||
@@ -140,6 +141,7 @@ const DateField: React.FC<FieldProps<string>> = ({ value, config, onSave, readOn
|
||||
</button>
|
||||
<span className="font-semibold text-sm">{format(viewDate, 'MMMM yyyy')}</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setViewDate(addMonths(viewDate, 1))}
|
||||
className="p-1 hover:bg-accent rounded"
|
||||
>
|
||||
@@ -168,6 +170,7 @@ const DateField: React.FC<FieldProps<string>> = ({ value, config, onSave, readOn
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
key={date.toString()}
|
||||
onClick={() => handleDateClick(date)}
|
||||
className={`w-8 h-8 rounded-full flex items-center justify-center hover:bg-accent transition-colors ${
|
||||
@@ -194,6 +197,7 @@ const DateField: React.FC<FieldProps<string>> = ({ value, config, onSave, readOn
|
||||
{hours.map((h) => (
|
||||
<div
|
||||
key={h}
|
||||
data-testid={`hour-${h}`}
|
||||
onClick={() => handleTimeChange('hour', h)}
|
||||
className={`px-2 py-1 text-center text-sm cursor-pointer hover:bg-accent ${getHours(safeDate) === h ? 'bg-primary/10 font-medium text-primary' : ''}`}
|
||||
>
|
||||
@@ -205,6 +209,7 @@ const DateField: React.FC<FieldProps<string>> = ({ value, config, onSave, readOn
|
||||
{minutes.map((m) => (
|
||||
<div
|
||||
key={m}
|
||||
data-testid={`minute-${m}`}
|
||||
onClick={() => handleTimeChange('minute', m)}
|
||||
className={`px-2 py-1 text-center text-sm cursor-pointer hover:bg-accent ${getMinutes(safeDate) === m ? 'bg-primary/10 font-medium text-primary' : ''}`}
|
||||
>
|
||||
@@ -215,19 +220,8 @@ const DateField: React.FC<FieldProps<string>> = ({ value, config, onSave, readOn
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
onClick={handleStartEdit}
|
||||
className={`w-full min-h-[28px] px-2 py-1 text-sm text-foreground rounded border border-transparent transition-colors ${
|
||||
!readOnly ? 'cursor-pointer hover:bg-accent hover:border-border' : ''
|
||||
}`}
|
||||
>
|
||||
{value ? getDisplayValue(value) : <span className="text-muted-foreground italic">Empty</span>}
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -17,8 +17,9 @@ describe('LongTextField Component', () => {
|
||||
|
||||
it('renders collapsed placeholder with fixed 2-row height and whitespace-pre-wrap', () => {
|
||||
render(<LongTextField value="Line 1\nLine 2\nLine 3" config={dummyConfig} onSave={vi.fn()} />)
|
||||
const collapsed = screen.getByTitle('Click to expand')
|
||||
const collapsed = screen.getByTestId('long-text-placeholder')
|
||||
expect(collapsed).toBeTruthy()
|
||||
expect(collapsed.title).toBe('Click to edit')
|
||||
expect(collapsed.className).toContain('h-[48px]')
|
||||
expect(collapsed.className).toContain('line-clamp-2')
|
||||
expect(collapsed.className).toContain('whitespace-pre-wrap')
|
||||
@@ -26,17 +27,102 @@ describe('LongTextField Component', () => {
|
||||
|
||||
it('renders Empty state inside 2-row container when value is empty', () => {
|
||||
render(<LongTextField value="" config={dummyConfig} onSave={vi.fn()} />)
|
||||
const collapsed = screen.getByTitle('Click to expand')
|
||||
const collapsed = screen.getByTestId('long-text-placeholder')
|
||||
expect(collapsed.className).toContain('h-[48px]')
|
||||
expect(screen.getByText('Empty')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('expands on click to show full content overlay', () => {
|
||||
render(<LongTextField value="Line 1\nLine 2\nLine 3" config={dummyConfig} onSave={vi.fn()} />)
|
||||
const collapsed = screen.getByTitle('Click to expand')
|
||||
it('single click expands directly into textarea editing mode and positions cursor at the end', () => {
|
||||
const text = 'Line 1\nLine 2\nLine 3'
|
||||
render(<LongTextField value={text} config={dummyConfig} onSave={vi.fn()} />)
|
||||
const collapsed = screen.getByTestId('long-text-placeholder')
|
||||
fireEvent.click(collapsed)
|
||||
|
||||
const elements = screen.getAllByText(/Line 1/)
|
||||
expect(elements.length).toBe(2)
|
||||
const textarea = screen.getByRole('textbox') as HTMLTextAreaElement
|
||||
expect(textarea).toBeTruthy()
|
||||
expect(textarea.value).toBe(text)
|
||||
expect(textarea.selectionStart).toBe(text.length)
|
||||
expect(textarea.selectionEnd).toBe(text.length)
|
||||
expect(collapsed.className).toContain('invisible')
|
||||
})
|
||||
|
||||
it('saves updated content on blur', () => {
|
||||
const onSave = vi.fn()
|
||||
render(<LongTextField value="Initial content" config={dummyConfig} onSave={onSave} />)
|
||||
|
||||
// Single click directly opens editing textarea
|
||||
fireEvent.click(screen.getByTestId('long-text-placeholder'))
|
||||
|
||||
const textarea = screen.getByRole('textbox') as HTMLTextAreaElement
|
||||
expect(textarea).toBeTruthy()
|
||||
expect(textarea.value).toBe('Initial content')
|
||||
|
||||
// Change value and blur
|
||||
fireEvent.change(textarea, { target: { value: 'Updated content' } })
|
||||
fireEvent.blur(textarea)
|
||||
|
||||
expect(onSave).toHaveBeenCalledWith('Updated content')
|
||||
expect(screen.queryByRole('textbox')).toBeNull()
|
||||
})
|
||||
|
||||
it('does not call onSave on blur if value did not change', () => {
|
||||
const onSave = vi.fn()
|
||||
render(<LongTextField value="Unchanged" config={dummyConfig} onSave={onSave} />)
|
||||
|
||||
fireEvent.click(screen.getByTestId('long-text-placeholder'))
|
||||
const textarea = screen.getByRole('textbox') as HTMLTextAreaElement
|
||||
fireEvent.blur(textarea)
|
||||
|
||||
expect(onSave).not.toHaveBeenCalled()
|
||||
expect(screen.queryByRole('textbox')).toBeNull()
|
||||
})
|
||||
|
||||
it('blurs and saves when pressing Cmd+Enter in textarea', () => {
|
||||
const onSave = vi.fn()
|
||||
render(<LongTextField value="Initial content" config={dummyConfig} onSave={onSave} />)
|
||||
|
||||
fireEvent.click(screen.getByTestId('long-text-placeholder'))
|
||||
|
||||
const textarea = screen.getByRole('textbox') as HTMLTextAreaElement
|
||||
fireEvent.change(textarea, { target: { value: 'Content saved via shortcut' } })
|
||||
fireEvent.keyDown(textarea, { key: 'Enter', metaKey: true })
|
||||
|
||||
expect(onSave).toHaveBeenCalledWith('Content saved via shortcut')
|
||||
expect(screen.queryByRole('textbox')).toBeNull()
|
||||
})
|
||||
|
||||
it('cancels editing on Escape key and discards changes', () => {
|
||||
const onSave = vi.fn()
|
||||
render(<LongTextField value="Line 1\nLine 2" config={dummyConfig} onSave={onSave} />)
|
||||
|
||||
fireEvent.click(screen.getByTestId('long-text-placeholder'))
|
||||
const textarea = screen.getByRole('textbox') as HTMLTextAreaElement
|
||||
expect(textarea).toBeTruthy()
|
||||
|
||||
fireEvent.change(textarea, { target: { value: 'Changed content' } })
|
||||
fireEvent.keyDown(document, { key: 'Escape' })
|
||||
|
||||
expect(screen.queryByRole('textbox')).toBeNull()
|
||||
expect(onSave).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not allow editing in readOnly mode, only expanding view', () => {
|
||||
const onSave = vi.fn()
|
||||
render(<LongTextField value="Readonly text" config={dummyConfig} onSave={onSave} readOnly />)
|
||||
|
||||
const collapsed = screen.getByTestId('long-text-placeholder')
|
||||
expect(collapsed.title).toBe('Click to expand')
|
||||
fireEvent.click(collapsed)
|
||||
|
||||
// Expanded read-only overlay is present, but no textarea
|
||||
expect(screen.queryByRole('textbox')).toBeNull()
|
||||
const expandedView = screen.getByTestId('long-text-expanded-overlay')
|
||||
expect(expandedView).toBeTruthy()
|
||||
expect(expandedView.textContent).toContain('Readonly text')
|
||||
|
||||
// Escape closes read-only overlay
|
||||
fireEvent.keyDown(document, { key: 'Escape' })
|
||||
expect(screen.queryByTestId('long-text-expanded-overlay')).toBeNull()
|
||||
expect(onSave).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import React, { useEffect, useRef, useState } from 'react'
|
||||
import React, { useEffect, useLayoutEffect, useRef, useState } from 'react'
|
||||
import { createPortal } from 'react-dom'
|
||||
import type { FieldProps } from './field-types'
|
||||
|
||||
const LongTextField: React.FC<FieldProps<string>> = ({ value, onSave, readOnly }) => {
|
||||
@@ -6,92 +7,210 @@ const LongTextField: React.FC<FieldProps<string>> = ({ value, onSave, readOnly }
|
||||
const [localValue, setLocalValue] = useState(value || '')
|
||||
const textareaRef = useRef<HTMLTextAreaElement>(null)
|
||||
const containerRef = useRef<HTMLDivElement>(null)
|
||||
const overlayRef = useRef<HTMLDivElement | HTMLTextAreaElement | null>(null)
|
||||
const [expanded, setExpanded] = useState(false)
|
||||
const [coords, setCoords] = useState<{
|
||||
top: number
|
||||
left: number
|
||||
width: number
|
||||
height: number
|
||||
} | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
setLocalValue(value || '')
|
||||
}, [value])
|
||||
|
||||
const updateCoords = () => {
|
||||
if (containerRef.current) {
|
||||
const rect = containerRef.current.getBoundingClientRect()
|
||||
setCoords({
|
||||
top: rect.top,
|
||||
left: rect.left,
|
||||
width: rect.width,
|
||||
height: rect.height,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (expanded || isEditing) {
|
||||
updateCoords()
|
||||
}
|
||||
}, [expanded, isEditing])
|
||||
|
||||
const adjustHeight = () => {
|
||||
if (textareaRef.current) {
|
||||
textareaRef.current.style.height = 'auto'
|
||||
const baseHeight = Math.max(80, coords?.height || 0)
|
||||
const newHeight = Math.min(240, Math.max(baseHeight, textareaRef.current.scrollHeight))
|
||||
textareaRef.current.style.height = `${newHeight}px`
|
||||
}
|
||||
}
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (isEditing) {
|
||||
adjustHeight()
|
||||
}
|
||||
}, [isEditing, localValue])
|
||||
|
||||
useEffect(() => {
|
||||
if (isEditing && textareaRef.current) {
|
||||
textareaRef.current.focus()
|
||||
setExpanded(false)
|
||||
const len = textareaRef.current.value.length
|
||||
textareaRef.current.setSelectionRange(len, len)
|
||||
}
|
||||
}, [isEditing])
|
||||
|
||||
// Handle click outside to close expanded state
|
||||
// Handle click outside and Escape to close expanded or editing state
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
const target = event.target as Node
|
||||
if (
|
||||
expanded &&
|
||||
containerRef.current &&
|
||||
!containerRef.current.contains(event.target as Node)
|
||||
!containerRef.current.contains(target) &&
|
||||
overlayRef.current &&
|
||||
!overlayRef.current.contains(target)
|
||||
) {
|
||||
setExpanded(false)
|
||||
if (isEditing) {
|
||||
handleBlur()
|
||||
} else {
|
||||
setExpanded(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (expanded) {
|
||||
const handleKeyDownGlobal = (event: KeyboardEvent) => {
|
||||
if (event.key === 'Escape') {
|
||||
if (isEditing) {
|
||||
setIsEditing(false)
|
||||
setLocalValue(value || '')
|
||||
} else {
|
||||
setExpanded(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleScrollOrResize = (event: Event) => {
|
||||
if (overlayRef.current && overlayRef.current.contains(event.target as Node)) {
|
||||
return
|
||||
}
|
||||
updateCoords()
|
||||
}
|
||||
|
||||
if (expanded || isEditing) {
|
||||
document.addEventListener('mousedown', handleClickOutside)
|
||||
document.addEventListener('keydown', handleKeyDownGlobal)
|
||||
window.addEventListener('scroll', handleScrollOrResize, true)
|
||||
window.addEventListener('resize', handleScrollOrResize)
|
||||
}
|
||||
return () => {
|
||||
document.removeEventListener('mousedown', handleClickOutside)
|
||||
document.removeEventListener('keydown', handleKeyDownGlobal)
|
||||
window.removeEventListener('scroll', handleScrollOrResize, true)
|
||||
window.removeEventListener('resize', handleScrollOrResize)
|
||||
}
|
||||
}, [expanded])
|
||||
}, [expanded, isEditing, localValue, value])
|
||||
|
||||
const handleBlur = () => {
|
||||
setIsEditing(false)
|
||||
onSave(localValue)
|
||||
setExpanded(false)
|
||||
if (localValue !== (value || '')) {
|
||||
onSave(localValue)
|
||||
}
|
||||
}
|
||||
|
||||
const handlePlaceholderClick = (e: React.MouseEvent) => {
|
||||
e.stopPropagation()
|
||||
setExpanded(true)
|
||||
}
|
||||
|
||||
const handleOverlayClick = (e: React.MouseEvent) => {
|
||||
e.stopPropagation()
|
||||
updateCoords()
|
||||
if (!readOnly) {
|
||||
setIsEditing(true)
|
||||
} else {
|
||||
setExpanded(true)
|
||||
}
|
||||
}
|
||||
|
||||
if (isEditing) {
|
||||
return (
|
||||
<textarea
|
||||
ref={textareaRef}
|
||||
value={localValue}
|
||||
onChange={(e) => setLocalValue(e.target.value)}
|
||||
onBlur={handleBlur}
|
||||
className="w-full min-h-[80px] p-2 border border-ring rounded bg-background text-sm outline-none shadow-sm resize-none"
|
||||
/>
|
||||
)
|
||||
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
||||
if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') {
|
||||
e.currentTarget.blur()
|
||||
}
|
||||
}
|
||||
|
||||
const setTextareaRef = (el: HTMLTextAreaElement | null) => {
|
||||
textareaRef.current = el
|
||||
overlayRef.current = el
|
||||
}
|
||||
|
||||
return (
|
||||
<div ref={containerRef} className="relative w-full text-sm">
|
||||
{/* Placeholder */}
|
||||
<div
|
||||
ref={containerRef}
|
||||
className="relative w-full text-sm"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{/* In-card placeholder: fixed 48px height so card height never changes */}
|
||||
<div
|
||||
data-testid="long-text-placeholder"
|
||||
onClick={handlePlaceholderClick}
|
||||
className={`w-full text-foreground rounded border border-transparent transition-all px-2 py-1 h-[48px] line-clamp-2 whitespace-pre-wrap overflow-hidden ${
|
||||
!readOnly ? 'cursor-pointer hover:bg-accent hover:border-border' : 'cursor-pointer'
|
||||
}`}
|
||||
title="Click to expand"
|
||||
expanded || isEditing ? 'invisible pointer-events-none select-none' : ''
|
||||
} ${!readOnly ? 'cursor-pointer hover:bg-accent hover:border-border' : 'cursor-pointer'}`}
|
||||
title={
|
||||
!expanded && !isEditing ? (!readOnly ? 'Click to edit' : 'Click to expand') : undefined
|
||||
}
|
||||
>
|
||||
{value ? value : <span className="text-muted-foreground italic">Empty</span>}
|
||||
</div>
|
||||
|
||||
{/* Expanded Overlay */}
|
||||
{expanded && (
|
||||
<div
|
||||
onClick={handleOverlayClick}
|
||||
className={`absolute top-0 left-0 w-full min-h-full h-auto z-50 bg-background border border-ring rounded shadow-lg px-2 py-1 whitespace-pre-wrap ${
|
||||
!readOnly ? 'cursor-text' : ''
|
||||
}`}
|
||||
>
|
||||
{value ? value : <span className="text-muted-foreground italic">Empty</span>}
|
||||
</div>
|
||||
)}
|
||||
{/* Expanded overlay or textarea: portaled to document.body so card border never clips it */}
|
||||
{(expanded || isEditing) &&
|
||||
coords &&
|
||||
typeof document !== 'undefined' &&
|
||||
createPortal(
|
||||
isEditing ? (
|
||||
<textarea
|
||||
ref={setTextareaRef}
|
||||
data-testid="long-text-editing-overlay"
|
||||
value={localValue}
|
||||
onChange={(e) => {
|
||||
setLocalValue(e.target.value)
|
||||
adjustHeight()
|
||||
}}
|
||||
onBlur={handleBlur}
|
||||
onKeyDown={handleKeyDown}
|
||||
style={{
|
||||
position: 'fixed',
|
||||
top: coords.top,
|
||||
left: coords.left,
|
||||
width: coords.width > 0 ? coords.width : 'auto',
|
||||
minWidth: coords.width > 0 ? coords.width : 200,
|
||||
minHeight: Math.max(80, coords.height),
|
||||
maxHeight: 240,
|
||||
zIndex: 50,
|
||||
}}
|
||||
className="bg-background border border-ring rounded shadow-lg px-2 py-1 text-sm outline-none resize-none overflow-y-auto"
|
||||
/>
|
||||
) : (
|
||||
<div
|
||||
ref={(el) => {
|
||||
overlayRef.current = el
|
||||
}}
|
||||
data-testid="long-text-expanded-overlay"
|
||||
style={{
|
||||
position: 'fixed',
|
||||
top: coords.top,
|
||||
left: coords.left,
|
||||
width: coords.width > 0 ? coords.width : 'auto',
|
||||
minWidth: coords.width > 0 ? coords.width : 200,
|
||||
minHeight: Math.max(80, coords.height),
|
||||
maxHeight: 240,
|
||||
zIndex: 50,
|
||||
}}
|
||||
className="min-h-[80px] bg-background border border-ring rounded shadow-lg px-2 py-1 whitespace-pre-wrap overflow-y-auto text-sm cursor-pointer"
|
||||
>
|
||||
{value ? value : <span className="text-muted-foreground italic">Empty</span>}
|
||||
</div>
|
||||
),
|
||||
document.body,
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
|
||||
import React from 'react'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import NumberField from './number-field'
|
||||
|
||||
describe('NumberField Component', () => {
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
const dummyConfig = {
|
||||
name: 'Score',
|
||||
type: 'number' as const,
|
||||
number: {
|
||||
scale: 2,
|
||||
},
|
||||
}
|
||||
|
||||
it('renders Empty state when value is undefined', () => {
|
||||
render(<NumberField value={undefined} config={dummyConfig} onSave={vi.fn()} />)
|
||||
expect(screen.getByText('Empty')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('formats number with scale', () => {
|
||||
render(<NumberField value={42} config={dummyConfig} onSave={vi.fn()} />)
|
||||
expect(screen.getByText('42.00')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('enters edit mode on click and stops event propagation', () => {
|
||||
const parentClick = vi.fn()
|
||||
const parentDoubleClick = vi.fn()
|
||||
render(
|
||||
<div onClick={parentClick} onDoubleClick={parentDoubleClick}>
|
||||
<NumberField value={10} config={dummyConfig} onSave={vi.fn()} />
|
||||
</div>,
|
||||
)
|
||||
|
||||
const display = screen.getByText('10.00')
|
||||
fireEvent.click(display)
|
||||
|
||||
const input = screen.getByRole('spinbutton') as HTMLInputElement
|
||||
expect(input).toBeTruthy()
|
||||
expect(input.value).toBe('10')
|
||||
expect(parentClick).not.toHaveBeenCalled()
|
||||
|
||||
fireEvent.doubleClick(input)
|
||||
expect(parentDoubleClick).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('saves parsed number on blur', () => {
|
||||
const onSave = vi.fn()
|
||||
render(<NumberField value={10} config={dummyConfig} onSave={onSave} />)
|
||||
|
||||
fireEvent.click(screen.getByText('10.00'))
|
||||
const input = screen.getByRole('spinbutton') as HTMLInputElement
|
||||
fireEvent.change(input, { target: { value: '25.5' } })
|
||||
fireEvent.blur(input)
|
||||
|
||||
expect(onSave).toHaveBeenCalledWith(25.5)
|
||||
})
|
||||
|
||||
it('cancels edit on Escape key', () => {
|
||||
const onSave = vi.fn()
|
||||
render(<NumberField value={10} config={dummyConfig} onSave={onSave} />)
|
||||
|
||||
fireEvent.click(screen.getByText('10.00'))
|
||||
const input = screen.getByRole('spinbutton') as HTMLInputElement
|
||||
fireEvent.change(input, { target: { value: '99' } })
|
||||
fireEvent.keyDown(input, { key: 'Escape' })
|
||||
|
||||
expect(screen.queryByRole('spinbutton')).toBeNull()
|
||||
expect(screen.getByText('10.00')).toBeTruthy()
|
||||
expect(onSave).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not enter edit mode when readOnly', () => {
|
||||
render(<NumberField value={10} config={dummyConfig} onSave={vi.fn()} readOnly />)
|
||||
|
||||
fireEvent.click(screen.getByText('10.00'))
|
||||
expect(screen.queryByRole('spinbutton')).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -23,7 +23,8 @@ const NumberField: React.FC<FieldProps<number | undefined>> = ({
|
||||
}
|
||||
}, [isEditing])
|
||||
|
||||
const handleStartEdit = () => {
|
||||
const handleStartEdit = (e: React.MouseEvent) => {
|
||||
e.stopPropagation()
|
||||
if (!readOnly) {
|
||||
setIsEditing(true)
|
||||
}
|
||||
@@ -44,6 +45,11 @@ const NumberField: React.FC<FieldProps<number | undefined>> = ({
|
||||
e.stopPropagation()
|
||||
inputRef.current?.blur()
|
||||
}
|
||||
if (e.key === 'Escape') {
|
||||
e.stopPropagation()
|
||||
setIsEditing(false)
|
||||
setLocalValue(value !== undefined && value !== null ? value.toString() : '')
|
||||
}
|
||||
}
|
||||
|
||||
const formatNumber = (val: number | undefined) => {
|
||||
@@ -51,34 +57,37 @@ const NumberField: React.FC<FieldProps<number | undefined>> = ({
|
||||
return val.toFixed(numberConfig?.scale)
|
||||
}
|
||||
|
||||
if (isEditing) {
|
||||
return (
|
||||
<input
|
||||
ref={inputRef}
|
||||
type="number"
|
||||
step={1 / Math.pow(10, numberConfig?.scale || 0)}
|
||||
value={localValue}
|
||||
onChange={(e) => setLocalValue(e.target.value)}
|
||||
onBlur={handleBlur}
|
||||
onKeyDown={handleKeyDown}
|
||||
onDoubleClick={(e) => e.stopPropagation()}
|
||||
className="w-full px-2 py-1 border border-ring rounded bg-background text-sm outline-none shadow-sm text-left font-mono"
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
onClick={handleStartEdit}
|
||||
className="relative w-full"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
onDoubleClick={(e) => e.stopPropagation()}
|
||||
className={`w-full min-h-[28px] px-2 py-1 text-sm text-foreground rounded border border-transparent transition-colors text-left font-mono ${
|
||||
!readOnly ? 'cursor-pointer hover:bg-accent hover:border-border' : ''
|
||||
}`}
|
||||
>
|
||||
{value !== undefined && value !== null ? (
|
||||
formatNumber(value)
|
||||
{isEditing ? (
|
||||
<input
|
||||
ref={inputRef}
|
||||
type="number"
|
||||
step={1 / Math.pow(10, numberConfig?.scale || 0)}
|
||||
value={localValue}
|
||||
onChange={(e) => setLocalValue(e.target.value)}
|
||||
onBlur={handleBlur}
|
||||
onKeyDown={handleKeyDown}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
className="w-full px-2 py-1 border border-ring rounded bg-background text-sm outline-none shadow-sm text-left font-mono"
|
||||
/>
|
||||
) : (
|
||||
<span className="text-muted-foreground italic font-sans text-left block">Empty</span>
|
||||
<div
|
||||
onClick={handleStartEdit}
|
||||
className={`w-full min-h-[28px] px-2 py-1 text-sm text-foreground rounded border border-transparent transition-colors text-left font-mono ${
|
||||
!readOnly ? 'cursor-pointer hover:bg-accent hover:border-border' : ''
|
||||
}`}
|
||||
>
|
||||
{value !== undefined && value !== null ? (
|
||||
formatNumber(value)
|
||||
) : (
|
||||
<span className="text-muted-foreground italic font-sans text-left block">Empty</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -25,6 +25,7 @@ const RatingField: React.FC<FieldProps<number>> = ({ value, config, onSave, read
|
||||
return (
|
||||
<div
|
||||
className="flex items-center gap-1 h-[28px]"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
onMouseLeave={() => !readOnly && setHoverValue(null)}
|
||||
onDoubleClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
|
||||
import React from 'react'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import TextField from './text-field'
|
||||
|
||||
describe('TextField Component', () => {
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
const dummyConfig = {
|
||||
name: 'Title',
|
||||
type: 'text' as const,
|
||||
}
|
||||
|
||||
it('renders Empty state when value is empty', () => {
|
||||
render(<TextField value="" config={dummyConfig} onSave={vi.fn()} />)
|
||||
expect(screen.getByText('Empty')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('enters edit mode on click and stops event propagation', () => {
|
||||
const parentClick = vi.fn()
|
||||
const parentDoubleClick = vi.fn()
|
||||
render(
|
||||
<div onClick={parentClick} onDoubleClick={parentDoubleClick}>
|
||||
<TextField value="Test Text" config={dummyConfig} onSave={vi.fn()} />
|
||||
</div>,
|
||||
)
|
||||
|
||||
const display = screen.getByText('Test Text')
|
||||
fireEvent.click(display)
|
||||
|
||||
const input = screen.getByRole('textbox') as HTMLInputElement
|
||||
expect(input).toBeTruthy()
|
||||
expect(input.value).toBe('Test Text')
|
||||
expect(parentClick).not.toHaveBeenCalled()
|
||||
|
||||
fireEvent.doubleClick(input)
|
||||
expect(parentDoubleClick).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('saves on blur when value changed', () => {
|
||||
const onSave = vi.fn()
|
||||
render(<TextField value="Initial" config={dummyConfig} onSave={onSave} />)
|
||||
|
||||
fireEvent.click(screen.getByText('Initial'))
|
||||
const input = screen.getByRole('textbox') as HTMLInputElement
|
||||
fireEvent.change(input, { target: { value: 'Updated' } })
|
||||
fireEvent.blur(input)
|
||||
|
||||
expect(onSave).toHaveBeenCalledWith('Updated')
|
||||
expect(screen.queryByRole('textbox')).toBeNull()
|
||||
})
|
||||
|
||||
it('does not save on blur if value is unchanged', () => {
|
||||
const onSave = vi.fn()
|
||||
render(<TextField value="Same" config={dummyConfig} onSave={onSave} />)
|
||||
|
||||
fireEvent.click(screen.getByText('Same'))
|
||||
const input = screen.getByRole('textbox') as HTMLInputElement
|
||||
fireEvent.blur(input)
|
||||
|
||||
expect(onSave).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('blurs on Enter key', () => {
|
||||
const onSave = vi.fn()
|
||||
render(<TextField value="Initial" config={dummyConfig} onSave={onSave} />)
|
||||
|
||||
fireEvent.click(screen.getByText('Initial'))
|
||||
const input = screen.getByRole('textbox') as HTMLInputElement
|
||||
fireEvent.change(input, { target: { value: 'Enter Saved' } })
|
||||
fireEvent.keyDown(input, { key: 'Enter' })
|
||||
|
||||
expect(onSave).toHaveBeenCalledWith('Enter Saved')
|
||||
})
|
||||
|
||||
it('cancels edit and discards changes on Escape key', () => {
|
||||
const onSave = vi.fn()
|
||||
render(<TextField value="Original" config={dummyConfig} onSave={onSave} />)
|
||||
|
||||
fireEvent.click(screen.getByText('Original'))
|
||||
const input = screen.getByRole('textbox') as HTMLInputElement
|
||||
fireEvent.change(input, { target: { value: 'Discarded' } })
|
||||
fireEvent.keyDown(input, { key: 'Escape' })
|
||||
|
||||
expect(screen.queryByRole('textbox')).toBeNull()
|
||||
expect(screen.getByText('Original')).toBeTruthy()
|
||||
expect(onSave).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not enter edit mode when readOnly', () => {
|
||||
render(<TextField value="ReadOnly Text" config={dummyConfig} onSave={vi.fn()} readOnly />)
|
||||
|
||||
fireEvent.click(screen.getByText('ReadOnly Text'))
|
||||
expect(screen.queryByRole('textbox')).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -17,7 +17,8 @@ const TextField: React.FC<FieldProps<string>> = ({ value, onSave, readOnly }) =>
|
||||
}
|
||||
}, [isEditing])
|
||||
|
||||
const handleStartEdit = () => {
|
||||
const handleStartEdit = (e: React.MouseEvent) => {
|
||||
e.stopPropagation()
|
||||
if (!readOnly) {
|
||||
setIsEditing(true)
|
||||
}
|
||||
@@ -25,37 +26,49 @@ const TextField: React.FC<FieldProps<string>> = ({ value, onSave, readOnly }) =>
|
||||
|
||||
const handleBlur = () => {
|
||||
setIsEditing(false)
|
||||
onSave(localValue)
|
||||
if (localValue !== (value || '')) {
|
||||
onSave(localValue)
|
||||
}
|
||||
}
|
||||
|
||||
const handleKeyDown = (e: React.KeyboardEvent) => {
|
||||
if (e.key === 'Enter') {
|
||||
inputRef.current?.blur()
|
||||
}
|
||||
}
|
||||
|
||||
if (isEditing) {
|
||||
return (
|
||||
<input
|
||||
ref={inputRef}
|
||||
type="text"
|
||||
value={localValue}
|
||||
onChange={(e) => setLocalValue(e.target.value)}
|
||||
onBlur={handleBlur}
|
||||
onKeyDown={handleKeyDown}
|
||||
className="w-full px-2 py-1 border border-ring rounded bg-background text-sm outline-none shadow-sm"
|
||||
/>
|
||||
)
|
||||
if (e.key === 'Escape') {
|
||||
setIsEditing(false)
|
||||
setLocalValue(value || '')
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
onClick={handleStartEdit}
|
||||
className={`w-full min-h-[28px] px-2 py-1 text-sm text-foreground rounded truncate border border-transparent transition-colors ${
|
||||
!readOnly ? 'cursor-pointer hover:bg-accent hover:border-border' : ''
|
||||
}`}
|
||||
className="relative w-full"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
onDoubleClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{value || <span className="text-muted-foreground italic">Empty</span>}
|
||||
{isEditing ? (
|
||||
<input
|
||||
ref={inputRef}
|
||||
type="text"
|
||||
value={localValue}
|
||||
onChange={(e) => setLocalValue(e.target.value)}
|
||||
onBlur={handleBlur}
|
||||
onKeyDown={handleKeyDown}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
className="w-full px-2 py-1 border border-ring rounded bg-background text-sm outline-none shadow-sm"
|
||||
/>
|
||||
) : (
|
||||
<div
|
||||
data-testid="text-field-display"
|
||||
onClick={handleStartEdit}
|
||||
className={`w-full min-h-[28px] px-2 py-1 text-sm text-foreground rounded truncate border border-transparent transition-colors ${
|
||||
!readOnly ? 'cursor-pointer hover:bg-accent hover:border-border' : ''
|
||||
}`}
|
||||
>
|
||||
{value || <span className="text-muted-foreground italic">Empty</span>}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -476,4 +476,102 @@ describe('FileCard', () => {
|
||||
expect(matchedDuration).toBeTruthy()
|
||||
expect(matchedDuration.textContent).toBe('01:05 - 02:05')
|
||||
})
|
||||
|
||||
it('renders custom fields and allows expanding longText in FileCard', () => {
|
||||
const itemWithFields: AssetInfo = {
|
||||
...fileItem,
|
||||
fieldValues: [
|
||||
{
|
||||
fieldId: 'field_long_text',
|
||||
value: 'Line 1\nLine 2\nLine 3\nLine 4',
|
||||
},
|
||||
],
|
||||
} as AssetInfo
|
||||
|
||||
const fields = [
|
||||
{
|
||||
id: 'field_long_text',
|
||||
name: 'Notes',
|
||||
scope: 'project',
|
||||
readOnly: false,
|
||||
visible: true,
|
||||
description: '',
|
||||
config: {
|
||||
type: 'longText' as const,
|
||||
name: 'Notes',
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
renderComponent({ item: itemWithFields, fields })
|
||||
|
||||
expect(screen.getByText('Notes')).toBeTruthy()
|
||||
const collapsed = screen.getByTestId('long-text-placeholder')
|
||||
expect(collapsed).toBeTruthy()
|
||||
|
||||
// Expanding directly enters editing mode on single click
|
||||
fireEvent.click(collapsed)
|
||||
const textarea = screen.getByRole('textbox') as HTMLTextAreaElement
|
||||
expect(textarea).toBeTruthy()
|
||||
expect(textarea.value).toContain('Line 1')
|
||||
expect(textarea.value).toContain('Line 4')
|
||||
})
|
||||
|
||||
it('does not trigger onSelect when clicking a single line text field or number field to edit', () => {
|
||||
const onSelect = vi.fn()
|
||||
const itemWithFields: AssetInfo = {
|
||||
...fileItem,
|
||||
fieldValues: [
|
||||
{
|
||||
fieldId: 'field_text',
|
||||
value: 'Single line text',
|
||||
},
|
||||
{
|
||||
fieldId: 'field_number',
|
||||
value: 42,
|
||||
},
|
||||
],
|
||||
} as AssetInfo
|
||||
|
||||
const fields = [
|
||||
{
|
||||
id: 'field_text',
|
||||
name: 'Title',
|
||||
scope: 'project',
|
||||
readOnly: false,
|
||||
visible: true,
|
||||
description: '',
|
||||
config: {
|
||||
type: 'text' as const,
|
||||
name: 'Title',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'field_number',
|
||||
name: 'Score',
|
||||
scope: 'project',
|
||||
readOnly: false,
|
||||
visible: true,
|
||||
description: '',
|
||||
config: {
|
||||
type: 'number' as const,
|
||||
name: 'Score',
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
renderComponent({ item: itemWithFields, fields, onSelect })
|
||||
|
||||
// Click single line text field
|
||||
const textField = screen.getByText('Single line text')
|
||||
fireEvent.click(textField)
|
||||
expect(screen.getByDisplayValue('Single line text')).toBeTruthy()
|
||||
expect(onSelect).not.toHaveBeenCalled()
|
||||
|
||||
// Click number field
|
||||
const numberField = screen.getByText('42')
|
||||
fireEvent.click(numberField)
|
||||
expect(screen.getByDisplayValue('42')).toBeTruthy()
|
||||
expect(onSelect).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -617,7 +617,11 @@ export function FileCard({
|
||||
)}
|
||||
</div>
|
||||
{fields && fields.length > 0 && (
|
||||
<div className="space-y-2 border-t p-1 pt-3 mx-2">
|
||||
<div
|
||||
className="space-y-2 border-t p-1 pt-3 mx-2"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
onDoubleClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{fields.map((field) => {
|
||||
const Icon = field.config?.type
|
||||
? FIELD_TYPE_ICONS[field.config.type as FieldType]
|
||||
|
||||
@@ -147,4 +147,40 @@ describe('FileListItem', () => {
|
||||
expect(failedLabel).toBeTruthy()
|
||||
expect(failedLabel.textContent).toMatch(/Processing failed|处理失败/i)
|
||||
})
|
||||
|
||||
it('does not trigger onSelect when clicking a custom field in list view', () => {
|
||||
const onSelect = vi.fn()
|
||||
const itemWithFields: AssetInfo = {
|
||||
...mockItem,
|
||||
fieldValues: [
|
||||
{
|
||||
fieldId: 'field_text',
|
||||
value: 'List text value',
|
||||
},
|
||||
],
|
||||
} as AssetInfo
|
||||
|
||||
const fields = [
|
||||
{
|
||||
id: 'field_text',
|
||||
name: 'Custom Column',
|
||||
scope: 'project',
|
||||
readOnly: false,
|
||||
visible: true,
|
||||
description: '',
|
||||
config: {
|
||||
type: 'text' as const,
|
||||
name: 'Custom Column',
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
renderComponent({ item: itemWithFields, fields, onSelect })
|
||||
|
||||
const textField = screen.getByText('List text value')
|
||||
fireEvent.click(textField)
|
||||
|
||||
expect(screen.getByDisplayValue('List text value')).toBeTruthy()
|
||||
expect(onSelect).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -328,6 +328,8 @@ export function FileListItem({
|
||||
fields.map((field) => (
|
||||
<div
|
||||
key={field.id}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
onDoubleClick={(e) => e.stopPropagation()}
|
||||
className="px-4 py-2 truncate border-r shrink-0 flex items-center"
|
||||
style={{
|
||||
width: columnSizing?.[field.id!] || 150,
|
||||
|
||||
@@ -182,6 +182,7 @@ export function FileBrowserGridView({
|
||||
[rows],
|
||||
),
|
||||
overscan: 5,
|
||||
paddingEnd: 240,
|
||||
})
|
||||
|
||||
const virtualItems = rowVirtualizer.getVirtualItems()
|
||||
|
||||
@@ -332,6 +332,7 @@ export function FileBrowserListView({
|
||||
[items, folders, files],
|
||||
),
|
||||
overscan: 10,
|
||||
paddingEnd: 240,
|
||||
})
|
||||
|
||||
const virtualItems = rowVirtualizer.getVirtualItems()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/webui",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./index.html",
|
||||
|
||||
@@ -1 +1 @@
|
||||
export const APP_VERSION = '0.6.0'
|
||||
export const APP_VERSION = '0.6.1'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/workflow-core",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
|
||||
Reference in New Issue
Block a user