fix: handle shorthand type sort fields
This commit is contained in:
@@ -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<string>(),
|
||||
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 = {
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -117,6 +117,7 @@ export interface SortConfig {
|
||||
}
|
||||
|
||||
export const DEFAULT_SORT_OPTIONS: SortOption[] = ['modified', 'created', 'title', 'status']
|
||||
const BUILT_IN_SORT_OPTIONS = new Set<string>(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 }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user