@contrail/extensions-sdk 1.0.33 → 1.0.34

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.
@@ -8,7 +8,8 @@ export declare enum PlanCommand {
8
8
  GET_PLACEHOLDERS = "plan:get_placeholders",
9
9
  GET_VIEW_STATE = "plan:get_view_state",
10
10
  ASSIGN_ITEMS = "plan:assign_items",
11
- SCROLL_TO_PLACEHOLDER = "plan:scroll_to_placeholder"
11
+ SCROLL_TO_PLACEHOLDER = "plan:scroll_to_placeholder",
12
+ UPDATE_PLACEHOLDERS = "plan:update_placeholders"
12
13
  }
13
14
  /**
14
15
  * A row on a plan. Beyond the item linkage below, properties are the org-configured
@@ -43,6 +44,45 @@ export interface PlaceholderItemAssignment {
43
44
  /** The item to assign — an item family or an item option. */
44
45
  itemId: string;
45
46
  }
47
+ /**
48
+ * Edits to one existing row, keyed by property slug.
49
+ *
50
+ * Only two kinds of property can be written this way:
51
+ *
52
+ * - `isDropped` — `true` drops the row, `false` restores it.
53
+ * - Assortment-item properties (`forecast`, `targetVolume`, ...) — plan-placeholder properties
54
+ * that also exist on the `assortment-item` type and on neither `item` nor `project-item`.
55
+ *
56
+ * Item and project-item properties are refused: edit those entities directly and the plan picks the
57
+ * change up through propagation.
58
+ *
59
+ * Values take the shape {@link PlanApp.getPlaceholders} returns. An object-reference or user-list
60
+ * property takes the referenced object (with its `id`) or `null`.
61
+ */
62
+ export interface PlaceholderChange {
63
+ /** The row to edit. */
64
+ id: string;
65
+ changes: {
66
+ [propertySlug: string]: any;
67
+ };
68
+ }
69
+ export interface UpdatePlaceholdersOptions {
70
+ /** Skip the undo/redo entry. Intended for bulk programmatic writes. */
71
+ skipRecordingUndoRedo?: boolean;
72
+ }
73
+ /** One property edit the plan declined, and why. The row's other edits are still applied. */
74
+ export interface RejectedPlaceholderChange {
75
+ placeholderId: string;
76
+ propertySlug: string;
77
+ /** Human-readable, e.g. `This value is calculated with a formula.` */
78
+ reason: string;
79
+ }
80
+ export interface UpdatePlaceholdersResult {
81
+ /** The edited rows as they are after the write, formulas re-evaluated. */
82
+ placeholders: Array<PlanPlaceholder>;
83
+ /** Edits refused by the row's own rules — permissions, rule sets, value validation, drop checks. */
84
+ rejectedChanges: Array<RejectedPlaceholderChange>;
85
+ }
46
86
  export interface ScrollToPlaceholderOptions {
47
87
  /**
48
88
  * Also bring this column into view horizontally.
@@ -155,6 +195,32 @@ export declare class PlanApp {
155
195
  * Requires the plan to be editable.
156
196
  */
157
197
  static assignItems(assignments: Array<PlaceholderItemAssignment>): Promise<void>;
198
+ /**
199
+ * Edits existing rows: drops or restores them, and sets assortment-item properties such as
200
+ * forecasts. See {@link PlaceholderChange} for what can be written.
201
+ *
202
+ * Runs the same write path as a grid edit, so formulas re-evaluate, the change is undoable, it is
203
+ * persisted, and it is broadcast to other users. Resolves once the write has been applied, with
204
+ * the updated rows.
205
+ *
206
+ * Two kinds of failure are reported differently:
207
+ *
208
+ * - **Throws, and writes nothing,** when the request is wrong: a row id not on this plan, or a
209
+ * property that cannot be written through this method. These are bugs in the caller.
210
+ * - **Rejects individual edits,** listed in `rejectedChanges`, when a row's own rules refuse them:
211
+ * the property is read-only, a formula, or locked by a rule set; the value fails validation; or
212
+ * the row cannot be dropped. Every other edit is applied, as a paste into the grid would be.
213
+ *
214
+ * ```ts
215
+ * const { rejectedChanges } = await PlanApp.updatePlaceholders([
216
+ * { id: rowA, changes: { isDropped: true } },
217
+ * { id: rowB, changes: { forecast: 1200 } },
218
+ * ]);
219
+ * ```
220
+ *
221
+ * Requires the plan to be editable.
222
+ */
223
+ static updatePlaceholders(placeholderChanges: Array<PlaceholderChange>, options?: UpdatePlaceholdersOptions): Promise<UpdatePlaceholdersResult>;
158
224
  /**
159
225
  * Scrolls the plan's grid so a row is in view.
160
226
  *
package/lib/apps/plan.js CHANGED
@@ -23,6 +23,7 @@ var PlanCommand;
23
23
  PlanCommand["GET_VIEW_STATE"] = "plan:get_view_state";
24
24
  PlanCommand["ASSIGN_ITEMS"] = "plan:assign_items";
25
25
  PlanCommand["SCROLL_TO_PLACEHOLDER"] = "plan:scroll_to_placeholder";
26
+ PlanCommand["UPDATE_PLACEHOLDERS"] = "plan:update_placeholders";
26
27
  })(PlanCommand = exports.PlanCommand || (exports.PlanCommand = {}));
27
28
  class PlanApp {
28
29
  static getCurrentPlan() {
@@ -172,6 +173,44 @@ class PlanApp {
172
173
  PlanApp.validateAndReturnResults(results);
173
174
  });
174
175
  }
176
+ /**
177
+ * Edits existing rows: drops or restores them, and sets assortment-item properties such as
178
+ * forecasts. See {@link PlaceholderChange} for what can be written.
179
+ *
180
+ * Runs the same write path as a grid edit, so formulas re-evaluate, the change is undoable, it is
181
+ * persisted, and it is broadcast to other users. Resolves once the write has been applied, with
182
+ * the updated rows.
183
+ *
184
+ * Two kinds of failure are reported differently:
185
+ *
186
+ * - **Throws, and writes nothing,** when the request is wrong: a row id not on this plan, or a
187
+ * property that cannot be written through this method. These are bugs in the caller.
188
+ * - **Rejects individual edits,** listed in `rejectedChanges`, when a row's own rules refuse them:
189
+ * the property is read-only, a formula, or locked by a rule set; the value fails validation; or
190
+ * the row cannot be dropped. Every other edit is applied, as a paste into the grid would be.
191
+ *
192
+ * ```ts
193
+ * const { rejectedChanges } = await PlanApp.updatePlaceholders([
194
+ * { id: rowA, changes: { isDropped: true } },
195
+ * { id: rowB, changes: { forecast: 1200 } },
196
+ * ]);
197
+ * ```
198
+ *
199
+ * Requires the plan to be editable.
200
+ */
201
+ static updatePlaceholders(placeholderChanges, options) {
202
+ return __awaiter(this, void 0, void 0, function* () {
203
+ PlanApp.validatePlanContext();
204
+ if (!(placeholderChanges === null || placeholderChanges === void 0 ? void 0 : placeholderChanges.length)) {
205
+ return { placeholders: [], rejectedChanges: [] };
206
+ }
207
+ const results = yield (0, actions_1.getExtensionActions)().sendMessageToHost({
208
+ command: PlanCommand.UPDATE_PLACEHOLDERS,
209
+ data: { placeholderChanges, options },
210
+ });
211
+ return PlanApp.validateAndReturnResults(results);
212
+ });
213
+ }
175
214
  /**
176
215
  * Scrolls the plan's grid so a row is in view.
177
216
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/extensions-sdk",
3
- "version": "1.0.33",
3
+ "version": "1.0.34",
4
4
  "description": "Client library for interfacing with VibeIQ's services and apps from an extension.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",