MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / commitmentDisplayState

Function commitmentDisplayState

web/src/lib/commitment.ts:215–246  ·  view source on GitHub ↗
(view: ItemCommitmentView & { itemClosed?: boolean }, now: Date)

Source from the content-addressed store, hash-verified

213}
214
215export function commitmentDisplayState(view: ItemCommitmentView & { itemClosed?: boolean }, now: Date): {
216 primary: string; annotations: string[]; mark?: OccurrenceState; unavailable: boolean;
217 acknowledgedAt?: string; acknowledgedBy?: AcknowledgedBy;
218} {
219 const annotations: string[] = [];
220 const unavailable = !!view.error_code || (!view.ended_at && !view.next_occurrence);
221 const last = view.last_resolution?.state;
222 const next = view.next_occurrence;
223 let primary: string;
224 let mark: OccurrenceState | undefined;
225 if (unavailable) primary = 'Date unavailable';
226 else if (view.ended_at) {
227 primary = last === 'done' ? 'Done · schedule ended' : 'Ended';
228 if (last === 'done') mark = 'done';
229 if (last === 'skip') annotations.push('Last occurrence skipped');
230 } else {
231 const acknowledged = next?.state === 'acknowledged';
232 const outstanding = acknowledged ? 'Outstanding · acknowledged' : 'Outstanding';
233 const missed = view.missed_count ?? 0;
234 const snoozed = !!view.snoozed_until && Date.parse(view.snoozed_until) > now.getTime();
235 primary = snoozed ? 'Snoozed' : missed > 0 || view.stale ? 'Outstanding' : outstanding;
236 mark = acknowledged ? 'acknowledged' : 'outstanding';
237 if (snoozed || (acknowledged && primary !== outstanding)) annotations.push(outstanding);
238 if (missed > 0) annotations.push(`Missed: ${view.missed_truncated ? 'at least ' : ''}${missed} later occurrences`);
239 if (view.stale) annotations.push('Behind schedule');
240 if (last === 'done' || last === 'skip') annotations.push(`Last occurrence ${last === 'done' ? 'done' : 'skipped'}`);
241 }
242 if (view.itemClosed) primary += ' · Item closed';
243 return { primary, annotations, mark, unavailable,
244 ...(!unavailable && !view.ended_at && next?.state === 'acknowledged'
245 ? { acknowledgedAt: next.acknowledged_at, acknowledgedBy: next.acknowledged_by } : {}) };
246}
247
248export function describeLinkOffset(link: CommitmentLink, thisItemId: string, otherLabel: string): string {
249 const role = (name: string) => name === 'occupied_until' ? 'occupied end' : name;

Callers 1

commitment.test.tsFile · 0.90

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected