fix: preserve exact linked note titles

This commit is contained in:
lucaronin
2026-04-14 17:32:47 +02:00
parent 9041246a32
commit 084d3d9c71
4 changed files with 65 additions and 5 deletions

View File

@@ -240,11 +240,47 @@ describe('NoteItem', () => {
)
const chip = screen.getByTestId('property-chip-topics-0')
expect(chip).toHaveTextContent('Ai')
expect(chip).toHaveTextContent('AI')
expect(chip).toHaveStyle({ color: 'var(--accent-green)', backgroundColor: 'var(--accent-green-light)' })
expect(chip.querySelector('svg')).not.toBeNull()
})
it('preserves exact linked note title formatting in relationship chips', () => {
const linkedTopic = makeEntry({
path: '/vault/topic/ai-ml.md',
filename: 'ai-ml.md',
title: 'AI / ML',
isA: 'Topic',
})
const topicType = makeEntry({
path: '/vault/type/topic.md',
filename: 'topic.md',
title: 'Topic',
isA: 'Type',
color: 'green',
})
const sourceEntry = makeEntry({
path: '/vault/note/source.md',
filename: 'source.md',
title: 'Source',
isA: 'Note',
relationships: { Topics: ['[[topic/ai-ml]]'] },
})
render(
<NoteItem
entry={sourceEntry}
isSelected={false}
typeEntryMap={{ Topic: topicType }}
allEntries={[sourceEntry, linkedTopic, topicType]}
displayPropsOverride={['Topics']}
onClickNote={vi.fn()}
/>,
)
expect(screen.getByTestId('property-chip-topics-0')).toHaveTextContent('AI / ML')
})
it('opens URL chips on Cmd+click only and keeps regular clicks inert', () => {
const entry = makeEntry({
path: '/vault/note/source.md',

View File

@@ -0,0 +1,25 @@
import { describe, expect, it } from 'vitest'
import { makeEntry } from '../../test-utils/noteListTestUtils'
import { resolveRefProps } from './shared'
describe('resolveRefProps', () => {
it('uses the resolved entry title for relationship labels', () => {
const linkedTopic = makeEntry({
path: '/vault/topic/ai-ml.md',
filename: 'ai-ml.md',
title: 'AI / ML',
isA: 'Topic',
})
const topicType = makeEntry({
path: '/vault/type/topic.md',
filename: 'topic.md',
title: 'Topic',
isA: 'Type',
color: 'green',
})
const props = resolveRefProps('[[topic/ai-ml]]', [linkedTopic, topicType], { Topic: topicType })
expect(props.label).toBe('AI / ML')
})
})

View File

@@ -31,7 +31,7 @@ export function resolveRefProps(ref: string, entries: VaultEntry[], typeEntryMap
const te = typeEntryMap[refType ?? '']
const icon = resolved?.icon
return {
label: wikilinkDisplay(ref),
label: resolved?.title ?? wikilinkDisplay(ref),
noteIcon: icon ?? null,
typeColor: getTypeColor(refType, te?.color),
bgColor: getTypeLightColor(refType, te?.color),

View File

@@ -71,10 +71,9 @@ function resolveRelationshipChip(
allEntries: VaultEntry[],
typeEntryMap: Record<string, VaultEntry>,
): PropertyChipValue | null {
const label = wikilinkDisplay(ref)
if (!label) return null
const targetEntry = resolveEntry(allEntries, wikilinkTarget(ref))
const label = targetEntry?.title ?? wikilinkDisplay(ref)
if (!label) return null
if (!targetEntry) {
return {
label,