diff --git a/src/components/note-list/noteListHooks.extra.test.tsx b/src/components/note-list/noteListHooks.extra.test.tsx index 28912c33..d6270e4e 100644 --- a/src/components/note-list/noteListHooks.extra.test.tsx +++ b/src/components/note-list/noteListHooks.extra.test.tsx @@ -217,6 +217,32 @@ describe('noteListHooks extra', () => { expect(result.current.sortPrefs.__list__).toEqual({ option: 'title', direction: 'asc' }) }) + it('uses shorthand type sort fields as custom properties', () => { + const typeDocument = makeEntry({ + path: '/vault/types/memory.md', + filename: 'memory.md', + title: 'Memory', + isA: 'Type', + sort: 'date:desc', + }) + const memoryEntry = makeEntry({ + isA: 'Memory', + properties: { date: '2026-05-06' }, + }) + + const { result } = renderHook(() => + useNoteListSort({ + entries: [typeDocument, memoryEntry], + selection: { kind: 'sectionGroup', type: 'Memory', label: 'Memory' }, + modifiedPathSet: new Set(), + modifiedSuffixes: [], + }), + ) + + expect(result.current.listSort).toBe('property:date') + expect(result.current.listDirection).toBe('desc') + }) + it('prefers selected view sort config and persists list sort changes back to the view definition', () => { const onUpdateViewDefinition = vi.fn() const view: ViewFile = { diff --git a/src/utils/noteListHelpers.extra.test.ts b/src/utils/noteListHelpers.extra.test.ts index 448667a8..0f398029 100644 --- a/src/utils/noteListHelpers.extra.test.ts +++ b/src/utils/noteListHelpers.extra.test.ts @@ -147,6 +147,7 @@ describe('noteListHelpers extra coverage', () => { const serialized = serializeSortConfig({ option: 'property:Priority', direction: 'desc' }) expect(serialized).toBe('property:Priority:desc') expect(parseSortConfig(serialized)).toEqual({ option: 'property:Priority', direction: 'desc' }) + expect(parseSortConfig('date:desc')).toEqual({ option: 'property:date', direction: 'desc' }) expect(parseSortConfig('broken')).toBeNull() expect(parseSortConfig('title:sideways')).toBeNull() diff --git a/src/utils/noteListHelpers.ts b/src/utils/noteListHelpers.ts index edfaefc6..b38be037 100644 --- a/src/utils/noteListHelpers.ts +++ b/src/utils/noteListHelpers.ts @@ -117,6 +117,7 @@ export interface SortConfig { } export const DEFAULT_SORT_OPTIONS: SortOption[] = ['modified', 'created', 'title', 'status'] +const BUILT_IN_SORT_OPTIONS = new Set(DEFAULT_SORT_OPTIONS) export function getDefaultDirection(option: SortOption): SortDirection { if (option === 'modified' || option === 'created') return 'desc' @@ -217,7 +218,12 @@ export function parseSortConfig(raw: string | null | undefined): SortConfig | nu if (lastColon <= 0) return null const dir = raw.slice(lastColon + 1) if (dir !== 'asc' && dir !== 'desc') return null - const option = raw.slice(0, lastColon) as SortOption + const optionName = raw.slice(0, lastColon) + const option = ( + optionName.startsWith('property:') || BUILT_IN_SORT_OPTIONS.has(optionName) + ? optionName + : `property:${optionName}` + ) as SortOption return { option, direction: dir } }