@sap-ux/preview-middleware 0.19.6 → 0.19.8

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.
@@ -114,19 +114,18 @@ sap.ui.define(["sap/ui/core/Component", "./core", "sap/ui/rta/command/CommandFac
114
114
  * @returns array with page descriptors
115
115
  */
116
116
  function getV4ApplicationPages(manifest) {
117
- if (manifest['sap.ui5']?.routing?.targets) {
118
- const targets = manifest['sap.ui5'].routing?.targets ?? {};
119
- const result = Object.keys(targets).map(key => {
120
- const entitySet = targets[key].options?.settings?.entitySet;
121
- const id = targets[key].id;
122
- return {
123
- id,
124
- entitySet
125
- };
126
- });
127
- return result;
117
+ const result = [];
118
+ const targets = manifest['sap.ui5'].routing?.targets ?? {};
119
+ for (const target of Object.values(targets)) {
120
+ if (target.name === 'sap.fe.templates.ObjectPage') {
121
+ result.push({
122
+ id: target.id,
123
+ entitySet: target.options?.settings?.entitySet,
124
+ contextPath: target.options?.settings?.contextPath
125
+ });
126
+ }
128
127
  }
129
- return [];
128
+ return result;
130
129
  }
131
130
  var __exports = {
132
131
  __esModule: true
@@ -138,15 +138,17 @@ export async function createManifestPropertyChange(
138
138
  * @param manifest - manifest object
139
139
  * @returns array with page descriptors
140
140
  */
141
- export function getV4ApplicationPages(manifest: Manifest): { id: string; entitySet: string | undefined }[] {
142
- if (manifest['sap.ui5']?.routing?.targets) {
143
- const targets = manifest['sap.ui5'].routing?.targets ?? {};
144
- const result = Object.keys(targets).map((key) => {
145
- const entitySet = targets[key].options?.settings?.entitySet;
146
- const id = targets[key].id;
147
- return { id, entitySet };
148
- });
149
- return result;
141
+ export function getV4ApplicationPages(manifest: Manifest): { id: string; entitySet?: string; contextPath?: string }[] {
142
+ const result: { id: string; entitySet?: string; contextPath?: string }[] = [];
143
+ const targets = manifest['sap.ui5'].routing?.targets ?? {};
144
+ for (const target of Object.values(targets)) {
145
+ if (target.name === 'sap.fe.templates.ObjectPage') {
146
+ result.push({
147
+ id: target.id,
148
+ entitySet: target.options?.settings?.entitySet,
149
+ contextPath: target.options?.settings?.contextPath
150
+ });
151
+ }
150
152
  }
151
- return [];
153
+ return result;
152
154
  }
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.19.6",
12
+ "version": "0.19.8",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -25,11 +25,11 @@
25
25
  "ejs": "3.1.10",
26
26
  "mem-fs": "2.1.0",
27
27
  "mem-fs-editor": "9.4.0",
28
- "@sap-ux/adp-tooling": "0.13.21",
28
+ "@sap-ux/adp-tooling": "0.13.22",
29
29
  "@sap-ux/btp-utils": "1.0.2",
30
+ "@sap-ux/control-property-editor-sources": "npm:@sap-ux/control-property-editor@0.6.1",
30
31
  "@sap-ux/feature-toggle": "0.2.3",
31
32
  "@sap-ux/logger": "0.6.0",
32
- "@sap-ux/control-property-editor-sources": "npm:@sap-ux/control-property-editor@0.6.1",
33
33
  "@sap-ux/project-access": "1.29.18",
34
34
  "@sap-ux/system-access": "0.5.34"
35
35
  },
@@ -49,11 +49,11 @@
49
49
  "nock": "13.4.0",
50
50
  "npm-run-all2": "6.2.0",
51
51
  "supertest": "6.3.3",
52
- "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.13.9",
52
+ "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.13.10",
53
53
  "@sap-ux/axios-extension": "1.19.2",
54
+ "@sap-ux/i18n": "0.2.3",
54
55
  "@sap-ux/store": "1.0.0",
55
- "@sap-ux/ui5-info": "0.9.1",
56
- "@sap-ux/i18n": "0.2.3"
56
+ "@sap-ux/ui5-info": "0.9.1"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "express": "4"
@@ -1,140 +0,0 @@
1
- "use strict";
2
-
3
- sap.ui.define(["sap/ui/core/Component", "sap/ui/dt/OverlayRegistry", "../../../cpe/quick-actions/utils", "../../../utils/core", "../../../utils/application", "../../dialog-factory", "../fe-v2/utils", "../../../utils/fe-v2", "../../../utils/fe-v4", "../../../i18n", "../simple-quick-action-base", "../dialog-enablement-validator"], function (Component, OverlayRegistry, _____cpe_quick_actions_utils, _____utils_core, _____utils_application, ____dialog_factory, ___fe_v2_utils, _____utils_fe_v2, _____utils_fe_v4, _____i18n, ___simple_quick_action_base, ___dialog_enablement_validator) {
4
- "use strict";
5
-
6
- const pageHasControlId = _____cpe_quick_actions_utils["pageHasControlId"];
7
- const getControlById = _____utils_core["getControlById"];
8
- const isA = _____utils_core["isA"];
9
- const getApplicationType = _____utils_application["getApplicationType"];
10
- const DialogFactory = ____dialog_factory["DialogFactory"];
11
- const DialogNames = ____dialog_factory["DialogNames"];
12
- const areManifestChangesSupported = ___fe_v2_utils["areManifestChangesSupported"];
13
- const getV2ApplicationPages = _____utils_fe_v2["getV2ApplicationPages"];
14
- const getV4ApplicationPages = _____utils_fe_v4["getV4ApplicationPages"];
15
- const getTextBundle = _____i18n["getTextBundle"];
16
- const SimpleQuickActionDefinitionBase = ___simple_quick_action_base["SimpleQuickActionDefinitionBase"];
17
- const DIALOG_ENABLEMENT_VALIDATOR = ___dialog_enablement_validator["DIALOG_ENABLEMENT_VALIDATOR"];
18
- const ADD_NEW_OBJECT_PAGE_ACTION = 'add-new-subpage';
19
- const CONTROL_TYPES = ['sap.f.DynamicPage', 'sap.uxap.ObjectPageLayout'];
20
-
21
- /**
22
- * Quick Action for adding a custom page action.
23
- */
24
- class AddNewSubpage extends SimpleQuickActionDefinitionBase {
25
- currentPageDescriptor = {
26
- entitySet: '',
27
- pageType: '',
28
- navProperties: []
29
- };
30
- constructor(context) {
31
- super(ADD_NEW_OBJECT_PAGE_ACTION, [], 'QUICK_ACTION_ADD_NEW_SUB_PAGE', context, [{
32
- run: async () => {
33
- const i18n = await getTextBundle();
34
- if (this.currentPageDescriptor.navProperties.length === 0) {
35
- return {
36
- type: 'error',
37
- message: i18n.getText('NO_SUB_PAGES_TO_ADD')
38
- };
39
- }
40
- return undefined;
41
- }
42
- }, DIALOG_ENABLEMENT_VALIDATOR]);
43
- }
44
- getApplicationPages() {
45
- if (this.appType === 'fe-v2') {
46
- return getV2ApplicationPages(this.context.manifest);
47
- } else if (this.appType === 'fe-v4') {
48
- return getV4ApplicationPages(this.context.manifest);
49
- }
50
- return [];
51
- }
52
- prepareNavigationData(entityType, metaModel) {
53
- const existingPages = this.getApplicationPages();
54
- if (this.currentPageDescriptor.pageType === 'sap.suite.ui.generic.template.ObjectPage') {
55
- // Navigation from Object Page
56
- for (const navProp of entityType?.navigationProperty || []) {
57
- const associationEnd = metaModel.getODataAssociationEnd(entityType, navProp.name);
58
- if (associationEnd?.multiplicity !== '*') {
59
- continue;
60
- }
61
- const entityContainer = metaModel.getODataEntityContainer();
62
- if (!entityContainer?.entitySet?.length) {
63
- continue;
64
- }
65
- const targetEntitySet = entityContainer.entitySet.find(item => item.entityType === associationEnd.type);
66
- const pageExists = existingPages.some(page => page.entitySet === targetEntitySet?.name);
67
- if (targetEntitySet && !pageExists) {
68
- this.currentPageDescriptor.navProperties.push({
69
- entitySet: targetEntitySet.name,
70
- navProperty: navProp.name
71
- });
72
- }
73
- }
74
- return;
75
- }
76
-
77
- // navigation from LR or ALP (only OP based on current entitySet is possible)
78
- const pageExists = existingPages.some(page => page.entitySet === this.currentPageDescriptor.entitySet);
79
- if (!pageExists) {
80
- this.currentPageDescriptor.navProperties.push({
81
- entitySet: this.currentPageDescriptor.entitySet,
82
- navProperty: this.currentPageDescriptor.entitySet
83
- });
84
- }
85
- }
86
- async initialize() {
87
- if (!(await areManifestChangesSupported(this.context.manifest))) {
88
- return Promise.resolve();
89
- }
90
- this.appType = getApplicationType(this.context.manifest);
91
- const allControls = CONTROL_TYPES.flatMap(item => this.context.controlIndex[item] ?? []);
92
- const control = allControls.find(c => pageHasControlId(this.context.view, c.controlId));
93
- const pageType = this.context.view.getViewName().split('.view.')[0];
94
- this.currentPageDescriptor.pageType = pageType;
95
- const metaModel = this.context.rta.getRootControlInstance().getModel()?.getMetaModel();
96
- if (!metaModel || !control) {
97
- return Promise.resolve();
98
- }
99
- const modifiedControl = getControlById(control.controlId);
100
- if (!modifiedControl) {
101
- return Promise.resolve();
102
- }
103
- const component = Component.getOwnerComponentFor(modifiedControl);
104
- if (!isA('sap.suite.ui.generic.template.lib.TemplateComponent', component)) {
105
- return Promise.reject(new Error('Unexpected type of page owner component'));
106
- }
107
- const entitySetName = component.getEntitySet();
108
- if (!entitySetName) {
109
- return Promise.resolve();
110
- }
111
- this.currentPageDescriptor.entitySet = entitySetName;
112
- const entitySet = metaModel.getODataEntitySet(entitySetName);
113
- const entityType = metaModel.getODataEntityType(entitySet.entityType);
114
- this.prepareNavigationData(entityType, metaModel);
115
- this.control = modifiedControl;
116
- return Promise.resolve();
117
- }
118
- async execute() {
119
- const overlay = OverlayRegistry.getOverlay(this.control);
120
- const appReference = this.context.flexSettings.projectId;
121
- await DialogFactory.createDialog(overlay, this.context.rta, DialogNames.ADD_SUBPAGE, undefined, {
122
- appType: this.appType,
123
- appReference,
124
- title: 'ADD_SUB_PAGE_DIALOG_TITLE',
125
- pageDescriptor: this.currentPageDescriptor
126
- }, {
127
- actionName: this.type,
128
- telemetryEventIdentifier: this.getTelemetryIdentifier()
129
- });
130
- return [];
131
- }
132
- }
133
- var __exports = {
134
- __esModule: true
135
- };
136
- __exports.ADD_NEW_OBJECT_PAGE_ACTION = ADD_NEW_OBJECT_PAGE_ACTION;
137
- __exports.AddNewSubpage = AddNewSubpage;
138
- return __exports;
139
- });
140
- //# sourceMappingURL=add-new-subpage.js.map
@@ -1,168 +0,0 @@
1
- import Component from 'sap/ui/core/Component';
2
- import FlexCommand from 'sap/ui/rta/command/FlexCommand';
3
- import ObjectPageLayout from 'sap/uxap/ObjectPageLayout';
4
- import ODataModel from 'sap/ui/model/odata/v2/ODataModel';
5
- import OverlayRegistry from 'sap/ui/dt/OverlayRegistry';
6
- import TemplateComponent from 'sap/suite/ui/generic/template/lib/TemplateComponent';
7
-
8
- import { QuickActionContext, SimpleQuickActionDefinition } from '../../../cpe/quick-actions/quick-action-definition';
9
- import { pageHasControlId } from '../../../cpe/quick-actions/utils';
10
- import { getControlById, isA } from '../../../utils/core';
11
- import ODataMetaModel, { EntityContainer, EntitySet, EntityType } from 'sap/ui/model/odata/ODataMetaModel';
12
- import { ApplicationType, getApplicationType } from '../../../utils/application';
13
- import { DialogFactory, DialogNames } from '../../dialog-factory';
14
- import { areManifestChangesSupported } from '../fe-v2/utils';
15
- import { getV2ApplicationPages } from '../../../utils/fe-v2';
16
- import { getV4ApplicationPages } from '../../../utils/fe-v4';
17
- import { EnablementValidatorResult } from '../enablement-validator';
18
- import { getTextBundle } from '../../../i18n';
19
- import { SimpleQuickActionDefinitionBase } from '../simple-quick-action-base';
20
- import { DIALOG_ENABLEMENT_VALIDATOR } from '../dialog-enablement-validator';
21
-
22
- export const ADD_NEW_OBJECT_PAGE_ACTION = 'add-new-subpage';
23
- const CONTROL_TYPES = ['sap.f.DynamicPage', 'sap.uxap.ObjectPageLayout'];
24
-
25
- /**
26
- * Quick Action for adding a custom page action.
27
- */
28
- export class AddNewSubpage extends SimpleQuickActionDefinitionBase implements SimpleQuickActionDefinition {
29
- private readonly currentPageDescriptor: {
30
- pageType: string;
31
- entitySet: string;
32
- navProperties: { navProperty: string; entitySet: string }[]; // only navProperty with 1:n relationship and the entitySet
33
- } = {
34
- entitySet: '',
35
- pageType: '',
36
- navProperties: []
37
- };
38
-
39
- private appType: ApplicationType;
40
-
41
- constructor(context: QuickActionContext) {
42
- super(ADD_NEW_OBJECT_PAGE_ACTION, [], 'QUICK_ACTION_ADD_NEW_SUB_PAGE', context, [
43
- {
44
- run: async (): Promise<EnablementValidatorResult> => {
45
- const i18n = await getTextBundle();
46
- if (this.currentPageDescriptor.navProperties.length === 0) {
47
- return {
48
- type: 'error',
49
- message: i18n.getText('NO_SUB_PAGES_TO_ADD')
50
- };
51
- }
52
- return undefined;
53
- }
54
- },
55
- DIALOG_ENABLEMENT_VALIDATOR
56
- ]);
57
- }
58
-
59
- private getApplicationPages() {
60
- if (this.appType === 'fe-v2') {
61
- return getV2ApplicationPages(this.context.manifest);
62
- } else if (this.appType === 'fe-v4') {
63
- return getV4ApplicationPages(this.context.manifest);
64
- }
65
- return [];
66
- }
67
-
68
- private prepareNavigationData(entityType: EntityType, metaModel: ODataMetaModel): void {
69
- const existingPages = this.getApplicationPages();
70
- if (this.currentPageDescriptor.pageType === 'sap.suite.ui.generic.template.ObjectPage') {
71
- // Navigation from Object Page
72
- for (const navProp of entityType?.navigationProperty || []) {
73
- const associationEnd = metaModel.getODataAssociationEnd(entityType, navProp.name);
74
- if (associationEnd?.multiplicity !== '*') {
75
- continue;
76
- }
77
- const entityContainer = metaModel.getODataEntityContainer() as EntityContainer;
78
- if (!entityContainer?.entitySet?.length) {
79
- continue;
80
- }
81
- const targetEntitySet = entityContainer.entitySet.find(
82
- (item) => item.entityType === associationEnd.type
83
- );
84
- const pageExists = existingPages.some((page) => page.entitySet === targetEntitySet?.name);
85
- if (targetEntitySet && !pageExists) {
86
- this.currentPageDescriptor.navProperties.push({
87
- entitySet: targetEntitySet.name,
88
- navProperty: navProp.name
89
- });
90
- }
91
- }
92
- return;
93
- }
94
-
95
- // navigation from LR or ALP (only OP based on current entitySet is possible)
96
- const pageExists = existingPages.some((page) => page.entitySet === this.currentPageDescriptor.entitySet);
97
- if (!pageExists) {
98
- this.currentPageDescriptor.navProperties.push({
99
- entitySet: this.currentPageDescriptor.entitySet,
100
- navProperty: this.currentPageDescriptor.entitySet
101
- });
102
- }
103
- }
104
-
105
- async initialize(): Promise<void> {
106
- if (!(await areManifestChangesSupported(this.context.manifest))) {
107
- return Promise.resolve();
108
- }
109
-
110
- this.appType = getApplicationType(this.context.manifest);
111
-
112
- const allControls = CONTROL_TYPES.flatMap((item) => this.context.controlIndex[item] ?? []);
113
- const control = allControls.find((c) => pageHasControlId(this.context.view, c.controlId));
114
-
115
- const pageType = this.context.view.getViewName().split('.view.')[0];
116
- this.currentPageDescriptor.pageType = pageType;
117
-
118
- const metaModel = (this.context.rta.getRootControlInstance().getModel() as ODataModel)?.getMetaModel();
119
- if (!metaModel || !control) {
120
- return Promise.resolve();
121
- }
122
-
123
- const modifiedControl = getControlById<ObjectPageLayout>(control.controlId);
124
- if (!modifiedControl) {
125
- return Promise.resolve();
126
- }
127
-
128
- const component = Component.getOwnerComponentFor(modifiedControl);
129
- if (!isA<TemplateComponent>('sap.suite.ui.generic.template.lib.TemplateComponent', component)) {
130
- return Promise.reject(new Error('Unexpected type of page owner component'));
131
- }
132
-
133
- const entitySetName = component.getEntitySet();
134
- if (!entitySetName) {
135
- return Promise.resolve();
136
- }
137
-
138
- this.currentPageDescriptor.entitySet = entitySetName;
139
-
140
- const entitySet = metaModel.getODataEntitySet(entitySetName) as EntitySet;
141
- const entityType = metaModel.getODataEntityType(entitySet.entityType) as EntityType;
142
-
143
- this.prepareNavigationData(entityType, metaModel);
144
-
145
- this.control = modifiedControl;
146
-
147
- return Promise.resolve();
148
- }
149
-
150
- async execute(): Promise<FlexCommand[]> {
151
- const overlay = OverlayRegistry.getOverlay(this.control!);
152
- const appReference = this.context.flexSettings.projectId;
153
- await DialogFactory.createDialog(
154
- overlay,
155
- this.context.rta,
156
- DialogNames.ADD_SUBPAGE,
157
- undefined,
158
- {
159
- appType: this.appType,
160
- appReference,
161
- title: 'ADD_SUB_PAGE_DIALOG_TITLE',
162
- pageDescriptor: this.currentPageDescriptor
163
- },
164
- { actionName: this.type, telemetryEventIdentifier: this.getTelemetryIdentifier() }
165
- );
166
- return [];
167
- }
168
- }