From b00183419e978daf6ec0f11d6eed7d29d429ecbc Mon Sep 17 00:00:00 2001 From: lucaronin Date: Sat, 18 Apr 2026 13:37:15 +0200 Subject: [PATCH] fix: show Note metadata in autocomplete --- src/components/Editor.test.tsx | 18 +++++++++++------- src/components/SingleEditorView.tsx | 1 + src/utils/rawEditorUtils.test.ts | 1 + src/utils/rawEditorUtils.ts | 2 ++ src/utils/suggestionEnrichment.test.ts | 16 ++++++++++++---- src/utils/suggestionEnrichment.ts | 13 +++++++------ 6 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/components/Editor.test.tsx b/src/components/Editor.test.tsx index cd11d50a..23880575 100644 --- a/src/components/Editor.test.tsx +++ b/src/components/Editor.test.tsx @@ -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) }) diff --git a/src/components/SingleEditorView.tsx b/src/components/SingleEditorView.tsx index 59a321ce..a37b678c 100644 --- a/src/components/SingleEditorView.tsx +++ b/src/components/SingleEditorView.tsx @@ -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, }))), diff --git a/src/utils/rawEditorUtils.test.ts b/src/utils/rawEditorUtils.test.ts index 00fed270..d6bce65f 100644 --- a/src/utils/rawEditorUtils.test.ts +++ b/src/utils/rawEditorUtils.test.ts @@ -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', }, diff --git a/src/utils/rawEditorUtils.ts b/src/utils/rawEditorUtils.ts index 1119e31e..9ec6dcb6 100644 --- a/src/utils/rawEditorUtils.ts +++ b/src/utils/rawEditorUtils.ts @@ -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, }))) diff --git a/src/utils/suggestionEnrichment.test.ts b/src/utils/suggestionEnrichment.test.ts index c3bf3075..65aa6ec4 100644 --- a/src/utils/suggestionEnrichment.test.ts +++ b/src/utils/suggestionEnrichment.test.ts @@ -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() diff --git a/src/utils/suggestionEnrichment.ts b/src/utils/suggestionEnrichment.ts index b72f21db..1883197e 100644 --- a/src/utils/suggestionEnrichment.ts +++ b/src/utils/suggestionEnrichment.ts @@ -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, } }) }