2026-04-06 16:31:51 +02:00
|
|
|
import { useMemo, useCallback, useRef, useEffect } from 'react'
|
2026-02-17 12:12:32 +01:00
|
|
|
import type { VaultEntry } from '../types'
|
|
|
|
|
import type { FrontmatterValue } from './Inspector'
|
|
|
|
|
import type { ParsedFrontmatter } from '../utils/frontmatter'
|
2026-03-05 07:11:33 +01:00
|
|
|
import { usePropertyPanelState } from '../hooks/usePropertyPanelState'
|
2026-03-16 07:25:40 +01:00
|
|
|
import { getEffectiveDisplayMode, detectPropertyType } from '../utils/propertyTypes'
|
|
|
|
|
import { SmartPropertyValueCell, DisplayModeSelector } from './PropertyValueCells'
|
|
|
|
|
import { TypeSelector } from './TypeSelector'
|
|
|
|
|
import { AddPropertyForm } from './AddPropertyForm'
|
|
|
|
|
import type { PropertyDisplayMode } from '../utils/propertyTypes'
|
2026-02-17 12:12:32 +01:00
|
|
|
|
2026-03-29 16:36:31 +02:00
|
|
|
function toSentenceCase(key: string): string {
|
|
|
|
|
const spaced = key.replace(/[_-]/g, ' ')
|
|
|
|
|
if (!spaced) return spaced
|
|
|
|
|
return spaced.charAt(0).toUpperCase() + spaced.slice(1)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-22 13:11:38 +01:00
|
|
|
// eslint-disable-next-line react-refresh/only-export-components -- utility co-located with component
|
2026-02-17 12:12:32 +01:00
|
|
|
export function containsWikilinks(value: FrontmatterValue): boolean {
|
|
|
|
|
if (typeof value === 'string') return /^\[\[.*\]\]$/.test(value)
|
|
|
|
|
if (Array.isArray(value)) return value.some(v => typeof v === 'string' && /^\[\[.*\]\]$/.test(v))
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-27 16:20:31 +01:00
|
|
|
function PropertyRow({ propKey, value, editingKey, displayMode, autoMode, vaultStatuses, vaultTags, onStartEdit, onSave, onSaveList, onUpdate, onDelete, onDisplayModeChange }: {
|
2026-02-22 10:55:45 +01:00
|
|
|
propKey: string; value: FrontmatterValue; editingKey: string | null
|
feat: smart property display — type-aware rendering with display mode override (#83)
* design: add smart property display wireframes
Frames: date picker, boolean toggle, status badge, display mode override dropdown.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* feat: smart property display — type-aware rendering with display mode override
- Add property type auto-detection (date, boolean, status, url, text) based on value content and property name
- Date properties (ISO strings) show as friendly format (e.g. "Mar 31, 2026") with native date picker on click
- Boolean properties show as toggle buttons
- Status properties auto-detected from key name or known status values, rendered as colored badges
- Each property gets a display mode override dropdown (visible on hover) to force a specific display type
- Display mode overrides persist across sessions via localStorage
- Add mock data with date/boolean fields for testing
- 36 new tests covering type detection, date formatting, localStorage persistence, and UI rendering
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 01:12:40 +01:00
|
|
|
displayMode: PropertyDisplayMode; autoMode: PropertyDisplayMode
|
2026-02-28 12:34:01 +01:00
|
|
|
vaultStatuses: string[]; vaultTags: string[]
|
2026-02-22 10:55:45 +01:00
|
|
|
onStartEdit: (key: string | null) => void; onSave: (key: string, value: string) => void
|
|
|
|
|
onSaveList: (key: string, items: string[]) => void
|
|
|
|
|
onUpdate?: (key: string, value: FrontmatterValue) => void; onDelete?: (key: string) => void
|
feat: smart property display — type-aware rendering with display mode override (#83)
* design: add smart property display wireframes
Frames: date picker, boolean toggle, status badge, display mode override dropdown.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* feat: smart property display — type-aware rendering with display mode override
- Add property type auto-detection (date, boolean, status, url, text) based on value content and property name
- Date properties (ISO strings) show as friendly format (e.g. "Mar 31, 2026") with native date picker on click
- Boolean properties show as toggle buttons
- Status properties auto-detected from key name or known status values, rendered as colored badges
- Each property gets a display mode override dropdown (visible on hover) to force a specific display type
- Display mode overrides persist across sessions via localStorage
- Add mock data with date/boolean fields for testing
- 36 new tests covering type detection, date formatting, localStorage persistence, and UI rendering
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 01:12:40 +01:00
|
|
|
onDisplayModeChange: (key: string, mode: PropertyDisplayMode | null) => void
|
2026-02-22 10:55:45 +01:00
|
|
|
}) {
|
feat: keyboard-first navigation — menu bar shortcuts, note list nav, inspector Tab/Enter (#158)
* feat: keyboard-first navigation — menu bar shortcuts, note list nav, inspector Tab/Enter
- Add missing menu bar items: Archive Note (⌘E), Trash Note (⌘⌫),
Find in Vault (⌘⇧F), Go Back (⌘[), Go Forward (⌘])
- Wire new menu events through useMenuEvents → useAppCommands
- Note list: ↑↓ moves highlight, Enter opens selected note (useNoteListKeyboard hook)
- Inspector properties: Tab between rows, Enter to start editing
- Settings panel: auto-focus first input on open
- Extract StatusDot, StateBadge, noteItemStyle from NoteItem (reduces complexity)
- Extract dispatchActiveTabEvent/dispatchOptionalEvent from useMenuEvents
- 21 new tests (useNoteListKeyboard + useMenuEvents for new events)
- All 1275 frontend tests pass, 319 Rust tests pass
- CodeScene quality gates: passed (NoteItem improved from 22→18 complexity)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* design: keyboard-first-nav wireframes (note list highlight, menu shortcuts, inspector tab nav)
* test: add search.rs coverage for fallback branches (qmd_uri_to_vault_path, extract_clean_snippet)
* chore: exclude search.rs and lib.rs from coverage (qmd integration + Tauri setup code)
---------
Co-authored-by: Test <test@test.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 19:32:15 +01:00
|
|
|
const handleKeyDown = (e: React.KeyboardEvent) => {
|
|
|
|
|
if (e.key === 'Enter' && editingKey !== propKey) {
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
onStartEdit(propKey)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-22 10:55:45 +01:00
|
|
|
return (
|
2026-03-31 16:30:22 +02:00
|
|
|
<div className="group/prop grid min-h-7 min-w-0 grid-cols-2 items-center gap-2 rounded px-1.5 outline-none transition-colors hover:bg-muted focus:bg-muted focus:ring-1 focus:ring-primary" tabIndex={0} onKeyDown={handleKeyDown} data-testid="editable-property">
|
2026-03-29 16:36:31 +02:00
|
|
|
<span className="flex min-w-0 items-center gap-1 text-[12px] text-muted-foreground">
|
|
|
|
|
<span className="truncate">{toSentenceCase(propKey)}</span>
|
2026-02-22 10:55:45 +01:00
|
|
|
{onDelete && (
|
|
|
|
|
<button className="border-none bg-transparent p-0 text-sm leading-none text-muted-foreground opacity-0 transition-all hover:text-destructive group-hover/prop:opacity-100" onClick={() => onDelete(propKey)} title="Delete property">×</button>
|
|
|
|
|
)}
|
feat: smart property display — type-aware rendering with display mode override (#83)
* design: add smart property display wireframes
Frames: date picker, boolean toggle, status badge, display mode override dropdown.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* feat: smart property display — type-aware rendering with display mode override
- Add property type auto-detection (date, boolean, status, url, text) based on value content and property name
- Date properties (ISO strings) show as friendly format (e.g. "Mar 31, 2026") with native date picker on click
- Boolean properties show as toggle buttons
- Status properties auto-detected from key name or known status values, rendered as colored badges
- Each property gets a display mode override dropdown (visible on hover) to force a specific display type
- Display mode overrides persist across sessions via localStorage
- Add mock data with date/boolean fields for testing
- 36 new tests covering type detection, date formatting, localStorage persistence, and UI rendering
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 01:12:40 +01:00
|
|
|
<DisplayModeSelector propKey={propKey} currentMode={displayMode} autoMode={autoMode} onSelect={onDisplayModeChange} />
|
2026-02-22 10:55:45 +01:00
|
|
|
</span>
|
2026-03-20 20:27:36 +01:00
|
|
|
<div className="min-w-0">
|
2026-03-19 06:57:11 +01:00
|
|
|
<SmartPropertyValueCell propKey={propKey} value={value} displayMode={displayMode} isEditing={editingKey === propKey} vaultStatuses={vaultStatuses} vaultTags={vaultTags} onStartEdit={onStartEdit} onSave={onSave} onSaveList={onSaveList} onUpdate={onUpdate} />
|
|
|
|
|
</div>
|
2026-02-22 10:55:45 +01:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function AddPropertyButton({ onClick, disabled }: { onClick: () => void; disabled: boolean }) {
|
|
|
|
|
return (
|
|
|
|
|
<button
|
2026-03-29 16:36:31 +02:00
|
|
|
className="mt-1 flex w-full cursor-pointer items-center gap-1 border-none bg-transparent px-1.5 text-[12px] text-muted-foreground opacity-50 transition-opacity hover:opacity-100 disabled:cursor-not-allowed"
|
2026-02-22 10:55:45 +01:00
|
|
|
onClick={onClick} disabled={disabled}
|
2026-03-29 16:36:31 +02:00
|
|
|
>
|
|
|
|
|
<span className="text-[12px] leading-none">+</span>
|
|
|
|
|
Add property
|
|
|
|
|
</button>
|
2026-02-22 10:55:45 +01:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-04 15:42:10 +02:00
|
|
|
const SUGGESTED_PROPERTIES = ['Status', 'Date', 'URL'] as const
|
|
|
|
|
|
|
|
|
|
function SuggestedPropertySlot({ label, onAdd }: { label: string; onAdd: () => void }) {
|
|
|
|
|
return (
|
|
|
|
|
<button
|
2026-04-05 14:27:08 +02:00
|
|
|
className="grid min-h-7 min-w-0 grid-cols-2 items-center gap-2 rounded border-none bg-transparent px-1.5 text-left outline-none transition-colors hover:bg-muted focus:bg-muted focus:ring-1 focus:ring-primary cursor-pointer"
|
2026-04-04 15:42:10 +02:00
|
|
|
tabIndex={0}
|
|
|
|
|
onClick={onAdd}
|
|
|
|
|
onKeyDown={e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); onAdd() } }}
|
|
|
|
|
data-testid="suggested-property"
|
|
|
|
|
>
|
|
|
|
|
<span className="min-w-0 truncate text-[12px] text-muted-foreground/50">{label}</span>
|
2026-04-05 14:27:08 +02:00
|
|
|
<span className="min-w-0 truncate text-[12px] text-muted-foreground/30">{'\u2014'}</span>
|
2026-04-04 15:42:10 +02:00
|
|
|
</button>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-27 12:59:23 +01:00
|
|
|
export function DynamicPropertiesPanel({
|
2026-04-04 15:15:43 +02:00
|
|
|
entry, frontmatter, entries,
|
2026-02-27 12:59:23 +01:00
|
|
|
onUpdateProperty, onDeleteProperty, onAddProperty, onNavigate,
|
|
|
|
|
}: {
|
|
|
|
|
entry: VaultEntry
|
2026-04-04 15:15:43 +02:00
|
|
|
content?: string | null
|
2026-02-27 12:59:23 +01:00
|
|
|
frontmatter: ParsedFrontmatter
|
|
|
|
|
entries?: VaultEntry[]
|
|
|
|
|
onUpdateProperty?: (key: string, value: FrontmatterValue) => void
|
|
|
|
|
onDeleteProperty?: (key: string) => void
|
|
|
|
|
onAddProperty?: (key: string, value: FrontmatterValue) => void
|
|
|
|
|
onNavigate?: (target: string) => void
|
|
|
|
|
}) {
|
|
|
|
|
const {
|
|
|
|
|
editingKey, setEditingKey, showAddDialog, setShowAddDialog, displayOverrides,
|
2026-02-28 20:01:56 +01:00
|
|
|
availableTypes, customColorKey, typeColorKeys, typeIconKeys, vaultStatuses, vaultTagsByKey, propertyEntries,
|
2026-02-27 12:59:23 +01:00
|
|
|
handleSaveValue, handleSaveList, handleAdd, handleDisplayModeChange,
|
2026-03-08 22:15:08 +01:00
|
|
|
} = usePropertyPanelState({ entries, entryIsA: entry.isA, frontmatter, onUpdateProperty, onDeleteProperty, onAddProperty })
|
2026-02-27 12:59:23 +01:00
|
|
|
|
2026-04-04 15:42:10 +02:00
|
|
|
const existingKeys = useMemo(() => {
|
|
|
|
|
const keys = new Set(propertyEntries.map(([k]) => k.toLowerCase()))
|
|
|
|
|
// Also check full frontmatter for relationship keys that are filtered out of propertyEntries
|
|
|
|
|
for (const k of Object.keys(frontmatter)) keys.add(k.toLowerCase())
|
|
|
|
|
return keys
|
|
|
|
|
}, [propertyEntries, frontmatter])
|
|
|
|
|
|
|
|
|
|
const missingSuggested = onAddProperty
|
|
|
|
|
? SUGGESTED_PROPERTIES.filter(p => !existingKeys.has(p.toLowerCase()))
|
|
|
|
|
: []
|
|
|
|
|
|
2026-04-06 16:31:51 +02:00
|
|
|
const pendingEditKeyRef = useRef<string | null>(null)
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (pendingEditKeyRef.current && propertyEntries.some(([k]) => k === pendingEditKeyRef.current)) {
|
|
|
|
|
setEditingKey(pendingEditKeyRef.current)
|
|
|
|
|
pendingEditKeyRef.current = null
|
|
|
|
|
}
|
|
|
|
|
}, [propertyEntries, setEditingKey])
|
|
|
|
|
|
2026-04-04 15:42:10 +02:00
|
|
|
const handleSuggestedAdd = useCallback((key: string) => {
|
|
|
|
|
if (!onAddProperty) return
|
2026-04-06 16:31:51 +02:00
|
|
|
pendingEditKeyRef.current = key
|
2026-04-04 15:42:10 +02:00
|
|
|
onAddProperty(key, '')
|
2026-04-06 16:31:51 +02:00
|
|
|
}, [onAddProperty])
|
2026-04-04 15:42:10 +02:00
|
|
|
|
2026-02-17 12:12:32 +01:00
|
|
|
return (
|
2026-02-23 15:19:57 +01:00
|
|
|
<div className="flex flex-col gap-3">
|
2026-03-19 07:56:26 +01:00
|
|
|
<div className="flex flex-col gap-1.5">
|
2026-02-28 20:01:56 +01:00
|
|
|
<TypeSelector isA={entry.isA} customColorKey={customColorKey} availableTypes={availableTypes} typeColorKeys={typeColorKeys} typeIconKeys={typeIconKeys} onUpdateProperty={onUpdateProperty} onNavigate={onNavigate} />
|
2026-02-27 12:59:23 +01:00
|
|
|
{propertyEntries.map(([key, value]) => (
|
|
|
|
|
<PropertyRow
|
|
|
|
|
key={key} propKey={key} value={value}
|
|
|
|
|
editingKey={editingKey} displayMode={getEffectiveDisplayMode(key, value, displayOverrides)} autoMode={detectPropertyType(key, value)}
|
|
|
|
|
vaultStatuses={vaultStatuses}
|
2026-02-28 12:34:01 +01:00
|
|
|
vaultTags={vaultTagsByKey[key] ?? []}
|
2026-02-27 12:59:23 +01:00
|
|
|
onStartEdit={setEditingKey} onSave={handleSaveValue}
|
|
|
|
|
onSaveList={handleSaveList} onUpdate={onUpdateProperty}
|
|
|
|
|
onDelete={onDeleteProperty}
|
|
|
|
|
onDisplayModeChange={handleDisplayModeChange}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
2026-04-04 15:42:10 +02:00
|
|
|
{missingSuggested.map(key => (
|
|
|
|
|
<SuggestedPropertySlot key={key} label={key} onAdd={() => handleSuggestedAdd(key)} />
|
|
|
|
|
))}
|
2026-02-17 12:12:32 +01:00
|
|
|
</div>
|
2026-02-22 10:55:45 +01:00
|
|
|
{showAddDialog
|
2026-02-27 12:59:23 +01:00
|
|
|
? <AddPropertyForm onAdd={handleAdd} onCancel={() => setShowAddDialog(false)} vaultStatuses={vaultStatuses} />
|
2026-02-22 10:55:45 +01:00
|
|
|
: <AddPropertyButton onClick={() => setShowAddDialog(true)} disabled={!onAddProperty} />
|
|
|
|
|
}
|
2026-02-17 12:12:32 +01:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|