mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-19 14:16:29 +00:00
fix(webui): prevent clipping of long text overlay and date picker in cards (#490)
* fix(webui): prevent clipping of long text overlay and date picker in cards * docs: update DeepWiki badge url in README and README_CN * fix(webui): preserve expanded overlay height and textarea style in LongTextField * fix(webui): add bottom padding to file list to prevent screen clipping of expanded fields * fix(webui): expand directly into edit mode on single click for LongTextField * fix(webui): prevent file selection when interacting with metadata fields in cards and list rows
This commit is contained in:
@@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
|
||||
* **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
|
||||
|
||||
## [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">
|
||||
|
||||
+1
-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">
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user