@startsimpli/integrations 0.2.189 → 0.2.190

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,7 @@
6
6
  export const TAB_COPY = {
7
7
  today: { label: 'Today', subtitle: 'Your morning brief and what is due soon.' },
8
8
  talk: { label: 'Talk', subtitle: 'Talk or type: plans, questions, notes. Say "parse that note" when you are done.' },
9
+ overview: { label: 'Overview', subtitle: 'Everything in flight, and who each project is waiting on.' },
9
10
  plan: { label: 'Plan', subtitle: 'Everything you owe, and what you are aiming for.' },
10
11
  more: { label: 'More', subtitle: 'Library, Decisions, Connections.' },
11
12
  } as const;
@@ -0,0 +1,105 @@
1
+ /**
2
+ * The Overview's numbers: projects (rows) by who each is waiting on (columns). Pure, so the grid is
3
+ * testable without a render. Nothing here names a person, an area or a workflow: the columns are whoever
4
+ * the open items belong to (`ownerName`), "Me" is whoever the caller says is the signed-in user, and a
5
+ * project is any focus. A different account gets different columns from its own data.
6
+ */
7
+ import type { Commitment, Focus } from './types';
8
+
9
+ const OPEN = new Set(['open', 'in_progress', 'blocked']);
10
+ export const NO_PROJECT = '__none__';
11
+
12
+ export interface OverviewCell {
13
+ count: number;
14
+ /** The most pressing open item here: earliest due date first, then priority. */
15
+ next: Commitment | null;
16
+ }
17
+ export interface OverviewColumn {
18
+ key: string;
19
+ label: string;
20
+ total: number;
21
+ isMe: boolean;
22
+ }
23
+ export interface OverviewRow {
24
+ /** The focus id, or NO_PROJECT for items filed under no project. */
25
+ id: string;
26
+ focus: Focus | null;
27
+ title: string;
28
+ open: number;
29
+ overdue: number;
30
+ blocked: number;
31
+ /** ISO instant of the newest sighting of any of its items. */
32
+ lastActivity: string | null;
33
+ cells: Record<string, OverviewCell>;
34
+ }
35
+ export interface Overview {
36
+ columns: OverviewColumn[];
37
+ rows: OverviewRow[];
38
+ }
39
+
40
+ export interface OverviewOptions {
41
+ /** Names that mean the signed-in user (display name, email local part). Case-insensitive. */
42
+ meNames?: string[];
43
+ now?: number;
44
+ }
45
+
46
+ const norm = (s: string | undefined) => (s ?? '').trim().toLowerCase();
47
+ const ownerKey = (c: Commitment) => norm(c.ownerName);
48
+ const byUrgency = (a: Commitment, b: Commitment) => {
49
+ const da = a.dueAt ? Date.parse(a.dueAt) : Infinity;
50
+ const db = b.dueAt ? Date.parse(b.dueAt) : Infinity;
51
+ if (da !== db) return da - db;
52
+ return (a.priority ?? 9) - (b.priority ?? 9);
53
+ };
54
+
55
+ export function buildOverview(focuses: Focus[], items: Array<Commitment & { focusId?: string }>, opts: OverviewOptions = {}): Overview {
56
+ const now = opts.now ?? Date.now();
57
+ const me = new Set((opts.meNames ?? []).map(norm).filter(Boolean));
58
+ const open = items.filter((c) => OPEN.has(c.status));
59
+ const byFocus = new Map<string, Commitment[]>();
60
+ for (const c of open) {
61
+ const id = c.focusId || NO_PROJECT;
62
+ byFocus.set(id, [...(byFocus.get(id) ?? []), c]);
63
+ }
64
+ const live = focuses.filter((f) => f.status !== 'completed' && f.status !== 'cancelled');
65
+ const ids = new Set(live.map((f) => f.id));
66
+ const rowsSrc: Array<{ id: string; focus: Focus | null; title: string }> = live.map((f) => ({ id: f.id, focus: f, title: f.title }));
67
+ // items filed under a closed or unknown project still count: show them under "No project" rather than losing them
68
+ const strayItems = [...byFocus.entries()].filter(([id]) => id !== NO_PROJECT && !ids.has(id)).flatMap(([, v]) => v);
69
+ const noProject = [...(byFocus.get(NO_PROJECT) ?? []), ...strayItems];
70
+ if (noProject.length) rowsSrc.push({ id: NO_PROJECT, focus: null, title: 'No project' });
71
+
72
+ const totals = new Map<string, { label: string; total: number }>();
73
+ const rows: OverviewRow[] = rowsSrc.map((r) => {
74
+ const mine = r.id === NO_PROJECT ? noProject : byFocus.get(r.id) ?? [];
75
+ const cells: Record<string, OverviewCell> = {};
76
+ for (const c of mine) {
77
+ const k = ownerKey(c);
78
+ const cell = (cells[k] ??= { count: 0, next: null });
79
+ cell.count += 1;
80
+ if (!cell.next || byUrgency(c, cell.next) < 0) cell.next = c;
81
+ const t = totals.get(k) ?? { label: c.ownerName?.trim() || '', total: 0 };
82
+ t.total += 1;
83
+ totals.set(k, t);
84
+ }
85
+ const lastActivity = mine.map((c) => c.lastSeenAt).filter(Boolean).sort().at(-1) ?? null;
86
+ return {
87
+ ...r,
88
+ open: mine.length,
89
+ overdue: mine.filter((c) => c.dueAt && Date.parse(c.dueAt) < now).length,
90
+ blocked: mine.filter((c) => c.status === 'blocked').length,
91
+ lastActivity,
92
+ cells,
93
+ };
94
+ });
95
+
96
+ const columns: OverviewColumn[] = [...totals.entries()].map(([key, v]) => {
97
+ const isMe = me.has(key);
98
+ return { key, label: isMe ? 'Me' : v.label || 'Unassigned', total: v.total, isMe };
99
+ });
100
+ columns.sort((a, b) => Number(b.isMe) - Number(a.isMe) || Number(a.key === '') - Number(b.key === '') || b.total - a.total || a.label.localeCompare(b.label));
101
+
102
+ const attention = (r: OverviewRow) => (r.focus?.status === 'off_track' || r.focus?.status === 'at_risk' ? 0 : r.blocked ? 1 : r.overdue ? 2 : 3);
103
+ rows.sort((a, b) => (a.id === NO_PROJECT ? 1 : 0) - (b.id === NO_PROJECT ? 1 : 0) || attention(a) - attention(b) || b.open - a.open || a.title.localeCompare(b.title));
104
+ return { columns, rows };
105
+ }