@sap-ux/preview-middleware 0.16.76 → 0.16.78

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.
@@ -0,0 +1,208 @@
1
+ 'use strict';
2
+ sap.ui.define([
3
+ 'open/ux/preview/client/thirdparty/@sap-ux-private/control-property-editor-common',
4
+ 'sap/ui/dt/OverlayUtil',
5
+ '../../../cpe/quick-actions/utils',
6
+ '../../../utils/core',
7
+ '../../../utils/version'
8
+ ], function (___sap_ux_private_control_property_editor_common, OverlayUtil, _____cpe_quick_actions_utils, _____utils_core, _____utils_version) {
9
+ 'use strict';
10
+ const NESTED_QUICK_ACTION_KIND = ___sap_ux_private_control_property_editor_common['NESTED_QUICK_ACTION_KIND'];
11
+ const getParentContainer = _____cpe_quick_actions_utils['getParentContainer'];
12
+ const getRelevantControlFromActivePage = _____cpe_quick_actions_utils['getRelevantControlFromActivePage'];
13
+ const getControlById = _____utils_core['getControlById'];
14
+ const isA = _____utils_core['isA'];
15
+ const isManagedObject = _____utils_core['isManagedObject'];
16
+ const getUi5Version = _____utils_version['getUi5Version'];
17
+ const isLowerThanMinimalUi5Version = _____utils_version['isLowerThanMinimalUi5Version'];
18
+ const SMART_TABLE_ACTION_ID = 'CTX_COMP_VARIANT_CONTENT';
19
+ const M_TABLE_ACTION_ID = 'CTX_ADD_ELEMENTS_AS_CHILD';
20
+ const SETTINGS_ID = 'CTX_SETTINGS';
21
+ const ICON_TAB_BAR_TYPE = 'sap.m.IconTabBar';
22
+ const SMART_TABLE_TYPE = 'sap.ui.comp.smarttable.SmartTable';
23
+ const M_TABLE_TYPE = 'sap.m.Table';
24
+ async function getActionId(table) {
25
+ const {major, minor} = await getUi5Version();
26
+ if (isA(SMART_TABLE_TYPE, table)) {
27
+ if (major === 1 && minor === 96) {
28
+ return [SETTINGS_ID];
29
+ } else {
30
+ return [SMART_TABLE_ACTION_ID];
31
+ }
32
+ }
33
+ return [
34
+ M_TABLE_ACTION_ID,
35
+ SETTINGS_ID
36
+ ];
37
+ }
38
+ class TableQuickActionDefinitionBase {
39
+ kind = NESTED_QUICK_ACTION_KIND;
40
+ get id() {
41
+ return `${ this.context.key }-${ this.type }`;
42
+ }
43
+ isActive = false;
44
+ children = [];
45
+ tableMap = {};
46
+ get textKey() {
47
+ return this.defaultTextKey;
48
+ }
49
+ constructor(type, controlTypes, defaultTextKey, context, includeServiceAction) {
50
+ this.type = type;
51
+ this.controlTypes = controlTypes;
52
+ this.defaultTextKey = defaultTextKey;
53
+ this.context = context;
54
+ this.includeServiceAction = includeServiceAction;
55
+ }
56
+ async initialize() {
57
+ const version = await getUi5Version();
58
+ if (isLowerThanMinimalUi5Version(version, {
59
+ major: 1,
60
+ minor: 96
61
+ })) {
62
+ this.isActive = false;
63
+ return;
64
+ }
65
+ const iconTabBarfilterMap = this.buildIconTabBarFilterMap();
66
+ for (const table of getRelevantControlFromActivePage(this.context.controlIndex, this.context.view, this.controlTypes)) {
67
+ const tabKey = Object.keys(iconTabBarfilterMap).find(key => table.getId().endsWith(key));
68
+ const section = getParentContainer(table, 'sap.uxap.ObjectPageSection');
69
+ if (section) {
70
+ this.collectChildrenInSection(section, table);
71
+ } else if (this.iconTabBar && tabKey) {
72
+ this.children.push({
73
+ label: `'${ iconTabBarfilterMap[tabKey] }' table`,
74
+ children: []
75
+ });
76
+ this.tableMap[`${ this.children.length - 1 }`] = {
77
+ table,
78
+ iconTabBarFilterKey: tabKey,
79
+ tableUpdateEventAttachedOnce: false
80
+ };
81
+ } else {
82
+ this.processTable(table);
83
+ }
84
+ if (this.includeServiceAction) {
85
+ const actions = await this.context.actionService.get(table.getId());
86
+ const actionsIds = await getActionId(table);
87
+ const changeColumnAction = actionsIds.find(actionId => actions.findIndex(action => action.id === actionId) > -1);
88
+ Object.keys(this.tableMap).forEach(key => {
89
+ this.tableMap[key].changeColumnActionId = changeColumnAction;
90
+ });
91
+ }
92
+ }
93
+ if (this.children.length > 0) {
94
+ this.isActive = true;
95
+ }
96
+ }
97
+ getTableLabel(table) {
98
+ if (isA(SMART_TABLE_TYPE, table)) {
99
+ const header = table.getHeader();
100
+ if (header) {
101
+ return `'${ header }' table`;
102
+ }
103
+ }
104
+ if (isA(M_TABLE_TYPE, table)) {
105
+ const tilte = table?.getHeaderToolbar()?.getTitleControl()?.getText();
106
+ if (tilte) {
107
+ return `'${ tilte }' table`;
108
+ }
109
+ }
110
+ return 'Unnamed table';
111
+ }
112
+ buildIconTabBarFilterMap() {
113
+ const iconTabBarFilterMap = {};
114
+ const tabBar = getRelevantControlFromActivePage(this.context.controlIndex, this.context.view, [ICON_TAB_BAR_TYPE])[0];
115
+ if (tabBar) {
116
+ const control = getControlById(tabBar.getId());
117
+ if (isA(ICON_TAB_BAR_TYPE, control)) {
118
+ this.iconTabBar = control;
119
+ for (const item of control.getItems()) {
120
+ if (isManagedObject(item) && isA('sap.m.IconTabFilter', item)) {
121
+ iconTabBarFilterMap[item.getKey()] = item.getText();
122
+ }
123
+ }
124
+ }
125
+ }
126
+ return iconTabBarFilterMap;
127
+ }
128
+ collectChildrenInSection(section, table) {
129
+ const layout = getParentContainer(table, 'sap.uxap.ObjectPageLayout');
130
+ const subSections = section.getSubSections();
131
+ const subSection = getParentContainer(table, 'sap.uxap.ObjectPageSubSection');
132
+ if (subSection) {
133
+ if (subSections?.length === 1) {
134
+ this.processTable(table, {
135
+ section,
136
+ subSection: subSections[0],
137
+ layout
138
+ });
139
+ } else if (subSections.length > 1) {
140
+ const sectionChild = this.children.find(val => val.label === `${ section.getTitle() } section`);
141
+ let tableMapIndex = `${ this.children.length - 1 }`;
142
+ if (!sectionChild) {
143
+ tableMapIndex = `${ tableMapIndex }/0`;
144
+ this.children.push({
145
+ label: `'${ section?.getTitle() }' section`,
146
+ children: [{
147
+ label: this.getTableLabel(table),
148
+ children: []
149
+ }]
150
+ });
151
+ } else {
152
+ tableMapIndex = `${ tableMapIndex }/${ sectionChild.children.length - 1 }`;
153
+ sectionChild.children.push({
154
+ label: this.getTableLabel(table),
155
+ children: []
156
+ });
157
+ }
158
+ this.tableMap[tableMapIndex] = {
159
+ table,
160
+ sectionInfo: {
161
+ section,
162
+ subSection,
163
+ layout
164
+ },
165
+ tableUpdateEventAttachedOnce: false
166
+ };
167
+ }
168
+ }
169
+ }
170
+ processTable(table, sectionInfo) {
171
+ if (isA(SMART_TABLE_TYPE, table) || isA('sap.ui.table.TreeTable', table)) {
172
+ this.children.push({
173
+ label: this.getTableLabel(table),
174
+ children: []
175
+ });
176
+ }
177
+ if (isA(M_TABLE_TYPE, table)) {
178
+ this.children.push({
179
+ label: this.getTableLabel(table),
180
+ children: []
181
+ });
182
+ }
183
+ this.tableMap[`${ this.children.length - 1 }`] = {
184
+ table,
185
+ sectionInfo: sectionInfo,
186
+ tableUpdateEventAttachedOnce: false
187
+ };
188
+ }
189
+ selectOverlay(table) {
190
+ const controlOverlay = OverlayUtil.getClosestOverlayFor(table);
191
+ if (controlOverlay) {
192
+ controlOverlay.setSelected(true);
193
+ }
194
+ }
195
+ getActionObject() {
196
+ return {
197
+ kind: NESTED_QUICK_ACTION_KIND,
198
+ id: this.id,
199
+ enabled: this.isActive,
200
+ title: this.context.resourceBundle.getText(this.textKey),
201
+ children: this.children
202
+ };
203
+ }
204
+ }
205
+ var __exports = { __esModule: true };
206
+ __exports.TableQuickActionDefinitionBase = TableQuickActionDefinitionBase;
207
+ return __exports;
208
+ });
@@ -0,0 +1,276 @@
1
+ import UI5Element from 'sap/ui/core/Element';
2
+ import { NESTED_QUICK_ACTION_KIND, NestedQuickAction } from '@sap-ux-private/control-property-editor-common';
3
+ import type IconTabBar from 'sap/m/IconTabBar';
4
+ import type IconTabFilter from 'sap/m/IconTabFilter';
5
+ import type Table from 'sap/m/Table';
6
+ import type SmartTable from 'sap/ui/comp/smarttable/SmartTable';
7
+ import { QuickActionContext } from '../../../cpe/quick-actions/quick-action-definition';
8
+ import OverlayUtil from 'sap/ui/dt/OverlayUtil';
9
+ import type { NestedQuickActionChild } from '@sap-ux-private/control-property-editor-common';
10
+ import { getParentContainer, getRelevantControlFromActivePage } from '../../../cpe/quick-actions/utils';
11
+ import { getControlById, isA, isManagedObject } from '../../../utils/core';
12
+ import { getUi5Version, isLowerThanMinimalUi5Version } from '../../../utils/version';
13
+ import ObjectPageSection from 'sap/uxap/ObjectPageSection';
14
+ import ObjectPageSubSection from 'sap/uxap/ObjectPageSubSection';
15
+ import TreeTable from 'sap/ui/table/TreeTable';
16
+ import ObjectPageLayout from 'sap/uxap/ObjectPageLayout';
17
+
18
+ const SMART_TABLE_ACTION_ID = 'CTX_COMP_VARIANT_CONTENT';
19
+ const M_TABLE_ACTION_ID = 'CTX_ADD_ELEMENTS_AS_CHILD';
20
+ const SETTINGS_ID = 'CTX_SETTINGS';
21
+ const ICON_TAB_BAR_TYPE = 'sap.m.IconTabBar';
22
+ const SMART_TABLE_TYPE = 'sap.ui.comp.smarttable.SmartTable';
23
+ const M_TABLE_TYPE = 'sap.m.Table';
24
+ async function getActionId(table: UI5Element): Promise<string[]> {
25
+ const { major, minor } = await getUi5Version();
26
+
27
+ if (isA(SMART_TABLE_TYPE, table)) {
28
+ if (major === 1 && minor === 96) {
29
+ return [SETTINGS_ID];
30
+ } else {
31
+ return [SMART_TABLE_ACTION_ID];
32
+ }
33
+ }
34
+
35
+ return [M_TABLE_ACTION_ID, SETTINGS_ID];
36
+ }
37
+
38
+ /**
39
+ * Base class for table quick actions.
40
+ */
41
+ export abstract class TableQuickActionDefinitionBase {
42
+ readonly kind = NESTED_QUICK_ACTION_KIND;
43
+ public get id(): string {
44
+ return `${this.context.key}-${this.type}`;
45
+ }
46
+
47
+ public isActive = false;
48
+
49
+ public children: NestedQuickActionChild[] = [];
50
+ public tableMap: Record<
51
+ string,
52
+ {
53
+ table: UI5Element;
54
+ tableUpdateEventAttachedOnce: boolean;
55
+ iconTabBarFilterKey?: string;
56
+ changeColumnActionId?: string;
57
+ sectionInfo?: {
58
+ section: ObjectPageSection;
59
+ subSection: ObjectPageSubSection;
60
+ layout?: ObjectPageLayout;
61
+ };
62
+ }
63
+ > = {};
64
+ public iconTabBar: IconTabBar | undefined;
65
+
66
+ protected get textKey(): string {
67
+ return this.defaultTextKey;
68
+ }
69
+
70
+ protected control: UI5Element | undefined;
71
+
72
+ constructor(
73
+ public readonly type: string,
74
+ protected readonly controlTypes: string[],
75
+ protected readonly defaultTextKey: string,
76
+ protected readonly context: QuickActionContext,
77
+ protected includeServiceAction?: boolean
78
+ ) {}
79
+
80
+ /**
81
+ * Initializes action object instance
82
+ */
83
+ async initialize(): Promise<void> {
84
+ // No action found in control design time for version < 1.96
85
+ const version = await getUi5Version();
86
+ if (isLowerThanMinimalUi5Version(version, { major: 1, minor: 96 })) {
87
+ this.isActive = false;
88
+ return;
89
+ }
90
+ const iconTabBarfilterMap = this.buildIconTabBarFilterMap();
91
+ for (const table of getRelevantControlFromActivePage(
92
+ this.context.controlIndex,
93
+ this.context.view,
94
+ this.controlTypes
95
+ )) {
96
+ const tabKey = Object.keys(iconTabBarfilterMap).find((key) => table.getId().endsWith(key));
97
+ const section = getParentContainer<ObjectPageSection>(table, 'sap.uxap.ObjectPageSection');
98
+ if (section) {
99
+ this.collectChildrenInSection(section, table);
100
+ } else if (this.iconTabBar && tabKey) {
101
+ this.children.push({
102
+ label: `'${iconTabBarfilterMap[tabKey]}' table`,
103
+ children: []
104
+ });
105
+ this.tableMap[`${this.children.length - 1}`] = {
106
+ table,
107
+ iconTabBarFilterKey: tabKey,
108
+ tableUpdateEventAttachedOnce: false
109
+ };
110
+ } else {
111
+ this.processTable(table);
112
+ }
113
+
114
+ // add action id to the table map, if the service actions are needed.
115
+ if (this.includeServiceAction) {
116
+ const actions = await this.context.actionService.get(table.getId());
117
+ const actionsIds = await getActionId(table);
118
+
119
+ const changeColumnAction = actionsIds.find(
120
+ (actionId) => actions.findIndex((action) => action.id === actionId) > -1
121
+ );
122
+ Object.keys(this.tableMap).forEach((key) => {
123
+ // Update the changeColumnActionId for each entry
124
+ this.tableMap[key].changeColumnActionId = changeColumnAction;
125
+ });
126
+ }
127
+ }
128
+ if (this.children.length > 0) {
129
+ this.isActive = true;
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Determines table label for the given table element
135
+ * @param table - table element
136
+ * @returns table label if found or 'Unnamed table'
137
+ */
138
+ private getTableLabel(table: UI5Element): string {
139
+ if (isA<SmartTable>(SMART_TABLE_TYPE, table)) {
140
+ const header = table.getHeader();
141
+ if (header) {
142
+ return `'${header}' table`;
143
+ }
144
+ }
145
+ if (isA<Table>(M_TABLE_TYPE, table)) {
146
+ const tilte = table?.getHeaderToolbar()?.getTitleControl()?.getText();
147
+ if (tilte) {
148
+ return `'${tilte}' table`;
149
+ }
150
+ }
151
+
152
+ return 'Unnamed table';
153
+ }
154
+
155
+ /**
156
+ * Builds a map kay/tab_name for ICON_TAB_BAR control of the active page, if such exists
157
+ * @returns built map
158
+ */
159
+ private buildIconTabBarFilterMap(): { [key: string]: string } {
160
+ const iconTabBarFilterMap: { [key: string]: string } = {};
161
+
162
+ // Assumption only a tab bar control per page.
163
+ const tabBar = getRelevantControlFromActivePage(this.context.controlIndex, this.context.view, [
164
+ ICON_TAB_BAR_TYPE
165
+ ])[0];
166
+ if (tabBar) {
167
+ const control = getControlById(tabBar.getId());
168
+ if (isA<IconTabBar>(ICON_TAB_BAR_TYPE, control)) {
169
+ this.iconTabBar = control;
170
+ for (const item of control.getItems()) {
171
+ if (isManagedObject(item) && isA<IconTabFilter>('sap.m.IconTabFilter', item)) {
172
+ iconTabBarFilterMap[item.getKey()] = item.getText();
173
+ }
174
+ }
175
+ }
176
+ }
177
+
178
+ return iconTabBarFilterMap;
179
+ }
180
+
181
+ /**
182
+ * Collects subsection data in the table map for the given section and table
183
+ * @param section - object page section
184
+ * @param table - table element
185
+ */
186
+ private collectChildrenInSection(section: ObjectPageSection, table: UI5Element): void {
187
+ const layout = getParentContainer<ObjectPageLayout>(table, 'sap.uxap.ObjectPageLayout');
188
+ const subSections = section.getSubSections();
189
+ const subSection = getParentContainer<ObjectPageSubSection>(table, 'sap.uxap.ObjectPageSubSection');
190
+ if (subSection) {
191
+ if (subSections?.length === 1) {
192
+ this.processTable(table, { section, subSection: subSections[0], layout });
193
+ } else if (subSections.length > 1) {
194
+ const sectionChild = this.children.find((val) => val.label === `${section.getTitle()} section`);
195
+ let tableMapIndex = `${this.children.length - 1}`;
196
+ if (!sectionChild) {
197
+ tableMapIndex = `${tableMapIndex}/0`;
198
+ this.children.push({
199
+ label: `'${section?.getTitle()}' section`,
200
+ children: [
201
+ {
202
+ label: this.getTableLabel(table),
203
+ children: []
204
+ }
205
+ ]
206
+ });
207
+ } else {
208
+ tableMapIndex = `${tableMapIndex}/${sectionChild.children.length - 1}`;
209
+ sectionChild.children.push({
210
+ label: this.getTableLabel(table),
211
+ children: []
212
+ });
213
+ }
214
+
215
+ this.tableMap[tableMapIndex] = {
216
+ table,
217
+ sectionInfo: { section, subSection, layout },
218
+ tableUpdateEventAttachedOnce: false
219
+ };
220
+ }
221
+ }
222
+ }
223
+
224
+ /**
225
+ * Processes table element and pushes table data to the children array
226
+ * @param table - table element
227
+ * @param sectionInfo - section info object
228
+ */
229
+ private processTable(
230
+ table: UI5Element,
231
+ sectionInfo?: { section: ObjectPageSection; subSection: ObjectPageSubSection; layout?: ObjectPageLayout }
232
+ ): void {
233
+ if (isA<SmartTable>(SMART_TABLE_TYPE, table) || isA<TreeTable>('sap.ui.table.TreeTable', table)) {
234
+ this.children.push({
235
+ label: this.getTableLabel(table),
236
+ children: []
237
+ });
238
+ }
239
+ if (isA<Table>(M_TABLE_TYPE, table)) {
240
+ this.children.push({
241
+ label: this.getTableLabel(table),
242
+ children: []
243
+ });
244
+ }
245
+ this.tableMap[`${this.children.length - 1}`] = {
246
+ table,
247
+ sectionInfo: sectionInfo,
248
+ tableUpdateEventAttachedOnce: false
249
+ };
250
+ }
251
+
252
+ /**
253
+ * Selects closest overlay for the given table element
254
+ * @param table - table element
255
+ */
256
+ protected selectOverlay(table: UI5Element): void {
257
+ const controlOverlay = OverlayUtil.getClosestOverlayFor(table);
258
+ if (controlOverlay) {
259
+ controlOverlay.setSelected(true);
260
+ }
261
+ }
262
+
263
+ /**
264
+ * Prepares nested quick action object
265
+ * @returns action instance
266
+ */
267
+ getActionObject(): NestedQuickAction {
268
+ return {
269
+ kind: NESTED_QUICK_ACTION_KIND,
270
+ id: this.id,
271
+ enabled: this.isActive,
272
+ title: this.context.resourceBundle.getText(this.textKey),
273
+ children: this.children
274
+ };
275
+ }
276
+ }
@@ -2,6 +2,8 @@ QUICK_ACTION_ADD_PAGE_CONTROLLER=Add Controller to Page
2
2
  QUICK_ACTION_SHOW_PAGE_CONTROLLER=Show Page Controller
3
3
  QUICK_ACTION_OP_ADD_HEADER_FIELD=Add Header Field
4
4
  QUICK_ACTION_OP_ADD_CUSTOM_SECTION=Add Custom Section
5
+ QUICK_ACTION_ADD_CUSTOM_PAGE_ACTION=Add Custom Page Action
6
+ QUICK_ACTION_ADD_CUSTOM_TABLE_ACTION=Add Custom Table Action
5
7
 
6
8
  V2_QUICK_ACTION_CHANGE_TABLE_COLUMNS=Change Table Columns
7
9