97907a5a5c
* fix: article number ordering, free-text rows, invoice back-nav, onboarding resilience (#1053) Four fixes from Discord feedback in issue #1053: - Articles now order by article number with numeric-aware comparison ('2' before '10', unnumbered last, name tiebreak) in the invoice editor's article picker and as the register's default sort, via a shared lib/articles/sort.ts. Name order put article "1" last. - Invoice rows with no amounts (quantity 0, unit price 0) render as pure text rows on the PDF, the invoice detail page, and the review step via shared isTextLikeLine(), instead of printing "0 / 0,00 SEK / 0,00 SEK". Display-only; booking untouched. - The invoice editor navigates with router.replace after saving, so the detail page's back arrow returns to the list instead of reopening a fresh editor from history. - A transient query failure no longer reads as "no companies" / "onboarding not done": getActiveCompanyId throws CompanyContextError('resolution_failed') instead of returning null, the Edge middleware fails open on a degraded resolution (no onboarding redirect, no cookie clearing, no locale overwrite), and the dashboard page only redirects to /onboarding on a positively read incomplete/missing settings row. This is the likely cause of the completed onboarding wizard reappearing. Fixes #1053 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * docs: CLAUDE.md tenancy line matches actual resolution order (prefs-first, cookie not read) The middleware stopped reading the gnubok-company-id cookie when user_preferences became authoritative (RLS parity); the stale doc line still described cookie-first order and misled review tooling. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
32 lines
1012 B
TypeScript
32 lines
1012 B
TypeScript
/**
|
|
* Canonical ordering for article lists and pickers: by article number with
|
|
* numeric-aware comparison ('2' before '10'), articles without a number last,
|
|
* name as tie-breaker. Users number their articles to control this order
|
|
* (issue #1053), so a plain string sort ('10' < '2') or name sort breaks it.
|
|
*/
|
|
|
|
interface SortableArticle {
|
|
article_number?: string | null
|
|
name: string
|
|
}
|
|
|
|
const numberCollator = new Intl.Collator('sv', { numeric: true, sensitivity: 'base' })
|
|
|
|
export function compareArticles(a: SortableArticle, b: SortableArticle): number {
|
|
const aNum = a.article_number?.trim()
|
|
const bNum = b.article_number?.trim()
|
|
if (aNum && bNum) {
|
|
const byNumber = numberCollator.compare(aNum, bNum)
|
|
if (byNumber !== 0) return byNumber
|
|
} else if (aNum) {
|
|
return -1
|
|
} else if (bNum) {
|
|
return 1
|
|
}
|
|
return numberCollator.compare(a.name, b.name)
|
|
}
|
|
|
|
export function sortArticles<T extends SortableArticle>(articles: T[]): T[] {
|
|
return [...articles].sort(compareArticles)
|
|
}
|