@sap-ux/preview-middleware 0.11.3 → 0.11.5

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.
@@ -29,6 +29,20 @@ sap.ui.define(["sap/m/MessageToast", "sap/ui/model/json/JSONModel", "sap/ui/dt/O
29
29
  this.getView()?.setModel(this.model);
30
30
  this.dialog.open();
31
31
  },
32
+ specialIndexHandling: function _specialIndexHandling(specialIndexAggregation) {
33
+ const overlay = OverlayRegistry.getOverlay(this.runtimeControl);
34
+ const aggregations = overlay.getDesignTimeMetadata().getData().aggregations;
35
+ if (specialIndexAggregation in aggregations && 'specialIndexHandling' in aggregations[specialIndexAggregation]) {
36
+ const controlType = this.runtimeControl.getMetadata().getName();
37
+ this.model.setProperty('/indexHandlingFlag', false);
38
+ this.model.setProperty('/specialIndexHandlingIcon', true);
39
+ this.model.setProperty('/iconTooltip', `Index is defined by special logic of ${controlType} and can't be set here`);
40
+ } else {
41
+ this.model.setProperty('/indexHandlingFlag', true);
42
+ this.model.setProperty('/specialIndexHandlingIcon', false);
43
+ this.model.setProperty('/specialIndexHandlingIconPressed', false);
44
+ }
45
+ },
32
46
  onAggregationChanged: function _onAggregationChanged(event) {
33
47
  const source = event.getSource();
34
48
  const selectedKey = source.getSelectedKey();
@@ -43,6 +57,7 @@ sap.ui.define(["sap/m/MessageToast", "sap/ui/model/json/JSONModel", "sap/ui/dt/O
43
57
  newSelectedControlChildren = newSelectedControlChildren.map(key => {
44
58
  return parseInt(key);
45
59
  });
60
+ this.specialIndexHandling(selectedItemText);
46
61
  const updatedIndexArray = this.fillIndexArray(newSelectedControlChildren);
47
62
  this.model.setProperty('/index', updatedIndexArray);
48
63
  this.model.setProperty('/selectedIndex', updatedIndexArray.length - 1);
@@ -105,11 +120,13 @@ sap.ui.define(["sap/m/MessageToast", "sap/ui/model/json/JSONModel", "sap/ui/dt/O
105
120
  obj.key = 'default';
106
121
  this.model.setProperty('/selectedAggregation/key', obj.key);
107
122
  this.model.setProperty('/selectedAggregation/value', obj.value);
123
+ this.specialIndexHandling(obj.value);
108
124
  }
109
125
  });
110
126
  } else {
111
127
  this.model.setProperty('/selectedAggregation/key', controlAggregation[0].key);
112
128
  this.model.setProperty('/selectedAggregation/value', controlAggregation[0].value);
129
+ this.specialIndexHandling(controlAggregation[0].value);
113
130
  }
114
131
  try {
115
132
  const {
@@ -59,6 +59,28 @@ export default class AddFragment extends BaseDialog {
59
59
  this.dialog.open();
60
60
  }
61
61
 
62
+ /**
63
+ * Handles the index field whenever a specific aggregation is chosen
64
+ *
65
+ * @param specialIndexAggregation string | number
66
+ */
67
+ private specialIndexHandling(specialIndexAggregation: string | number): void {
68
+ const overlay = OverlayRegistry.getOverlay(this.runtimeControl as UI5Element);
69
+ const aggregations = overlay.getDesignTimeMetadata().getData().aggregations;
70
+
71
+ if(specialIndexAggregation in aggregations && 'specialIndexHandling' in aggregations[specialIndexAggregation]) {
72
+ const controlType = this.runtimeControl.getMetadata().getName();
73
+ this.model.setProperty('/indexHandlingFlag', false);
74
+ this.model.setProperty('/specialIndexHandlingIcon', true);
75
+ this.model.setProperty('/iconTooltip', `Index is defined by special logic of ${controlType} and can't be set here`);
76
+
77
+ } else {
78
+ this.model.setProperty('/indexHandlingFlag', true);
79
+ this.model.setProperty('/specialIndexHandlingIcon', false);
80
+ this.model.setProperty('/specialIndexHandlingIconPressed', false);
81
+ }
82
+ }
83
+
62
84
  /**
63
85
  * Handles the change in aggregations
64
86
  *
@@ -85,6 +107,8 @@ export default class AddFragment extends BaseDialog {
85
107
  newSelectedControlChildren = newSelectedControlChildren.map((key) => {
86
108
  return parseInt(key);
87
109
  });
110
+
111
+ this.specialIndexHandling(selectedItemText);
88
112
 
89
113
  const updatedIndexArray: { key: number; value: number }[] = this.fillIndexArray(newSelectedControlChildren);
90
114
 
@@ -178,11 +202,13 @@ export default class AddFragment extends BaseDialog {
178
202
  obj.key = 'default';
179
203
  this.model.setProperty('/selectedAggregation/key', obj.key);
180
204
  this.model.setProperty('/selectedAggregation/value', obj.value);
205
+ this.specialIndexHandling(obj.value);
181
206
  }
182
207
  });
183
208
  } else {
184
209
  this.model.setProperty('/selectedAggregation/key', controlAggregation[0].key);
185
210
  this.model.setProperty('/selectedAggregation/value', controlAggregation[0].value);
211
+ this.specialIndexHandling(controlAggregation[0].value);
186
212
  }
187
213
 
188
214
  try {
@@ -23,14 +23,23 @@
23
23
  <core:Item key="{key}" text="{value}" />
24
24
  </ComboBox>
25
25
  <Label text="Index" />
26
- <ComboBox
27
- selectedKey='{/selectedIndex}'
28
- items="{
29
- path: '/index',
30
- sorter: { path: 'text' }
31
- }">
32
- <core:Item key="{key}" text="{value}" />
33
- </ComboBox>
26
+ <HBox alignItems="Center">
27
+ <ComboBox
28
+ enabled="{/indexHandlingFlag}"
29
+ selectedKey='{/selectedIndex}'
30
+ items="{
31
+ path: '/index',
32
+ sorter: { path: 'text' }
33
+ }">
34
+ <core:Item key="{key}" text="{value}" />
35
+ </ComboBox>
36
+ <core:Icon
37
+ useIconTooltip="false"
38
+ visible="{/specialIndexHandlingIcon}"
39
+ src="sap-icon://message-information"
40
+ class= "sapUiTinyMarginBegin"
41
+ tooltip="{/iconTooltip}" />
42
+ </HBox>
34
43
  <Label text="Fragment Name" />
35
44
  <Input
36
45
  description=".fragment.xml"
@@ -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.3",
12
+ "version": "0.11.5",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -23,9 +23,9 @@
23
23
  ],
24
24
  "dependencies": {
25
25
  "ejs": "3.1.9",
26
- "@sap-ux/logger": "0.4.0",
26
+ "@sap-ux/control-property-editor-sources": "npm:@sap-ux/control-property-editor@0.4.3",
27
27
  "@sap-ux/adp-tooling": "0.7.1",
28
- "@sap-ux/control-property-editor-sources": "npm:@sap-ux/control-property-editor@0.4.2"
28
+ "@sap-ux/logger": "0.4.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/ejs": "3.1.2",
@@ -36,7 +36,7 @@
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",
39
+ "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.8.3",
40
40
  "@sap-ux/project-access": "1.15.5",
41
41
  "@sap-ux/store": "0.4.0"
42
42
  },