@sap-ux/preview-middleware 0.11.2 → 0.11.4

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.
@@ -142,10 +142,16 @@ sap.ui.define([
142
142
  if (typeof command.getCommands === 'function') {
143
143
  const subCommands = command.getCommands();
144
144
  subCommands.forEach(command => {
145
- activeChanges.push(this.prepareChangeType(command, inactiveCommandCount, i));
145
+ const pendingChange = this.prepareChangeType(command, inactiveCommandCount, i);
146
+ if (pendingChange) {
147
+ activeChanges.push(pendingChange);
148
+ }
146
149
  });
147
150
  } else {
148
- activeChanges.push(this.prepareChangeType(command, inactiveCommandCount, i));
151
+ const pendingChange = this.prepareChangeType(command, inactiveCommandCount, i);
152
+ if (pendingChange) {
153
+ activeChanges.push(pendingChange);
154
+ }
149
155
  }
150
156
  } catch (error) {
151
157
  Log.error('CPE: Change creation Failed', error);
@@ -161,8 +167,11 @@ sap.ui.define([
161
167
  prepareChangeType(command, inactiveCommandCount, index) {
162
168
  let result;
163
169
  let value = '';
164
- const selector = command.getSelector();
165
- const changeType = command.getChangeType();
170
+ const selectorId = this.getCommandSelectorId(command);
171
+ const changeType = this.getCommandChangeType(command);
172
+ if (!selectorId || !changeType) {
173
+ return undefined;
174
+ }
166
175
  switch (changeType) {
167
176
  case 'propertyChange':
168
177
  value = command.getProperty('newValue');
@@ -175,7 +184,7 @@ sap.ui.define([
175
184
  result = {
176
185
  type: 'pending',
177
186
  changeType,
178
- controlId: selector.id,
187
+ controlId: selectorId,
179
188
  propertyName: command.getProperty('propertyName'),
180
189
  isActive: index >= inactiveCommandCount,
181
190
  value,
@@ -184,7 +193,7 @@ sap.ui.define([
184
193
  } else {
185
194
  result = {
186
195
  type: 'pending',
187
- controlId: selector.id,
196
+ controlId: selectorId,
188
197
  changeType,
189
198
  isActive: index >= inactiveCommandCount,
190
199
  controlName: command.getElement().getMetadata().getName().split('.').pop() ?? ''
@@ -192,6 +201,29 @@ sap.ui.define([
192
201
  }
193
202
  return result;
194
203
  }
204
+ retryOperations(operations) {
205
+ for (const operation of operations) {
206
+ try {
207
+ return operation();
208
+ } catch (error) {
209
+ Log.error(`Retry operation failed: ${ error?.message }`);
210
+ continue;
211
+ }
212
+ }
213
+ return undefined;
214
+ }
215
+ getCommandChangeType(command) {
216
+ return this.retryOperations([
217
+ () => command.getChangeType(),
218
+ () => command.getPreparedChange().getDefinition().changeType
219
+ ]);
220
+ }
221
+ getCommandSelectorId(command) {
222
+ return this.retryOperations([
223
+ () => command.getSelector().id,
224
+ () => command.getElement().getProperty('persistencyKey')
225
+ ]);
226
+ }
195
227
  }
196
228
  var __exports = { __esModule: true };
197
229
  __exports.ChangeService = ChangeService;
@@ -16,7 +16,7 @@ import type { SelectionService } from '../selection';
16
16
 
17
17
  import type { ActionSenderFunction, SubscribeFunction, UI5AdaptationOptions } from '../types';
18
18
  import type Event from 'sap/ui/base/Event';
19
- import type BaseCommand from 'sap/ui/rta/command/BaseCommand';
19
+ import type FlexCommand from 'sap/ui/rta/command/FlexCommand';
20
20
  import Log from 'sap/base/Log';
21
21
 
22
22
  interface ChangeContent {
@@ -247,15 +247,21 @@ export class ChangeService {
247
247
  const executedCommands = stack.getAllExecutedCommands();
248
248
  const inactiveCommandCount = allCommands.length - executedCommands.length;
249
249
  let activeChanges: PendingChange[] = [];
250
- allCommands.forEach((command: BaseCommand, i): void => {
250
+ allCommands.forEach((command: FlexCommand, i): void => {
251
251
  try {
252
252
  if (typeof command.getCommands === 'function') {
253
253
  const subCommands = command.getCommands();
254
254
  subCommands.forEach((command) => {
255
- activeChanges.push(this.prepareChangeType(command, inactiveCommandCount, i));
255
+ const pendingChange = this.prepareChangeType(command, inactiveCommandCount, i);
256
+ if (pendingChange) {
257
+ activeChanges.push(pendingChange);
258
+ }
256
259
  });
257
260
  } else {
258
- activeChanges.push(this.prepareChangeType(command, inactiveCommandCount, i));
261
+ const pendingChange = this.prepareChangeType(command, inactiveCommandCount, i);
262
+ if (pendingChange) {
263
+ activeChanges.push(pendingChange);
264
+ }
259
265
  }
260
266
  } catch (error) {
261
267
  Log.error('CPE: Change creation Failed', error);
@@ -272,11 +278,20 @@ export class ChangeService {
272
278
  };
273
279
  }
274
280
 
275
- private prepareChangeType(command: BaseCommand, inactiveCommandCount: number, index: number): PendingChange {
281
+ private prepareChangeType(
282
+ command: FlexCommand,
283
+ inactiveCommandCount: number,
284
+ index: number
285
+ ): PendingChange | undefined {
276
286
  let result: PendingChange;
277
287
  let value = '';
278
- const selector = command.getSelector();
279
- const changeType = command.getChangeType();
288
+ const selectorId = this.getCommandSelectorId(command);
289
+ const changeType = this.getCommandChangeType(command);
290
+
291
+ if (!selectorId || !changeType) {
292
+ return undefined;
293
+ }
294
+
280
295
  switch (changeType) {
281
296
  case 'propertyChange':
282
297
  value = command.getProperty('newValue');
@@ -289,7 +304,7 @@ export class ChangeService {
289
304
  result = {
290
305
  type: 'pending',
291
306
  changeType,
292
- controlId: selector.id,
307
+ controlId: selectorId,
293
308
  propertyName: command.getProperty('propertyName'),
294
309
  isActive: index >= inactiveCommandCount,
295
310
  value,
@@ -298,7 +313,7 @@ export class ChangeService {
298
313
  } else {
299
314
  result = {
300
315
  type: 'pending',
301
- controlId: selector.id,
316
+ controlId: selectorId,
302
317
  changeType,
303
318
  isActive: index >= inactiveCommandCount,
304
319
  controlName: command.getElement().getMetadata().getName().split('.').pop() ?? ''
@@ -307,4 +322,48 @@ export class ChangeService {
307
322
 
308
323
  return result;
309
324
  }
325
+
326
+ /**
327
+ * Retry operations.
328
+ *
329
+ * @param operations to be executed
330
+ * @returns first successfull operation result or undefined
331
+ */
332
+ private retryOperations<T>(operations: Array<() => T>): T | undefined {
333
+ for (const operation of operations) {
334
+ try {
335
+ return operation();
336
+ } catch (error) {
337
+ Log.error(`Retry operation failed: ${error?.message}`);
338
+ continue;
339
+ }
340
+ }
341
+ return undefined;
342
+ }
343
+
344
+ /**
345
+ * Get command change type.
346
+ *
347
+ * @param command to be executed for creating change
348
+ * @returns command change type or undefined
349
+ */
350
+ private getCommandChangeType(command: FlexCommand): string | undefined {
351
+ return this.retryOperations([
352
+ () => command.getChangeType(),
353
+ () => command.getPreparedChange().getDefinition().changeType
354
+ ]);
355
+ }
356
+
357
+ /**
358
+ * Get command selector id.
359
+ *
360
+ * @param command to be executed for creating change
361
+ * @returns command selector id or undefined
362
+ */
363
+ private getCommandSelectorId(command: FlexCommand): string | undefined {
364
+ return this.retryOperations([
365
+ () => command.getSelector().id,
366
+ () => command.getElement().getProperty('persistencyKey')
367
+ ]);
368
+ }
310
369
  }
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "bugs": {
10
10
  "url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Apreview-middleware"
11
11
  },
12
- "version": "0.11.2",
12
+ "version": "0.11.4",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -24,8 +24,8 @@
24
24
  "dependencies": {
25
25
  "ejs": "3.1.9",
26
26
  "@sap-ux/logger": "0.4.0",
27
- "@sap-ux/adp-tooling": "0.7.0",
28
- "@sap-ux/control-property-editor-sources": "npm:@sap-ux/control-property-editor@0.4.2"
27
+ "@sap-ux/control-property-editor-sources": "npm:@sap-ux/control-property-editor@0.4.3",
28
+ "@sap-ux/adp-tooling": "0.7.1"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/ejs": "3.1.2",
@@ -36,8 +36,8 @@
36
36
  "npm-run-all": "4.1.5",
37
37
  "nock": "13.2.1",
38
38
  "supertest": "6.3.3",
39
- "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.8.1",
40
- "@sap-ux/project-access": "1.15.4",
39
+ "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.8.2",
40
+ "@sap-ux/project-access": "1.15.5",
41
41
  "@sap-ux/store": "0.4.0"
42
42
  },
43
43
  "peerDependencies": {