Files
multica/packages/views/issues/utils/sort.ts
Naiyuan Qing bd1fb10afa chore: react-doctor cleanup — button types, useContext→use(), toSorted, error fixes (#3350)
- Add explicit type="button" to 61 <button> elements missing the attribute
- Replace useContext() with React 19 use() across 16 context consumers
- Replace [...arr].sort() with arr.toSorted() in 12 web/desktop files
  (mobile excluded — Hermes lacks toSorted support)
- Fix rules-of-hooks violation: useSidebar try/catch → useSidebarSafe null check
- Fix nested component definition: useMemo wrapping HeaderRight → useCallback
- Fix missing ARIA: add aria-expanded + aria-controls to combobox in create-squad

React Doctor score: 23 → 30. No behavioral changes, no business logic modified.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 14:57:07 +08:00

50 lines
1.5 KiB
TypeScript

import type { Issue } from "@multica/core/types";
import { PRIORITY_ORDER } from "@multica/core/issues/config";
import type { SortField, SortDirection } from "@multica/core/issues/stores/view-store";
const PRIORITY_RANK: Record<string, number> = Object.fromEntries(
PRIORITY_ORDER.map((p, i) => [p, i])
);
export function sortIssues(
issues: Issue[],
field: SortField,
direction: SortDirection
): Issue[] {
const sorted = issues.toSorted((a, b) => {
switch (field) {
case "priority":
return (
(PRIORITY_RANK[a.priority] ?? 99) -
(PRIORITY_RANK[b.priority] ?? 99)
);
case "start_date": {
if (!a.start_date && !b.start_date) return 0;
if (!a.start_date) return 1;
if (!b.start_date) return -1;
return (
new Date(a.start_date).getTime() - new Date(b.start_date).getTime()
);
}
case "due_date": {
if (!a.due_date && !b.due_date) return 0;
if (!a.due_date) return 1;
if (!b.due_date) return -1;
return (
new Date(a.due_date).getTime() - new Date(b.due_date).getTime()
);
}
case "created_at":
return (
new Date(a.created_at).getTime() - new Date(b.created_at).getTime()
);
case "title":
return a.title.localeCompare(b.title);
case "position":
default:
return a.position - b.position;
}
});
return direction === "desc" ? sorted.reverse() : sorted;
}