@outbuild-company/schedule-core 1.10.0 → 1.10.2

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/dist/index.js CHANGED
@@ -890,6 +890,7 @@ function dispatchFilterSet(action, deps) {
890
890
 
891
891
  // src/internal/hierarchy/root-parent.ts
892
892
  var ROOT_PARENT_ID = "0";
893
+ var ROOT_PROJECT_CORRELATIVE_ID = 0;
893
894
  function isRootParent(parent) {
894
895
  return parent == null || parent === 0 || parent === ROOT_PARENT_ID;
895
896
  }
@@ -1815,6 +1816,9 @@ function findConnectedGroupForTrigger(triggerId, links) {
1815
1816
 
1816
1817
  // src/constants/progress.ts
1817
1818
  var COMPLETED_PROGRESS = 100;
1819
+ function isAutoSchedulingEnabledForProgress(progress) {
1820
+ return progress === 0;
1821
+ }
1818
1822
 
1819
1823
  // src/autoscheduler/engine/link-calculator.ts
1820
1824
  function normalize(predecessor, successor, link) {
@@ -3953,7 +3957,6 @@ var setRealWork = (value) => ({
3953
3957
  // src/columns/progress/progress-pipeline.ts
3954
3958
  var MIN_PROGRESS = 0;
3955
3959
  var MAX_PROGRESS = PROGRESS_COMPLETE;
3956
- var PROGRESS_NONE = 0;
3957
3960
  var progressPipeline = {
3958
3961
  targetField: "progress",
3959
3962
  canEdit(activity, hierarchy) {
@@ -3973,7 +3976,8 @@ var progressPipeline = {
3973
3976
  return valid();
3974
3977
  },
3975
3978
  transform(activity, newValue, ctx) {
3976
- const autoScheduling = determineAutoScheduling(newValue);
3979
+ const autoScheduling = isAutoSchedulingEnabledForProgress(newValue);
3980
+ const needsAutoSchedule = activity.progress !== newValue && autoScheduling;
3977
3981
  const recursive = isRecursiveProgressChange(newValue);
3978
3982
  const realWorkByActivity = buildCanonicalRealWorkOverlay(
3979
3983
  activity,
@@ -3997,7 +4001,7 @@ var progressPipeline = {
3997
4001
  const postProcessors = [];
3998
4002
  const trackingEvents = recursive ? buildRecursiveTrackingEvents(activity, newValue) : void 0;
3999
4003
  return fieldChanges(patch, {
4000
- autoSchedule: false,
4004
+ autoSchedule: needsAutoSchedule,
4001
4005
  postProcessors,
4002
4006
  cascadeMutations,
4003
4007
  trackingEvents
@@ -4008,11 +4012,8 @@ var progressPipeline = {
4008
4012
  function isOutOfRange(value) {
4009
4013
  return value < MIN_PROGRESS || value > MAX_PROGRESS;
4010
4014
  }
4011
- function determineAutoScheduling(progress) {
4012
- return progress === PROGRESS_NONE;
4013
- }
4014
4015
  function isRecursiveProgressChange(value) {
4015
- return value === PROGRESS_COMPLETE || value === PROGRESS_NONE;
4016
+ return value === PROGRESS_COMPLETE || isAutoSchedulingEnabledForProgress(value);
4016
4017
  }
4017
4018
  function buildDescendantCascade(activity, newValue, autoScheduling, hierarchy, realWorkByActivity) {
4018
4019
  const descendants = hierarchy.getDescendantIds(activity.id);
@@ -10297,10 +10298,6 @@ function mergeScheduledIds(firstSettleIds, secondSettleIds) {
10297
10298
  }
10298
10299
 
10299
10300
  // src/dispatch/sir-auto-reject.ts
10300
- function datesChanged(before, after) {
10301
- const toTime = (value) => value.getTime();
10302
- return toTime(before.startDate) !== toTime(after.startDate) || toTime(before.endDate) !== toTime(after.endDate) || before.durationHours !== after.durationHours;
10303
- }
10304
10301
  function detectSirAutoReject(beforeSnap, adapter, touchedIds) {
10305
10302
  const effects = [];
10306
10303
  for (const id of touchedIds) {
@@ -10308,21 +10305,15 @@ function detectSirAutoReject(beforeSnap, adapter, touchedIds) {
10308
10305
  if (!before) continue;
10309
10306
  const pendingRequestIds = before.pendingRequestIds ?? [];
10310
10307
  if (!isFrozen({ pendingRequestIds })) continue;
10311
- const after = adapter.getActivity(id);
10312
- const deleted = after == null;
10313
- if (!deleted && !datesChanged(before, after)) continue;
10314
- const reason = deleted ? "activity_deleted" : "date_changed";
10308
+ if (adapter.getActivity(id) != null) continue;
10315
10309
  for (const pending of pendingRequestIds) {
10316
10310
  effects.push({
10317
10311
  kind: "sir-auto-reject",
10318
10312
  activityId: id,
10319
10313
  sirId: pending,
10320
- reason
10314
+ reason: "activity_deleted"
10321
10315
  });
10322
10316
  }
10323
- if (!deleted) {
10324
- adapter.setActivityField(id, "pendingRequestIds", []);
10325
- }
10326
10317
  }
10327
10318
  return effects;
10328
10319
  }
@@ -11908,7 +11899,11 @@ async function dispatchActivityDelete(action, options, deps) {
11908
11899
  return { ok: false, reason: REJECTION_REASON.ACTIVITY_NOT_FOUND };
11909
11900
  }
11910
11901
  }
11911
- const toDelete = collectDescendantIds(action.activityIds, adapter);
11902
+ const deletableActivityIds = action.activityIds.filter((id) => {
11903
+ const activity = adapter.getActivity(id);
11904
+ return !(activity?.correlativeId === ROOT_PROJECT_CORRELATIVE_ID && activity.type === ACTIVITY_TYPE.PROJECT);
11905
+ });
11906
+ const toDelete = collectDescendantIds(deletableActivityIds, adapter);
11912
11907
  const incidentLinkIds = collectIncidentLinkIds(toDelete, adapter);
11913
11908
  const parentsToCheck = /* @__PURE__ */ new Set();
11914
11909
  for (const id of action.activityIds) {
@@ -12645,10 +12640,12 @@ async function applyReconciledProgress(entries, deps) {
12645
12640
  const before = await snapshotActivities(deps.adapter, touched);
12646
12641
  deps.adapter.batchUpdate(() => {
12647
12642
  for (const entry of progressToApply) {
12643
+ const activityId = String(entry.activityId);
12644
+ deps.adapter.setActivityField(activityId, "progress", entry.progress);
12648
12645
  deps.adapter.setActivityField(
12649
- String(entry.activityId),
12650
- "progress",
12651
- entry.progress
12646
+ activityId,
12647
+ "autoScheduling",
12648
+ isAutoSchedulingEnabledForProgress(entry.progress)
12652
12649
  );
12653
12650
  }
12654
12651
  recomputeProgressRollupForParents(ancestors, deps.adapter);
@@ -12819,7 +12816,7 @@ async function dispatchActivityLookaheadSync(action, options, deps) {
12819
12816
  },
12820
12817
  {
12821
12818
  action,
12822
- autoscheduleFrom: null,
12819
+ autoscheduleFrom: action.persistedProgress === 0 ? ids[0] : null,
12823
12820
  recomputeParentsFrom: [],
12824
12821
  now: deps.now,
12825
12822
  options
@@ -14436,9 +14433,13 @@ function resolveDestination(afterSiblingId, adapter) {
14436
14433
  if (!sibling) {
14437
14434
  return { ok: false, reason: REJECTION_REASON.ANCHOR_SIBLING_NOT_FOUND };
14438
14435
  }
14436
+ if (sibling.parentId == null) {
14437
+ return adapter.getRootIds().length === 1 ? { ok: true, parentId: sibling.id } : { ok: true, parentId: ROOT_PARENT_ID, afterSiblingId };
14438
+ }
14439
14439
  return {
14440
14440
  ok: true,
14441
- parentId: sibling.parentId == null ? ROOT_PARENT_ID : String(sibling.parentId)
14441
+ parentId: String(sibling.parentId),
14442
+ afterSiblingId
14442
14443
  };
14443
14444
  }
14444
14445
  var invariantFailure = () => ({
@@ -14465,12 +14466,11 @@ async function dispatchActivityPasteCopied(action, options, deps) {
14465
14466
  let previousRootId;
14466
14467
  for (const copied of clipboard.activities) {
14467
14468
  const mappedParent = originalToNew.get(copied.originalParentId);
14469
+ const afterSiblingId = mappedParent === void 0 ? previousRootId ?? destination.afterSiblingId : void 0;
14468
14470
  const created = await createActivityCore(
14469
14471
  {
14470
14472
  parentId: mappedParent ?? destination.parentId,
14471
- ...mappedParent === void 0 ? {
14472
- afterSiblingId: previousRootId ?? action.destination.afterSiblingId
14473
- } : {},
14473
+ ...afterSiblingId === void 0 ? {} : { afterSiblingId },
14474
14474
  overrides: cloneDomainValue(copied.overrides),
14475
14475
  eventSource: action.eventSource
14476
14476
  },
@@ -19313,7 +19313,10 @@ var SaveTracker = class _SaveTracker {
19313
19313
  const persistable = {
19314
19314
  ...saved.persistable,
19315
19315
  ...acknowledgesLookahead ? { isLookahead: current.isLookahead } : {},
19316
- ...acknowledgesProgress ? { progress: current.progress } : {}
19316
+ ...acknowledgesProgress ? {
19317
+ progress: current.progress,
19318
+ autoScheduling: current.autoScheduling
19319
+ } : {}
19317
19320
  };
19318
19321
  this.activitiesAtLastSave.set(activityId, {
19319
19322
  ...saved,
@@ -19472,9 +19475,6 @@ function normalizeActivities(rawActivities, context) {
19472
19475
  reparentOrphansToRoot(activities, activityIds, context.reporter);
19473
19476
  return { activities, activityIds, hiddenIds };
19474
19477
  }
19475
- function isAutoSchedulable(progress) {
19476
- return progress === 0;
19477
- }
19478
19478
  function parseConstraintLabel(label, reporter) {
19479
19479
  if (!label) return null;
19480
19480
  const normalized2 = CONSTRAINT_LABEL_MAP[label.toUpperCase()];
@@ -19576,7 +19576,7 @@ function parseActivity(raw, context) {
19576
19576
  durationHours: durationToHours(durationDays, context.hoursPerDay),
19577
19577
  constraintType,
19578
19578
  constraintDate,
19579
- autoScheduling: isAutoSchedulable(progress),
19579
+ autoScheduling: isAutoSchedulingEnabledForProgress(progress),
19580
19580
  calendarId,
19581
19581
  assignedDefaultCalendar: calendarId != null && inheritedDefaultCalendar,
19582
19582
  dateOrigin: raw.date_origin == null ? null : parseBackendDate(raw.date_origin),