fix(shell): share ext family between recents and starred filters (#357)
* fix(shell): share ext family between recents and starred filters * fix(sheets): satisfy exactOptionalPropertyTypes for LazyCellMatch rawValue --------- Co-authored-by: Aniruddha Adak <aniruddhaadak80@users.noreply.github.com>
This commit is contained in:
co-authored by
Aniruddha Adak
parent
af9a63e462
commit
6797e48c15
@@ -222,7 +222,12 @@ import {
|
||||
import type { TabKind } from '../shared/tabs-api'
|
||||
import { TABS_CHANNELS } from '../shared/tabs-api'
|
||||
import { showErrorDialog } from './error-dialog'
|
||||
import { normalizeRecentQuery, pageRecentPaths, statPathEntries } from './recent-files'
|
||||
import {
|
||||
matchesExtFamily,
|
||||
normalizeRecentQuery,
|
||||
pageRecentPaths,
|
||||
statPathEntries,
|
||||
} from './recent-files'
|
||||
import { isSameFile, isValidRenameName } from './rename-validation'
|
||||
import { runHeadlessExport, type HeadlessExporters } from './headless-export'
|
||||
import { TabManager } from './tab-manager'
|
||||
@@ -2981,7 +2986,7 @@ function registerHomeIpc(): void {
|
||||
ipcMain.handle(HOME_CHANNELS.starred, (_event, query: unknown): RecentPage => {
|
||||
const { offset, limit, ext } = normalizeRecentQuery(query)
|
||||
const all = statEntries(readStarredFiles()).sort((a, b) => b.mtimeMs - a.mtimeMs)
|
||||
const filtered = ext ? all.filter((entry) => entry.ext === ext) : all
|
||||
const filtered = ext ? all.filter((entry) => matchesExtFamily(entry.ext, ext)) : all
|
||||
return {
|
||||
entries: limit === 0 ? [] : filtered.slice(offset, offset + limit),
|
||||
total: filtered.length,
|
||||
|
||||
@@ -58,11 +58,17 @@ export function normalizeRecentQuery(
|
||||
}
|
||||
|
||||
/** sidebar filter keys that stand for a family of extensions, not one exact ext */
|
||||
const EXT_FAMILY: Record<string, readonly string[]> = {
|
||||
export const EXT_FAMILY: Record<string, readonly string[]> = {
|
||||
xlsx: ['xlsx', 'xlsm', 'xls'],
|
||||
html: ['html', 'htm'],
|
||||
}
|
||||
|
||||
/** Family-aware extension match for sidebar filters (recents and starred share it). */
|
||||
export function matchesExtFamily(entryExt: string, filterExt: string): boolean {
|
||||
const family = EXT_FAMILY[filterExt]
|
||||
return family ? family.includes(entryExt) : entryExt === filterExt
|
||||
}
|
||||
|
||||
/** Page over the recents paths, preserving the source's newest-first order (unavailable paths stay, flagged missing). */
|
||||
export function pageRecentPaths(
|
||||
paths: readonly string[],
|
||||
@@ -71,8 +77,7 @@ export function pageRecentPaths(
|
||||
): RecentPage {
|
||||
const { offset, limit, ext } = normalizeRecentQuery(raw)
|
||||
const all = statPathEntries(paths, starredPaths)
|
||||
const family = ext ? (EXT_FAMILY[ext] ?? [ext]) : undefined
|
||||
const filtered = family ? all.filter((entry) => family.includes(entry.ext)) : all
|
||||
const filtered = ext ? all.filter((entry) => matchesExtFamily(entry.ext, ext)) : all
|
||||
return {
|
||||
entries: limit === 0 ? [] : filtered.slice(offset, offset + limit),
|
||||
total: filtered.length,
|
||||
|
||||
@@ -116,6 +116,26 @@ describe('recent query ext normalization', () => {
|
||||
expect(page.total).toBe(1)
|
||||
expect(page.entries.map((entry) => entry.path)).toEqual([bookPath])
|
||||
})
|
||||
|
||||
it('shares the sheets/html families with the starred view (same helper)', () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), 'shell-counts-'))
|
||||
tempDirs.push(dir)
|
||||
const htmPath = join(dir, 'page.htm')
|
||||
const htmlPath = join(dir, 'page.html')
|
||||
const legacyPath = join(dir, 'legacy.xls')
|
||||
writeFileSync(htmPath, 'html')
|
||||
writeFileSync(htmlPath, 'html')
|
||||
writeFileSync(legacyPath, 'sheet')
|
||||
// pageRecentPaths is the recents helper; starred now calls the same
|
||||
// matchesExtFamily, so assert the family includes both spellings
|
||||
expect(
|
||||
pageRecentPaths([htmPath, legacyPath], { ext: 'html', limit: 50 }, new Set()).total,
|
||||
).toBe(1)
|
||||
expect(
|
||||
pageRecentPaths([htmPath, legacyPath], { ext: 'xlsx', limit: 50 }, new Set()).total,
|
||||
).toBe(1)
|
||||
expect(pageRecentPaths([htmlPath], { ext: 'htm', limit: 50 }, new Set()).total).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('count labels', () => {
|
||||
|
||||
Reference in New Issue
Block a user