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

Function editStateFromView

web/src/lib/commitment.ts:130–154  ·  view source on GitHub ↗
(view: ItemCommitmentView)

Source from the content-addressed store, hash-verified

128
129/** The Edit dialog's starting state, from the stored values only; null when the view offers no Edit. */
130export function editStateFromView(view: ItemCommitmentView): CommitmentEditState | null {
131 const o = view.role_offsets;
132 if (!o || view.ended_at) return null;
133 const [date, clock = ''] = view.dtstart.split('T');
134 const time = clock.slice(0, 5);
135 const rule = !view.rrule ? (view.rdates.length ? null : 'once') : COMMITMENT_RECURRENCES.find(([, r]) => r === view.rrule)?.[0] ?? null;
136 const behavior = view.roles.deadline_behavior;
137 const deadline = o.deadline_days !== null && o.deadline_secs !== null && behavior ? { days: o.deadline_days, secs: o.deadline_secs, behavior } : null;
138 const nativeDeadline = !!deadline && view.roles.roles_origin === 'native';
139 const linkedDeadline = view.links.some(l => (l.child_item_id === view.item_id && l.child_role === 'deadline') || (l.parent_item_id === view.item_id && l.parent_role === 'deadline'));
140 const next = view.next_occurrence;
141 const expected = next ? (isDateOnly(view.dtstart) ? next.wall.slice(0, 10) : next.at) : null;
142 return {
143 initial: { date, time, rule, deadline }, seconds: clock.slice(5),
144 timingLock: nativeDeadline ? 'Fixed while a hard deadline exists; renegotiate or remove the deadline first.'
145 : view.links.length ? 'Fixed while this date is linked to another item.'
146 : rule === null || view.rdates.length || view.exdates.length ? `Repeats by a custom rule (${[view.rrule, view.rdates.length && 'additional dates', view.exdates.length && 'excluded dates'].filter(Boolean).join(', ')}); use pad remind edit to change it.`
147 : o.target_days || o.target_secs ? 'Fixed because the target is offset from the start; use pad remind edit to change it.' : '',
148 deadlineLock: linkedDeadline ? 'Fixed while the deadline is linked to another item.'
149 : !time && deadline && deadline.secs ? 'This all-day date has a timed deadline; use pad remind edit to change it.' : '',
150 timeLocked: o.earliest_days !== null || o.occupied_days !== null || !!deadline,
151 nativeDeadline,
152 replanDrops: !!view.next_override_at || !!view.snoozed_until || (!!expected && view.roles.target !== null && view.roles.target !== expected)
153 };
154}
155
156export type CommitmentEditPlan =
157 | { kind: 'none' }

Callers 2

stFunction · 0.90
commitment.test.tsFile · 0.90

Calls 3

isDateOnlyFunction · 0.90
findMethod · 0.80
joinMethod · 0.80

Tested by 1

stFunction · 0.72