@startsimpli/integrations 0.2.150 → 0.2.151
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.
- package/package.json +4 -4
- package/src/__tests__/helpers/question-tenant.ts +45 -0
- package/src/__tests__/question-checkin.test.ts +139 -0
- package/src/__tests__/question-voice-parse.test.ts +110 -0
- package/src/__tests__/question-voice.test.ts +208 -0
- package/src/__tests__/tracker-done-stamp.test.ts +42 -0
- package/src/__tests__/tracker-timeline-component.test.tsx +81 -0
- package/src/__tests__/tracker-timeline-reader.test.ts +94 -0
- package/src/__tests__/tracker-timeline.test.ts +209 -0
- package/src/components/pages/TrackerPage.tsx +8 -0
- package/src/components/pages/tracker/TrackerTimeline.tsx +123 -0
- package/src/corpus/client.ts +12 -1
- package/src/corpus/questions/checkin-handle.ts +67 -0
- package/src/corpus/questions/checkin.ts +103 -0
- package/src/corpus/questions/index.ts +9 -0
- package/src/corpus/questions/respond.ts +76 -0
- package/src/corpus/questions/store.ts +5 -1
- package/src/corpus/questions/sync.ts +1 -0
- package/src/corpus/questions/types.ts +10 -2
- package/src/corpus/questions/voice-parse.ts +98 -0
- package/src/corpus/questions/voice.ts +225 -0
- package/src/corpus/tracker-timeline-client.ts +117 -0
- package/src/corpus/tracker-timeline.ts +228 -0
- package/src/corpus/types.ts +10 -0
- package/src/corpus/work-item-logic.ts +1 -1
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE TRACKER TIMELINE'S ARITHMETIC: three per-day series (created / done /
|
|
3
|
+
* overdue) and the to-dos behind them, as the generic `TimelinePoint` shape that
|
|
4
|
+
* `@startsimpli/ui/insights` draws. No React, no clock reads (the caller passes
|
|
5
|
+
* `now`), no HTTP: the reader in `tracker-timeline-client` fetches, this decides
|
|
6
|
+
* what the fetched numbers mean.
|
|
7
|
+
*
|
|
8
|
+
* WHAT EACH SERIES MEANS
|
|
9
|
+
* created items first seen that day (`first_seen_at`).
|
|
10
|
+
* done items marked done that day (`resolved_at`). Rows that were already
|
|
11
|
+
* done before completion was stamped have no `resolved_at`; they are
|
|
12
|
+
* placed on their last-updated day and COUNTED AS ESTIMATED so the
|
|
13
|
+
* screen can say so instead of pretending the date is exact.
|
|
14
|
+
* overdue items still owed whose date has passed, on the day they fell due.
|
|
15
|
+
* Same rule as the list (`isOverdue`): done and dropped are never
|
|
16
|
+
* overdue however old their date is.
|
|
17
|
+
*/
|
|
18
|
+
import type { TimelineEvent, TimelinePoint } from '@startsimpli/ui/insights';
|
|
19
|
+
|
|
20
|
+
import type { CommitmentQuery, CommitmentStatus } from './types';
|
|
21
|
+
import { isOverdue } from './work-item-logic';
|
|
22
|
+
|
|
23
|
+
/** The longest window the strip offers; one read serves every shorter window. */
|
|
24
|
+
export const TIMELINE_DAYS = 90;
|
|
25
|
+
|
|
26
|
+
export type TimelineKind = 'created' | 'done' | 'overdue';
|
|
27
|
+
|
|
28
|
+
const OWED: CommitmentStatus[] = ['open', 'in_progress', 'blocked'];
|
|
29
|
+
const DAY_MS = 86_400_000;
|
|
30
|
+
|
|
31
|
+
/** One value of a grouped count (the raw attribute text) and how many rows hold it. */
|
|
32
|
+
export interface ValueCount { value: string | null; count: number }
|
|
33
|
+
|
|
34
|
+
/** The slice of a to-do the timeline needs; dates are as stored. */
|
|
35
|
+
export interface TimelineItem {
|
|
36
|
+
id: string;
|
|
37
|
+
title: string;
|
|
38
|
+
status: CommitmentStatus;
|
|
39
|
+
dueAt: string | null;
|
|
40
|
+
firstSeenAt: string | null;
|
|
41
|
+
resolvedAt: string | null;
|
|
42
|
+
/** The row's own last-write time, the fallback for a done item with no `resolved_at`. */
|
|
43
|
+
updatedAt: string | null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface TimelineInput {
|
|
47
|
+
/** The reader's local day, YYYY-MM-DD. */
|
|
48
|
+
anchor: string;
|
|
49
|
+
created: ValueCount[];
|
|
50
|
+
done: ValueCount[];
|
|
51
|
+
overdue: ValueCount[];
|
|
52
|
+
items: TimelineItem[];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The page's filters, as the timeline understands them. */
|
|
56
|
+
export interface TimelineFilter {
|
|
57
|
+
/** Narrow to one status (the quick chips). */
|
|
58
|
+
status?: CommitmentStatus;
|
|
59
|
+
/** Only owed items past their date (the Overdue chip). */
|
|
60
|
+
overdueOnly?: boolean;
|
|
61
|
+
search?: string;
|
|
62
|
+
owner?: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const addDays = (day: string, days: number): string =>
|
|
66
|
+
new Date(Date.parse(`${day}T00:00:00Z`) + days * DAY_MS).toISOString().slice(0, 10);
|
|
67
|
+
|
|
68
|
+
/** The local calendar day of an instant; a date-only value is already a day. `null` if unreadable. */
|
|
69
|
+
export function dayOf(value: string | null | undefined, timeZone = 'UTC'): string | null {
|
|
70
|
+
if (!value) return null;
|
|
71
|
+
if (/^\d{4}-\d{2}-\d{2}$/.test(value)) return value;
|
|
72
|
+
const ms = Date.parse(value);
|
|
73
|
+
if (!Number.isFinite(ms)) return null;
|
|
74
|
+
try {
|
|
75
|
+
return new Intl.DateTimeFormat('en-CA', { timeZone, year: 'numeric', month: '2-digit', day: '2-digit' }).format(ms);
|
|
76
|
+
} catch {
|
|
77
|
+
return new Date(ms).toISOString().slice(0, 10);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The anchor day for a clock reading. */
|
|
82
|
+
export const anchorOf = (now: number, timeZone = 'UTC'): string => dayOf(new Date(now).toISOString(), timeZone) as string;
|
|
83
|
+
|
|
84
|
+
/** `days` calendar days ending on `anchorDay`, oldest first. */
|
|
85
|
+
export function windowDayList(anchorDay: string, days: number): string[] {
|
|
86
|
+
return Array.from({ length: days }, (_, i) => addDays(anchorDay, i - (days - 1)));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Grouped counts (one row per stored value) folded into one count per local day. */
|
|
90
|
+
export function bucketCounts(rows: ValueCount[], timeZone = 'UTC'): Map<string, number> {
|
|
91
|
+
const out = new Map<string, number>();
|
|
92
|
+
for (const row of rows) {
|
|
93
|
+
const day = dayOf(row.value, timeZone);
|
|
94
|
+
if (day) out.set(day, (out.get(day) ?? 0) + row.count);
|
|
95
|
+
}
|
|
96
|
+
return out;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** The day an item was completed, and whether that day is a guess (no `resolved_at`). */
|
|
100
|
+
export function completionOf(item: TimelineItem, timeZone = 'UTC'): { day: string; estimated: boolean } | null {
|
|
101
|
+
if (item.status !== 'done') return null;
|
|
102
|
+
const exact = dayOf(item.resolvedAt, timeZone);
|
|
103
|
+
if (exact) return { day: exact, estimated: false };
|
|
104
|
+
const guess = dayOf(item.updatedAt, timeZone);
|
|
105
|
+
return guess ? { day: guess, estimated: true } : null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const TONE: Record<TimelineKind, TimelineEvent['tone']> = { created: 'neutral', done: 'up', overdue: 'down' };
|
|
109
|
+
|
|
110
|
+
function eventFor(kind: TimelineKind, item: TimelineItem, label: string): TimelineEvent {
|
|
111
|
+
return { id: `${kind}:${item.id}`, label: item.title, delta: 0, tone: TONE[kind], category: kind, status: label };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface BuiltTimeline {
|
|
115
|
+
/** created / done / overdue, one point per day of the longest window, zero-filled. */
|
|
116
|
+
series: Array<{ id: TimelineKind; name: string; points: TimelinePoint[] }>;
|
|
117
|
+
/** Days that have at least one to-do, for the table under the chart. */
|
|
118
|
+
points: TimelinePoint[];
|
|
119
|
+
/** How many done items sit on an estimated day. */
|
|
120
|
+
estimatedDone: number;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function buildTimeline(input: TimelineInput, now: number, timeZone = 'UTC'): BuiltTimeline {
|
|
124
|
+
const days = windowDayList(input.anchor, TIMELINE_DAYS);
|
|
125
|
+
const inWindow = new Set(days);
|
|
126
|
+
const counts: Record<TimelineKind, Map<string, number>> = {
|
|
127
|
+
created: bucketCounts(input.created, timeZone),
|
|
128
|
+
done: bucketCounts(input.done, timeZone),
|
|
129
|
+
overdue: bucketCounts(input.overdue, timeZone),
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const byDay = new Map<string, TimelineEvent[]>();
|
|
133
|
+
const put = (day: string | null, event: TimelineEvent) => {
|
|
134
|
+
if (!day || !inWindow.has(day)) return;
|
|
135
|
+
byDay.set(day, [...(byDay.get(day) ?? []), event]);
|
|
136
|
+
};
|
|
137
|
+
let estimatedDone = 0;
|
|
138
|
+
for (const item of input.items) {
|
|
139
|
+
put(dayOf(item.firstSeenAt, timeZone), eventFor('created', item, 'Created'));
|
|
140
|
+
const completed = completionOf(item, timeZone);
|
|
141
|
+
if (completed) {
|
|
142
|
+
put(completed.day, eventFor('done', item, completed.estimated ? 'Done (date estimated)' : 'Done'));
|
|
143
|
+
if (completed.estimated && inWindow.has(completed.day)) {
|
|
144
|
+
estimatedDone += 1;
|
|
145
|
+
counts.done.set(completed.day, (counts.done.get(completed.day) ?? 0) + 1);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (isOverdue(item, now)) put(dayOf(item.dueAt, timeZone), eventFor('overdue', item, 'Overdue'));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const names: Record<TimelineKind, string> = { created: 'Created', done: 'Done', overdue: 'Overdue' };
|
|
152
|
+
const series = (['created', 'done', 'overdue'] as TimelineKind[]).map((id) => ({
|
|
153
|
+
id,
|
|
154
|
+
name: names[id],
|
|
155
|
+
points: days.map((date) => ({ date, value: counts[id].get(date) ?? 0 })),
|
|
156
|
+
}));
|
|
157
|
+
const points = days
|
|
158
|
+
.filter((date) => byDay.has(date))
|
|
159
|
+
.map((date) => ({ date, value: byDay.get(date)!.length, events: byDay.get(date)! }));
|
|
160
|
+
return { series, points, estimatedDone };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* The server parameters for one series' grouped count (`entities/counts`), or
|
|
165
|
+
* `null` when the filters make the series empty by definition (a Blocked chip
|
|
166
|
+
* has no done items) — no request is the honest answer there.
|
|
167
|
+
*/
|
|
168
|
+
export function timelineParams(
|
|
169
|
+
kind: TimelineKind,
|
|
170
|
+
filter: TimelineFilter,
|
|
171
|
+
clock: { now: number; timeZone?: string },
|
|
172
|
+
): Record<string, unknown> | null {
|
|
173
|
+
const anchor = anchorOf(clock.now, clock.timeZone);
|
|
174
|
+
// One day wider than the window: the day a stored instant falls on depends on
|
|
175
|
+
// the reader's zone, which only the client knows how to apply.
|
|
176
|
+
const since = addDays(anchor, -TIMELINE_DAYS);
|
|
177
|
+
const nowIso = new Date(clock.now).toISOString();
|
|
178
|
+
const params: Record<string, unknown> = {};
|
|
179
|
+
|
|
180
|
+
if (kind === 'done') {
|
|
181
|
+
if (filter.overdueOnly || (filter.status && filter.status !== 'done')) return null;
|
|
182
|
+
params['attr.status'] = 'done';
|
|
183
|
+
params['attr.resolved_at__gte'] = since;
|
|
184
|
+
} else if (kind === 'overdue') {
|
|
185
|
+
if (filter.status === 'done') return null;
|
|
186
|
+
if (filter.status) params['attr.status'] = filter.status;
|
|
187
|
+
else params['attr.status__in'] = OWED.join(',');
|
|
188
|
+
params['attr.due_at__gte'] = since;
|
|
189
|
+
params['attr.due_at__lt'] = nowIso;
|
|
190
|
+
} else {
|
|
191
|
+
params['attr.first_seen_at__gte'] = since;
|
|
192
|
+
if (filter.status) params['attr.status'] = filter.status;
|
|
193
|
+
if (filter.overdueOnly) {
|
|
194
|
+
if (!filter.status) params['attr.status__in'] = OWED.join(',');
|
|
195
|
+
params['attr.due_at__lt'] = nowIso;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
params.group_by = { created: 'attr.first_seen_at', done: 'attr.resolved_at', overdue: 'attr.due_at' }[kind];
|
|
199
|
+
if (filter.search?.trim()) params.search = filter.search.trim();
|
|
200
|
+
if (filter.owner?.trim()) params['attr.owner_name__icontains'] = filter.owner.trim();
|
|
201
|
+
return params;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Rows for the done items that have no `resolved_at` (finished before
|
|
206
|
+
* completion was stamped): the same filters as the done series, windowed by the
|
|
207
|
+
* row's own last update instead. `null` when the filters rule done items out.
|
|
208
|
+
*/
|
|
209
|
+
export function estimatedDoneParams(
|
|
210
|
+
filter: TimelineFilter,
|
|
211
|
+
clock: { now: number; timeZone?: string },
|
|
212
|
+
): Record<string, unknown> | null {
|
|
213
|
+
const base = timelineParams('done', filter, clock);
|
|
214
|
+
if (!base) return null;
|
|
215
|
+
const { group_by: _g, 'attr.resolved_at__gte': _r, ...rest } = base;
|
|
216
|
+
void _g; void _r;
|
|
217
|
+
const since = addDays(anchorOf(clock.now, clock.timeZone), -TIMELINE_DAYS);
|
|
218
|
+
return { ...rest, 'attr.resolved_at__isnull': 'true', updated_after: `${since}T00:00:00.000Z` };
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** Map the Tracker's quick chip onto the timeline's filter. */
|
|
222
|
+
export function filterFromChip(chip: 'all' | 'overdue' | 'blocked' | 'in_progress', rest: Pick<CommitmentQuery, 'search' | 'owner'> = {}): TimelineFilter {
|
|
223
|
+
return {
|
|
224
|
+
...(chip === 'blocked' || chip === 'in_progress' ? { status: chip } : {}),
|
|
225
|
+
...(chip === 'overdue' ? { overdueOnly: true } : {}),
|
|
226
|
+
...rest,
|
|
227
|
+
};
|
|
228
|
+
}
|
package/src/corpus/types.ts
CHANGED
|
@@ -1105,6 +1105,16 @@ export interface ExtractionDraft {
|
|
|
1105
1105
|
* handler; the handler runs the extraction server-side, where the key lives.
|
|
1106
1106
|
*/
|
|
1107
1107
|
export interface CommitmentTrackerApi extends CommitmentApi {
|
|
1108
|
+
/**
|
|
1109
|
+
* The Tracker timeline's data: grouped per-day counts for created / done /
|
|
1110
|
+
* overdue plus one capped page of the to-dos behind them, read server-side.
|
|
1111
|
+
* Absent on a deployment without the tenant's `entities/counts`; the page then
|
|
1112
|
+
* simply has no timeline.
|
|
1113
|
+
*/
|
|
1114
|
+
timeline?(
|
|
1115
|
+
filter: import('./tracker-timeline').TimelineFilter,
|
|
1116
|
+
clock: { now: number; timeZone?: string },
|
|
1117
|
+
): Promise<import('./tracker-timeline-client').TimelineRead>;
|
|
1108
1118
|
/**
|
|
1109
1119
|
* Run ONE slice of extraction and wait for it.
|
|
1110
1120
|
*
|
|
@@ -24,7 +24,7 @@ export function priorityLabel(priority?: number): string | null {
|
|
|
24
24
|
* A `done` or `dropped` item is never overdue however old its date is, because
|
|
25
25
|
* an overdue count is a list of things to do and a finished item is not one.
|
|
26
26
|
*/
|
|
27
|
-
export function isOverdue(item: Commitment, now: number): boolean {
|
|
27
|
+
export function isOverdue(item: Pick<Commitment, 'dueAt' | 'status'>, now: number): boolean {
|
|
28
28
|
if (!item.dueAt) return false;
|
|
29
29
|
if (item.status === 'done' || item.status === 'dropped') return false;
|
|
30
30
|
return Date.parse(item.dueAt) < now;
|