@sap-ux/preview-middleware 0.16.132 → 0.16.133

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.
@@ -13,7 +13,9 @@ sap.ui.define(["../../../utils/core", "../table-quick-action-base"], function (_
13
13
  const CONTROL_TYPES = [SMART_TABLE_TYPE, M_TABLE_TYPE, 'sap.ui.table.TreeTable', 'sap.ui.table.Table'];
14
14
  class ChangeTableColumnsQuickAction extends TableQuickActionDefinitionBase {
15
15
  constructor(context) {
16
- super(CHANGE_TABLE_COLUMNS, CONTROL_TYPES, 'V2_QUICK_ACTION_CHANGE_TABLE_COLUMNS', context, true);
16
+ super(CHANGE_TABLE_COLUMNS, CONTROL_TYPES, 'V2_QUICK_ACTION_CHANGE_TABLE_COLUMNS', context, {
17
+ includeServiceAction: true
18
+ });
17
19
  }
18
20
  async execute(path) {
19
21
  const {
@@ -18,7 +18,9 @@ export class ChangeTableColumnsQuickAction
18
18
  implements NestedQuickActionDefinition
19
19
  {
20
20
  constructor(context: QuickActionContext) {
21
- super(CHANGE_TABLE_COLUMNS, CONTROL_TYPES, 'V2_QUICK_ACTION_CHANGE_TABLE_COLUMNS', context, true);
21
+ super(CHANGE_TABLE_COLUMNS, CONTROL_TYPES, 'V2_QUICK_ACTION_CHANGE_TABLE_COLUMNS', context, {
22
+ includeServiceAction: true
23
+ });
22
24
  }
23
25
  async execute(path: string): Promise<FlexCommand[]> {
24
26
  const { table, iconTabBarFilterKey, changeColumnActionId, sectionInfo } = this.tableMap[path];
@@ -44,7 +44,9 @@ sap.ui.define(["../../../utils/core", "sap/ui/dt/OverlayRegistry", "../../init-d
44
44
  }
45
45
  class AddTableCustomColumnQuickAction extends TableQuickActionDefinitionBase {
46
46
  constructor(context) {
47
- super(CREATE_TABLE_CUSTOM_COLUMN, CONTROL_TYPES, 'QUICK_ACTION_ADD_CUSTOM_TABLE_COLUMN', context);
47
+ super(CREATE_TABLE_CUSTOM_COLUMN, CONTROL_TYPES, 'QUICK_ACTION_ADD_CUSTOM_TABLE_COLUMN', context, {
48
+ areTableRowsRequired: true
49
+ });
48
50
  }
49
51
  async execute(path) {
50
52
  const {
@@ -64,7 +64,9 @@ export class AddTableCustomColumnQuickAction
64
64
  implements NestedQuickActionDefinition
65
65
  {
66
66
  constructor(context: QuickActionContext) {
67
- super(CREATE_TABLE_CUSTOM_COLUMN, CONTROL_TYPES, 'QUICK_ACTION_ADD_CUSTOM_TABLE_COLUMN', context);
67
+ super(CREATE_TABLE_CUSTOM_COLUMN, CONTROL_TYPES, 'QUICK_ACTION_ADD_CUSTOM_TABLE_COLUMN', context, {
68
+ areTableRowsRequired: true
69
+ });
68
70
  }
69
71
 
70
72
  async execute(path: string): Promise<FlexCommand[]> {
@@ -53,12 +53,13 @@ sap.ui.define([
53
53
  get textKey() {
54
54
  return this.defaultTextKey;
55
55
  }
56
- constructor(type, controlTypes, defaultTextKey, context, includeServiceAction) {
56
+ constructor(type, controlTypes, defaultTextKey, context) {
57
+ let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
57
58
  this.type = type;
58
59
  this.controlTypes = controlTypes;
59
60
  this.defaultTextKey = defaultTextKey;
60
61
  this.context = context;
61
- this.includeServiceAction = includeServiceAction;
62
+ this.options = options;
62
63
  }
63
64
  async initialize() {
64
65
  const version = await getUi5Version();
@@ -76,11 +77,9 @@ sap.ui.define([
76
77
  if (section) {
77
78
  this.collectChildrenInSection(section, table);
78
79
  } else if (this.iconTabBar && tabKey) {
79
- this.children.push({
80
- label: `'${ iconTabBarfilterMap[tabKey] }' table`,
81
- enabled: true,
82
- children: []
83
- });
80
+ const label = `'${ iconTabBarfilterMap[tabKey] }' table`;
81
+ const child = this.createChild(label, table);
82
+ this.children.push(child);
84
83
  this.tableMap[`${ this.children.length - 1 }`] = {
85
84
  table,
86
85
  iconTabBarFilterKey: tabKey,
@@ -89,7 +88,7 @@ sap.ui.define([
89
88
  } else {
90
89
  this.processTable(table);
91
90
  }
92
- if (this.includeServiceAction) {
91
+ if (this.options.includeServiceAction) {
93
92
  const actions = await this.context.actionService.get(table.getId());
94
93
  const actionsIds = await getActionId(table);
95
94
  const changeColumnAction = actionsIds.find(actionId => actions.findIndex(action => action.id === actionId) > -1);
@@ -102,6 +101,23 @@ sap.ui.define([
102
101
  this.isApplicable = true;
103
102
  }
104
103
  }
104
+ getInternalTable(table) {
105
+ try {
106
+ let tableInternal;
107
+ if (isA(SMART_TABLE_TYPE, table)) {
108
+ const itemsAggregation = table.getAggregation('items');
109
+ tableInternal = itemsAggregation.find(item => [
110
+ M_TABLE_TYPE,
111
+ TREE_TABLE_TYPE,
112
+ ANALYTICAL_TABLE_TYPE,
113
+ GRID_TABLE_TYPE
114
+ ].some(tType => isA(tType, item)));
115
+ }
116
+ return tableInternal;
117
+ } catch (error) {
118
+ return undefined;
119
+ }
120
+ }
105
121
  getTableLabel(table) {
106
122
  if (isA(SMART_TABLE_TYPE, table) || isA(MDC_TABLE_TYPE, table)) {
107
123
  const header = table.getHeader();
@@ -146,24 +162,18 @@ sap.ui.define([
146
162
  } else if (subSections.length > 1) {
147
163
  const sectionChild = this.children.find(val => val.label === `${ section.getTitle() } section`);
148
164
  let tableMapIndex = `${ this.children.length - 1 }`;
165
+ const label = this.getTableLabel(table);
166
+ const child = this.createChild(label, table);
149
167
  if (!sectionChild) {
150
168
  tableMapIndex = `${ tableMapIndex }/0`;
151
169
  this.children.push({
152
170
  label: `'${ section?.getTitle() }' section`,
153
171
  enabled: true,
154
- children: [{
155
- label: this.getTableLabel(table),
156
- enabled: true,
157
- children: []
158
- }]
172
+ children: [child]
159
173
  });
160
174
  } else {
161
175
  tableMapIndex = `${ tableMapIndex }/${ sectionChild.children.length - 1 }`;
162
- sectionChild.children.push({
163
- label: this.getTableLabel(table),
164
- enabled: true,
165
- children: []
166
- });
176
+ sectionChild.children.push(child);
167
177
  }
168
178
  this.tableMap[tableMapIndex] = {
169
179
  table,
@@ -184,11 +194,9 @@ sap.ui.define([
184
194
  MDC_TABLE_TYPE,
185
195
  TREE_TABLE_TYPE
186
196
  ].some(type => isA(type, table))) {
187
- this.children.push({
188
- label: this.getTableLabel(table),
189
- enabled: true,
190
- children: []
191
- });
197
+ const label = this.getTableLabel(table);
198
+ const child = this.createChild(label, table);
199
+ this.children.push(child);
192
200
  }
193
201
  this.tableMap[`${ this.children.length - 1 }`] = {
194
202
  table,
@@ -212,6 +220,23 @@ sap.ui.define([
212
220
  children: this.children
213
221
  };
214
222
  }
223
+ createChild(label, table) {
224
+ const child = {
225
+ label,
226
+ enabled: true,
227
+ children: []
228
+ };
229
+ if (!this.options.areTableRowsRequired) {
230
+ return child;
231
+ }
232
+ const innerTable = this.getInternalTable(table);
233
+ const tableRows = innerTable?.getAggregation('items') || [];
234
+ if (isA(M_TABLE_TYPE, innerTable) && !tableRows.length) {
235
+ child.enabled = false;
236
+ child.tooltip = this.context.resourceBundle.getText('TABLE_CUSTOM_COLUMN_ACTION_NOT_AVAILABLE');
237
+ }
238
+ return child;
239
+ }
215
240
  }
216
241
  var __exports = { __esModule: true };
217
242
  __exports.SMART_TABLE_TYPE = SMART_TABLE_TYPE;
@@ -14,6 +14,7 @@ import { getUi5Version, isLowerThanMinimalUi5Version } from '../../utils/version
14
14
  import ObjectPageSection from 'sap/uxap/ObjectPageSection';
15
15
  import ObjectPageSubSection from 'sap/uxap/ObjectPageSubSection';
16
16
  import ObjectPageLayout from 'sap/uxap/ObjectPageLayout';
17
+ import ManagedObject from 'sap/ui/base/ManagedObject';
17
18
 
18
19
  const SMART_TABLE_ACTION_ID = 'CTX_COMP_VARIANT_CONTENT';
19
20
  const M_TABLE_ACTION_ID = 'CTX_ADD_ELEMENTS_AS_CHILD';
@@ -39,6 +40,10 @@ async function getActionId(table: UI5Element): Promise<string[]> {
39
40
 
40
41
  return [M_TABLE_ACTION_ID, SETTINGS_ID];
41
42
  }
43
+ export type TableQuickActionsOptions = {
44
+ includeServiceAction?: boolean;
45
+ areTableRowsRequired?: boolean;
46
+ };
42
47
 
43
48
  /**
44
49
  * Base class for table quick actions.
@@ -85,7 +90,7 @@ export abstract class TableQuickActionDefinitionBase {
85
90
  protected readonly controlTypes: string[],
86
91
  protected readonly defaultTextKey: string,
87
92
  protected readonly context: QuickActionContext,
88
- protected includeServiceAction?: boolean
93
+ protected options: TableQuickActionsOptions = {}
89
94
  ) {}
90
95
 
91
96
  /**
@@ -109,11 +114,9 @@ export abstract class TableQuickActionDefinitionBase {
109
114
  if (section) {
110
115
  this.collectChildrenInSection(section, table);
111
116
  } else if (this.iconTabBar && tabKey) {
112
- this.children.push({
113
- label: `'${iconTabBarfilterMap[tabKey]}' table`,
114
- enabled: true,
115
- children: []
116
- });
117
+ const label = `'${iconTabBarfilterMap[tabKey]}' table`;
118
+ const child = this.createChild(label, table);
119
+ this.children.push(child);
117
120
  this.tableMap[`${this.children.length - 1}`] = {
118
121
  table,
119
122
  iconTabBarFilterKey: tabKey,
@@ -124,7 +127,7 @@ export abstract class TableQuickActionDefinitionBase {
124
127
  }
125
128
 
126
129
  // add action id to the table map, if the service actions are needed.
127
- if (this.includeServiceAction) {
130
+ if (this.options.includeServiceAction) {
128
131
  const actions = await this.context.actionService.get(table.getId());
129
132
  const actionsIds = await getActionId(table);
130
133
 
@@ -142,6 +145,30 @@ export abstract class TableQuickActionDefinitionBase {
142
145
  }
143
146
  }
144
147
 
148
+ /**
149
+ * Retrieves the internal table control from a UI5Element.
150
+ *
151
+ * @param table - The UI5Element instance to analyze.
152
+ * @returns The internal table otherwise undefined.
153
+ */
154
+ protected getInternalTable(table: UI5Element): UI5Element | undefined {
155
+ try {
156
+ let tableInternal: ManagedObject | undefined;
157
+
158
+ if (isA<SmartTable>(SMART_TABLE_TYPE, table)) {
159
+ const itemsAggregation = table.getAggregation('items') as ManagedObject[];
160
+ tableInternal = itemsAggregation.find((item) =>
161
+ [M_TABLE_TYPE, TREE_TABLE_TYPE, ANALYTICAL_TABLE_TYPE, GRID_TABLE_TYPE].some((tType) =>
162
+ isA(tType, item)
163
+ )
164
+ );
165
+ }
166
+ return tableInternal as UI5Element | undefined;
167
+ } catch (error) {
168
+ return undefined;
169
+ }
170
+ }
171
+
145
172
  /**
146
173
  * Determines table label for the given table element
147
174
  * @param table - table element
@@ -204,26 +231,19 @@ export abstract class TableQuickActionDefinitionBase {
204
231
  } else if (subSections.length > 1) {
205
232
  const sectionChild = this.children.find((val) => val.label === `${section.getTitle()} section`);
206
233
  let tableMapIndex = `${this.children.length - 1}`;
234
+ const label = this.getTableLabel(table);
235
+ const child = this.createChild(label, table);
207
236
  if (!sectionChild) {
208
237
  tableMapIndex = `${tableMapIndex}/0`;
238
+
209
239
  this.children.push({
210
240
  label: `'${section?.getTitle()}' section`,
211
241
  enabled: true,
212
- children: [
213
- {
214
- label: this.getTableLabel(table),
215
- enabled: true,
216
- children: []
217
- }
218
- ]
242
+ children: [child]
219
243
  });
220
244
  } else {
221
245
  tableMapIndex = `${tableMapIndex}/${sectionChild.children.length - 1}`;
222
- sectionChild.children.push({
223
- label: this.getTableLabel(table),
224
- enabled: true,
225
- children: []
226
- });
246
+ sectionChild.children.push(child);
227
247
  }
228
248
 
229
249
  this.tableMap[tableMapIndex] = {
@@ -245,11 +265,9 @@ export abstract class TableQuickActionDefinitionBase {
245
265
  sectionInfo?: { section: ObjectPageSection; subSection: ObjectPageSubSection; layout?: ObjectPageLayout }
246
266
  ): void {
247
267
  if ([SMART_TABLE_TYPE, M_TABLE_TYPE, MDC_TABLE_TYPE, TREE_TABLE_TYPE].some((type) => isA(type, table))) {
248
- this.children.push({
249
- label: this.getTableLabel(table),
250
- enabled: true,
251
- children: []
252
- });
268
+ const label = this.getTableLabel(table);
269
+ const child = this.createChild(label, table);
270
+ this.children.push(child);
253
271
  }
254
272
 
255
273
  this.tableMap[`${this.children.length - 1}`] = {
@@ -284,4 +302,22 @@ export abstract class TableQuickActionDefinitionBase {
284
302
  children: this.children
285
303
  };
286
304
  }
305
+
306
+ createChild(label: string, table: UI5Element): NestedQuickActionChild {
307
+ const child: NestedQuickActionChild = {
308
+ label,
309
+ enabled: true,
310
+ children: []
311
+ };
312
+ if (!this.options.areTableRowsRequired) {
313
+ return child;
314
+ }
315
+ const innerTable = this.getInternalTable(table);
316
+ const tableRows = (innerTable?.getAggregation('items') as ManagedObject[]) || [];
317
+ if (isA(M_TABLE_TYPE, innerTable) && !tableRows.length) {
318
+ child.enabled = false;
319
+ child.tooltip = this.context.resourceBundle.getText('TABLE_CUSTOM_COLUMN_ACTION_NOT_AVAILABLE');
320
+ }
321
+ return child;
322
+ }
287
323
  }
@@ -38,4 +38,6 @@ CPE_CHANGES_VISIBLE_AFTER_SAVE_AND_RELOAD_MESSAGE = Note: The change will be vis
38
38
  TABLE_ROWS_NEEDED_TO_CREATE_CUSTOM_COLUMN=At least one table row is required to create new custom column. Make sure the table data is loaded and try again.
39
39
 
40
40
  HIGHER_LAYER_CHANGES_INFO_MESSAGE=The preview of the project was reloaded due to detected changes in higher layer than the one used in your project.
41
+
42
+ TABLE_CUSTOM_COLUMN_ACTION_NOT_AVAILABLE=This action has been disabled because the table rows are not available. Please load the table data and try again
41
43
  THE_CHANGE_HAS_ALREADY_BEEN_MADE=This option has been disabled because the change has already been made
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.16.132",
12
+ "version": "0.16.133",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -46,9 +46,9 @@
46
46
  "supertest": "6.3.3",
47
47
  "@sap-ux-private/playwright": "0.1.0",
48
48
  "dotenv": "16.3.1",
49
- "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.11.37",
50
- "@sap-ux/axios-extension": "1.17.4",
49
+ "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.11.38",
51
50
  "@sap-ux/store": "0.9.3",
51
+ "@sap-ux/axios-extension": "1.17.4",
52
52
  "@sap-ux/ui5-info": "0.8.3",
53
53
  "@sap-ux/i18n": "0.2.0"
54
54
  },