@outbuild-company/schedule-core 1.18.0 → 1.19.0

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.cjs CHANGED
@@ -354,6 +354,7 @@ var DISPATCH_ACTION_KIND = {
354
354
  SORT_SET: "sort-set",
355
355
  VIEW_ATTRIBUTES_SET: "view-attributes-set",
356
356
  GROUP_SET: "group-set",
357
+ WBS_DEPTH_SET: "wbs-depth-set",
357
358
  SIR_SYNC: "sir-sync",
358
359
  ACTIVITY_LOOKAHEAD_SYNC: "activity-lookahead-sync",
359
360
  SCHEDULE_AUTO_SCHEDULE: "schedule-auto-schedule"
@@ -688,6 +689,12 @@ function createScheduleNamespaces(engine) {
688
689
  kind: DISPATCH_ACTION_KIND.GROUP_SET,
689
690
  group
690
691
  }),
692
+ wbsDepth: () => engine.getWbsDepth(),
693
+ setWbsDepth: (wbsDepth, context = {}) => engine.dispatch({
694
+ ...context,
695
+ kind: DISPATCH_ACTION_KIND.WBS_DEPTH_SET,
696
+ wbsDepth
697
+ }),
691
698
  setVisibility: (activityIds, context = {}) => engine.dispatch({
692
699
  ...context,
693
700
  kind: DISPATCH_ACTION_KIND.VISIBILITY_SET,
@@ -1307,6 +1314,7 @@ var GROUP_ID_SEPARATOR = ":";
1307
1314
  var UNASSIGNED_GROUP_LABEL = "Unassigned";
1308
1315
  var MINIMUM_GROUP_DEPTH = 1;
1309
1316
  var MINIMUM_GROUP_LEVEL = 1;
1317
+ var FLAT_WBS_DEPTH = 0;
1310
1318
  function buildGroupRowId(attributeKey, valueId) {
1311
1319
  return `${GROUP_ID_PREFIX}${GROUP_ID_SEPARATOR}${attributeKey}${GROUP_ID_SEPARATOR}${valueId}`;
1312
1320
  }
@@ -2284,6 +2292,17 @@ function dispatchGroupSet(action, deps) {
2284
2292
  adapter.setGroup(group);
2285
2293
  return { ok: true, changes: emptyViewChanges(action) };
2286
2294
  }
2295
+ function dispatchWbsDepthSet(action, deps) {
2296
+ const { adapter } = deps;
2297
+ const { wbsDepth } = action;
2298
+ if (wbsDepth !== null) {
2299
+ if (!isFiniteInteger(wbsDepth) || wbsDepth < FLAT_WBS_DEPTH) {
2300
+ return { ok: false, reason: FILTER_REJECTION_REASON.INVALID_VALUE };
2301
+ }
2302
+ }
2303
+ adapter.setWbsDepth(wbsDepth);
2304
+ return { ok: true, changes: emptyViewChanges(action) };
2305
+ }
2287
2306
 
2288
2307
  // src/shared/assert-never.ts
2289
2308
  function assertNever(value, message) {
@@ -11215,6 +11234,7 @@ var NON_SCHEDULING_KINDS = /* @__PURE__ */ new Set([
11215
11234
  DISPATCH_ACTION_KIND.SORT_SET,
11216
11235
  DISPATCH_ACTION_KIND.VIEW_ATTRIBUTES_SET,
11217
11236
  DISPATCH_ACTION_KIND.GROUP_SET,
11237
+ DISPATCH_ACTION_KIND.WBS_DEPTH_SET,
11218
11238
  DISPATCH_ACTION_KIND.SIR_SYNC,
11219
11239
  DISPATCH_ACTION_KIND.ACTIVITY_LOOKAHEAD_SYNC,
11220
11240
  DISPATCH_ACTION_KIND.PERSISTENCE_ACKNOWLEDGE,
@@ -11231,7 +11251,8 @@ var PURE_VIEW_STATE_KINDS = /* @__PURE__ */ new Set([
11231
11251
  DISPATCH_ACTION_KIND.FILTER_SET,
11232
11252
  DISPATCH_ACTION_KIND.SORT_SET,
11233
11253
  DISPATCH_ACTION_KIND.VIEW_ATTRIBUTES_SET,
11234
- DISPATCH_ACTION_KIND.GROUP_SET
11254
+ DISPATCH_ACTION_KIND.GROUP_SET,
11255
+ DISPATCH_ACTION_KIND.WBS_DEPTH_SET
11235
11256
  ]);
11236
11257
  function reappliesViewState(action) {
11237
11258
  return !PURE_VIEW_STATE_KINDS.has(action.kind);
@@ -17121,6 +17142,12 @@ async function performDispatch(action, options, deps) {
17121
17142
  hoursPerDay: deps.sector.hoursPerDay
17122
17143
  });
17123
17144
  }
17145
+ if (action.kind === DISPATCH_ACTION_KIND.WBS_DEPTH_SET) {
17146
+ return dispatchWbsDepthSet(action, {
17147
+ adapter: deps.adapter,
17148
+ hoursPerDay: deps.sector.hoursPerDay
17149
+ });
17150
+ }
17124
17151
  if (action.kind === DISPATCH_ACTION_KIND.SIR_SYNC) {
17125
17152
  return dispatchSirSync(action, deps);
17126
17153
  }
@@ -20260,35 +20287,95 @@ function sortedChildNodes(node, direction) {
20260
20287
  if (direction === ORDER_DIRECTION.DESCENDING) children.reverse();
20261
20288
  return children;
20262
20289
  }
20263
- function emitWbsOrderedActivities(memberActivities, activitiesInVisualOrder, parentOf, rows) {
20264
- const members = new Set(
20290
+ var FIRST_WBS_LEVEL = 1;
20291
+ var WHOLE_WBS = Number.POSITIVE_INFINITY;
20292
+ function activityRow(activity) {
20293
+ return {
20294
+ kind: VISUAL_ROW_KIND.ACTIVITY,
20295
+ activityId: String(activity.id)
20296
+ };
20297
+ }
20298
+ function buildWbsTree(included, activitiesInVisualOrder, parentOf) {
20299
+ const roots = [];
20300
+ const childrenOf = /* @__PURE__ */ new Map();
20301
+ for (const activity of activitiesInVisualOrder) {
20302
+ if (!included.has(String(activity.id))) continue;
20303
+ const parentId = parentOf(activity.id);
20304
+ const parentKey = parentId === null ? null : String(parentId);
20305
+ if (parentKey === null || !included.has(parentKey)) {
20306
+ roots.push(activity);
20307
+ continue;
20308
+ }
20309
+ const siblings = childrenOf.get(parentKey);
20310
+ if (siblings === void 0) childrenOf.set(parentKey, [activity]);
20311
+ else siblings.push(activity);
20312
+ }
20313
+ return { roots, childrenOf };
20314
+ }
20315
+ function emitWbsRows(included, input) {
20316
+ const { roots, childrenOf } = buildWbsTree(
20317
+ included,
20318
+ input.activitiesInVisualOrder,
20319
+ input.parentOf
20320
+ );
20321
+ const cap = input.wbsDepth ?? WHOLE_WBS;
20322
+ const childrenOfActivity = (activity) => childrenOf.get(String(activity.id)) ?? [];
20323
+ const foldToActivities = (siblings) => {
20324
+ const folded = [];
20325
+ const walk = (nodes) => {
20326
+ for (const node of nodes) {
20327
+ const children = childrenOfActivity(node);
20328
+ if (children.length === 0) folded.push(node);
20329
+ else walk(children);
20330
+ }
20331
+ };
20332
+ walk(siblings);
20333
+ return folded;
20334
+ };
20335
+ const emit = (siblings, level) => {
20336
+ if (level > cap) {
20337
+ const folded = foldToActivities(siblings);
20338
+ const ordered = input.comparator === null ? folded : sortSiblingsInOrderMode(
20339
+ folded,
20340
+ input.comparator,
20341
+ input.orderMode,
20342
+ () => false
20343
+ );
20344
+ for (const activity of ordered) input.rows.push(activityRow(activity));
20345
+ return;
20346
+ }
20347
+ for (const activity of siblings) {
20348
+ input.rows.push(activityRow(activity));
20349
+ const children = childrenOfActivity(activity);
20350
+ if (children.length > 0) emit(children, level + 1);
20351
+ }
20352
+ };
20353
+ emit(roots, FIRST_WBS_LEVEL);
20354
+ }
20355
+ function emitWbsOrderedActivities(memberActivities, input) {
20356
+ const included = new Set(
20265
20357
  memberActivities.map((activity) => String(activity.id))
20266
20358
  );
20267
- const included = new Set(members);
20268
- for (const memberId of members) {
20269
- let ancestorId = parentOf(memberId);
20359
+ for (const member of memberActivities) {
20360
+ let ancestorId = input.parentOf(member.id);
20270
20361
  while (ancestorId !== null) {
20271
20362
  included.add(String(ancestorId));
20272
- ancestorId = parentOf(ancestorId);
20363
+ ancestorId = input.parentOf(ancestorId);
20273
20364
  }
20274
20365
  }
20275
- for (const activity of activitiesInVisualOrder) {
20276
- if (!included.has(String(activity.id))) continue;
20277
- rows.push({
20278
- kind: VISUAL_ROW_KIND.ACTIVITY,
20279
- activityId: String(activity.id)
20280
- });
20281
- }
20366
+ emitWbsRows(included, input);
20282
20367
  }
20283
20368
  function emitActivities(node, context) {
20284
20369
  const { rows } = context;
20285
20370
  if (context.group.includeWbs) {
20286
- emitWbsOrderedActivities(
20287
- node.activities,
20288
- context.activitiesInVisualOrder,
20289
- context.parentOf,
20371
+ emitWbsOrderedActivities(node.activities, {
20372
+ activitiesInVisualOrder: context.activitiesInVisualOrder,
20373
+ parentOf: context.parentOf,
20374
+ wbsDepth: context.wbsDepth,
20375
+ comparator: context.comparator,
20376
+ orderMode: context.orderMode,
20290
20377
  rows
20291
- );
20378
+ });
20292
20379
  return;
20293
20380
  }
20294
20381
  for (const activity of sortSiblingsInOrderMode(
@@ -20339,10 +20426,20 @@ function projectVisualRows(input) {
20339
20426
  (activity) => input.isVisible(activity.id)
20340
20427
  );
20341
20428
  if (input.group === null || input.catalog === null) {
20342
- return visibleActivities.map((activity) => ({
20343
- kind: VISUAL_ROW_KIND.ACTIVITY,
20344
- activityId: String(activity.id)
20345
- }));
20429
+ if (input.wbsDepth === null) return visibleActivities.map(activityRow);
20430
+ const rows2 = [];
20431
+ emitWbsRows(
20432
+ new Set(visibleActivities.map((activity) => String(activity.id))),
20433
+ {
20434
+ activitiesInVisualOrder: visibleActivities,
20435
+ parentOf: input.parentOf,
20436
+ wbsDepth: input.wbsDepth,
20437
+ comparator: input.comparator,
20438
+ orderMode: input.orderMode,
20439
+ rows: rows2
20440
+ }
20441
+ );
20442
+ return rows2;
20346
20443
  }
20347
20444
  const { group, catalog } = input;
20348
20445
  const root = buildGroupTree(
@@ -20360,6 +20457,7 @@ function projectVisualRows(input) {
20360
20457
  hasChildren: input.hasChildren,
20361
20458
  comparator: input.comparator,
20362
20459
  orderMode: input.orderMode,
20460
+ wbsDepth: input.wbsDepth,
20363
20461
  secondaryCatalog: input.secondaryCatalog,
20364
20462
  rows
20365
20463
  };
@@ -20373,6 +20471,7 @@ function projectVisualRows(input) {
20373
20471
  var ViewAttributeStore = class _ViewAttributeStore {
20374
20472
  catalogs = /* @__PURE__ */ new Map();
20375
20473
  group = null;
20474
+ wbsDepth = null;
20376
20475
  getCatalog(key) {
20377
20476
  return this.catalogs.get(key) ?? null;
20378
20477
  }
@@ -20392,10 +20491,17 @@ var ViewAttributeStore = class _ViewAttributeStore {
20392
20491
  setGroup(nextGroup) {
20393
20492
  this.group = nextGroup;
20394
20493
  }
20494
+ getWbsDepth() {
20495
+ return this.wbsDepth;
20496
+ }
20497
+ setWbsDepth(nextDepth) {
20498
+ this.wbsDepth = nextDepth;
20499
+ }
20395
20500
  clone() {
20396
20501
  const fork = new _ViewAttributeStore();
20397
20502
  fork.catalogs = new Map(this.catalogs);
20398
20503
  fork.group = this.group === null ? null : cloneDomainValue(this.group);
20504
+ fork.wbsDepth = this.wbsDepth;
20399
20505
  return fork;
20400
20506
  }
20401
20507
  };
@@ -20633,6 +20739,13 @@ var ScheduleState = class _ScheduleState {
20633
20739
  this._viewAttributes.setGroup(nextGroup);
20634
20740
  this.invalidateVisualRows();
20635
20741
  }
20742
+ getWbsDepth() {
20743
+ return this._viewAttributes.getWbsDepth();
20744
+ }
20745
+ setWbsDepth(nextDepth) {
20746
+ this._viewAttributes.setWbsDepth(nextDepth);
20747
+ this.invalidateVisualRows();
20748
+ }
20636
20749
  invalidateVisualRows() {
20637
20750
  this._cache.visualRows = null;
20638
20751
  }
@@ -20655,7 +20768,8 @@ var ScheduleState = class _ScheduleState {
20655
20768
  catalog,
20656
20769
  secondaryCatalog,
20657
20770
  comparator: this.getOrderComparator(),
20658
- orderMode: this.getOrderMode()
20771
+ orderMode: this.getOrderMode(),
20772
+ wbsDepth: this._viewAttributes.getWbsDepth()
20659
20773
  });
20660
20774
  return this._cache.visualRows;
20661
20775
  }
@@ -21252,7 +21366,7 @@ function getDispatchHistoryPolicy(action) {
21252
21366
  if (action.kind === DISPATCH_ACTION_KIND.PERSISTENCE_ACKNOWLEDGE) {
21253
21367
  return DISPATCH_HISTORY_POLICY.CHECKPOINT_ON_SUCCESS;
21254
21368
  }
21255
- if (action.kind === DISPATCH_ACTION_KIND.SIR_SYNC || action.kind === DISPATCH_ACTION_KIND.CALENDAR_RECONCILE || action.kind === DISPATCH_ACTION_KIND.ACTIVITY_LOOKAHEAD_SYNC || action.kind === DISPATCH_ACTION_KIND.BASELINE_APPLY || action.kind === DISPATCH_ACTION_KIND.PONDERATOR_CRITERION_SET || action.kind === DISPATCH_ACTION_KIND.STATUS_CRITERIA_SET || action.kind === DISPATCH_ACTION_KIND.ACTIVITY_CLIPBOARD_CLEAR || action.kind === DISPATCH_ACTION_KIND.ACTIVITY_COPY || action.kind === DISPATCH_ACTION_KIND.SELECTION_TOGGLE || action.kind === DISPATCH_ACTION_KIND.SELECTION_REPLACE || action.kind === DISPATCH_ACTION_KIND.VISIBILITY_SET || action.kind === DISPATCH_ACTION_KIND.FILTER_SET || action.kind === DISPATCH_ACTION_KIND.SORT_SET || action.kind === DISPATCH_ACTION_KIND.VIEW_ATTRIBUTES_SET || action.kind === DISPATCH_ACTION_KIND.GROUP_SET) {
21369
+ if (action.kind === DISPATCH_ACTION_KIND.SIR_SYNC || action.kind === DISPATCH_ACTION_KIND.CALENDAR_RECONCILE || action.kind === DISPATCH_ACTION_KIND.ACTIVITY_LOOKAHEAD_SYNC || action.kind === DISPATCH_ACTION_KIND.BASELINE_APPLY || action.kind === DISPATCH_ACTION_KIND.PONDERATOR_CRITERION_SET || action.kind === DISPATCH_ACTION_KIND.STATUS_CRITERIA_SET || action.kind === DISPATCH_ACTION_KIND.ACTIVITY_CLIPBOARD_CLEAR || action.kind === DISPATCH_ACTION_KIND.ACTIVITY_COPY || action.kind === DISPATCH_ACTION_KIND.SELECTION_TOGGLE || action.kind === DISPATCH_ACTION_KIND.SELECTION_REPLACE || action.kind === DISPATCH_ACTION_KIND.VISIBILITY_SET || action.kind === DISPATCH_ACTION_KIND.FILTER_SET || action.kind === DISPATCH_ACTION_KIND.SORT_SET || action.kind === DISPATCH_ACTION_KIND.VIEW_ATTRIBUTES_SET || action.kind === DISPATCH_ACTION_KIND.GROUP_SET || action.kind === DISPATCH_ACTION_KIND.WBS_DEPTH_SET) {
21256
21370
  return DISPATCH_HISTORY_POLICY.SKIP;
21257
21371
  }
21258
21372
  return DISPATCH_HISTORY_POLICY.RECORD;
@@ -24509,6 +24623,11 @@ var ScheduleCore = class _ScheduleCore {
24509
24623
  this.assertReady();
24510
24624
  return cloneDomainValue(this.coreRuntime.state.getGroup());
24511
24625
  }
24626
+ /** @returns How deep the WBS reaches the screen, or `null` for every level. */
24627
+ getWbsDepth() {
24628
+ this.assertReady();
24629
+ return this.coreRuntime.state.getWbsDepth();
24630
+ }
24512
24631
  /** @returns Whether the parent currently has a direct child. */
24513
24632
  hasChild(parentId) {
24514
24633
  this.assertReady();
@@ -25480,6 +25599,7 @@ exports.FILTER_LOGIC = FILTER_LOGIC;
25480
25599
  exports.FILTER_OPERATOR = FILTER_OPERATOR;
25481
25600
  exports.FILTER_REJECTION_REASON = FILTER_REJECTION_REASON;
25482
25601
  exports.FILTER_VALUE_KIND = FILTER_VALUE_KIND;
25602
+ exports.FLAT_WBS_DEPTH = FLAT_WBS_DEPTH;
25483
25603
  exports.GROUP_ID_PREFIX = GROUP_ID_PREFIX;
25484
25604
  exports.GROUP_ID_SEPARATOR = GROUP_ID_SEPARATOR;
25485
25605
  exports.LINK_BATCH_OPERATION_KIND = LINK_BATCH_OPERATION_KIND;