fix: show Note metadata in autocomplete

This commit is contained in:
lucaronin
2026-04-18 13:37:15 +02:00
parent ed9ceff1d2
commit b00183419e
6 changed files with 34 additions and 17 deletions

View File

@@ -658,7 +658,7 @@ describe('wikilink autocomplete', () => {
mockFilterSuggestionItems.mockImplementation((items: unknown[]) => items)
})
it('shows correct noteType and color for typed entries, neutral for untyped', async () => {
it('shows Note chips and icons for explicit Note entries while keeping untyped entries neutral', async () => {
const mixedEntries: VaultEntry[] = [
{ ...mockEntry, title: 'Test Project', filename: 'proj.md', path: '/vault/proj.md', isA: 'Project', aliases: [] },
{ ...mockEntry, title: 'Test Plain', filename: 'plain.md', path: '/vault/plain.md', isA: null, aliases: [] },
@@ -675,20 +675,24 @@ describe('wikilink autocomplete', () => {
/>
)
const items = await capturedGetItems!('Test')
// Typed entries should have noteType and color
// Typed entries should have noteType, color, and a left-side icon
const project = items.find((i: { title: string }) => i.title === 'Test Project')
expect(project).toBeDefined()
expect(project!.noteType).toBe('Project')
expect(project!.typeColor).toBeTruthy()
// Untyped entries (isA: null or 'Note') should have no noteType (grey/neutral)
expect(project!.TypeIcon).toBeTruthy()
const explicitNote = items.find((i: { title: string }) => i.title === 'Test Explicit')
expect(explicitNote).toBeDefined()
expect(explicitNote!.noteType).toBe('Note')
expect(explicitNote!.typeColor).toBeTruthy()
expect(explicitNote!.TypeIcon).toBeTruthy()
// Untyped entries should remain neutral
const plainNote = items.find((i: { title: string }) => i.title === 'Test Plain')
expect(plainNote).toBeDefined()
expect(plainNote!.noteType).toBeUndefined()
expect(plainNote!.typeColor).toBeUndefined()
const explicitNote = items.find((i: { title: string }) => i.title === 'Test Explicit')
expect(explicitNote).toBeDefined()
expect(explicitNote!.noteType).toBeUndefined()
expect(explicitNote!.typeColor).toBeUndefined()
mockFilterSuggestionItems.mockImplementation((items: unknown[]) => items)
})

View File

@@ -179,6 +179,7 @@ export function SingleEditorView({ editor, entries, onNavigateWikilink, onChange
title: entry.title,
aliases: [...new Set([entry.filename.replace(/\.md$/, ''), ...entry.aliases])],
group: entry.isA || 'Note',
entryType: entry.isA,
entryTitle: entry.title,
path: entry.path,
}))),

View File

@@ -99,6 +99,7 @@ describe('buildRawEditorBaseItems', () => {
title: 'Project Alpha',
aliases: ['project-alpha', 'Alpha'],
group: 'Project',
entryType: 'Project',
entryTitle: 'Project Alpha',
path: 'projects/project-alpha.md',
},

View File

@@ -8,6 +8,7 @@ export interface RawEditorBaseItem {
title: string
aliases: string[]
group: string
entryType?: string | null
entryTitle: string
path: string
}
@@ -59,6 +60,7 @@ export function buildRawEditorBaseItems(entries: VaultEntry[]): RawEditorBaseIte
title: entry.title,
aliases: [...new Set([entry.filename.replace(/\.md$/, ''), ...entry.aliases])],
group: entry.isA || 'Note',
entryType: entry.isA,
entryTitle: entry.title,
path: entry.path,
})))

View File

@@ -76,8 +76,8 @@ describe('enrichSuggestionItems', () => {
Project: makeEntry({ isA: 'Type', title: 'Project', color: 'blue', icon: 'wrench' }),
}
function makeItem(title: string, group: string, path: string) {
return { title, aliases: [] as string[], group, entryTitle: title, path, onItemClick: vi.fn() }
function makeItem(title: string, group: string, path: string, entryType?: string | null) {
return { title, aliases: [] as string[], group, entryType, entryTitle: title, path, onItemClick: vi.fn() }
}
it('filters items by query', () => {
@@ -88,7 +88,7 @@ describe('enrichSuggestionItems', () => {
})
it('adds type metadata for non-Note groups', () => {
const items = [makeItem('My Project', 'Project', '/p.md')]
const items = [makeItem('My Project', 'Project', '/p.md', 'Project')]
const result = enrichSuggestionItems(items, '', typeEntryMap)
expect(result[0].noteType).toBe('Project')
expect(result[0].typeColor).toBeDefined()
@@ -96,7 +96,15 @@ describe('enrichSuggestionItems', () => {
expect(result[0].TypeIcon).toBeDefined()
})
it('omits type metadata for Note group', () => {
it('preserves Note type metadata for explicit Note entries', () => {
const items = [makeItem('Explicit Note', 'Note', '/n.md', 'Note')]
const result = enrichSuggestionItems(items, '', {})
expect(result[0].noteType).toBe('Note')
expect(result[0].typeColor).toBeDefined()
expect(result[0].TypeIcon).toBeDefined()
})
it('keeps untyped Note-group entries neutral', () => {
const items = [makeItem('Plain Note', 'Note', '/n.md')]
const result = enrichSuggestionItems(items, '', {})
expect(result[0].noteType).toBeUndefined()

View File

@@ -13,6 +13,7 @@ interface BaseSuggestionItem {
title: string
aliases: string[]
group: string
entryType?: string | null
entryTitle: string
path: string
}
@@ -48,15 +49,15 @@ export function enrichSuggestionItems(
)
const sliced = filtered.slice(0, MAX_RESULTS)
const final = disambiguateTitles(deduplicateByPath(sliced))
return final.map(({ group, ...rest }) => {
const noteType = group !== 'Note' ? group : undefined
const te = typeEntryMap[group]
return final.map(({ entryType, ...rest }) => {
const noteType = entryType ?? undefined
const te = noteType ? typeEntryMap[noteType] : undefined
return {
...rest,
noteType,
typeColor: noteType ? getTypeColor(group, te?.color) : undefined,
typeLightColor: noteType ? getTypeLightColor(group, te?.color) : undefined,
TypeIcon: noteType ? getTypeIcon(group, te?.icon) : undefined,
typeColor: noteType ? getTypeColor(noteType, te?.color) : undefined,
typeLightColor: noteType ? getTypeLightColor(noteType, te?.color) : undefined,
TypeIcon: noteType ? getTypeIcon(noteType, te?.icon) : undefined,
}
})
}