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

Function editStateFromView

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

Source from the content-addressed store, hash-verified

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