All files / src/lib triage-selection.ts

100% Statements 9/9
100% Branches 2/2
100% Functions 6/6
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26                              30x 75x   33x 33x 30x 23x 10x      
import type { Item, Disposition } from "@/types";
 
export interface TriageQueueEntry {
  item: Item;
  deferred: boolean;
}
 
// The whole eligible remainder for the feelings phase — untriaged, not set_aside;
// active items first, then deferred, each in today's input ordering. NO count
// parameter: every live piece passes through once (spec §4).
export function selectTriageQueue(
  items: Item[],
  preferenceItemIds: Set<string>,
  dispositionByItemId: Map<string, Disposition>,
): TriageQueueEntry[] {
  const candidates = items.filter(
    (i) => !preferenceItemIds.has(i.id) && dispositionByItemId.get(i.id) !== "set_aside",
  );
  const active = candidates.filter((i) => dispositionByItemId.get(i.id) !== "deferred");
  const deferred = candidates.filter((i) => dispositionByItemId.get(i.id) === "deferred");
  return [
    ...active.map((item) => ({ item, deferred: false })),
    ...deferred.map((item) => ({ item, deferred: true })),
  ];
}