@sap-ux/preview-middleware 0.13.28 → 0.13.30

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- sap.ui.define(["sap/ui/core/Fragment", "./controllers/AddFragment.controller", "./controllers/ControllerExtension.controller", "./controllers/ExtensionPoint.controller"], function (Fragment, __AddFragment, __ControllerExtension, __ExtensionPoint) {
3
+ sap.ui.define(["sap/ui/core/Fragment", "sap/ui/fl/Utils", "./controllers/AddFragment.controller", "./controllers/ControllerExtension.controller", "./controllers/ExtensionPoint.controller"], function (Fragment, FlUtils, __AddFragment, __ControllerExtension, __ExtensionPoint) {
4
4
  "use strict";
5
5
 
6
6
  function _interopRequireDefault(obj) {
@@ -19,8 +19,9 @@ sap.ui.define(["sap/ui/core/Fragment", "./controllers/AddFragment.controller", "
19
19
  * Adds a new item to the context menu
20
20
  *
21
21
  * @param rta Runtime Authoring
22
+ * @param syncViewsIds Ids of all application sync views
22
23
  */
23
- const initDialogs = rta => {
24
+ const initDialogs = (rta, syncViewsIds) => {
24
25
  const contextMenu = rta.getDefaultPlugins().contextMenu;
25
26
  contextMenu.addMenuItem({
26
27
  id: 'ADD_FRAGMENT',
@@ -32,10 +33,24 @@ sap.ui.define(["sap/ui/core/Fragment", "./controllers/AddFragment.controller", "
32
33
  id: 'EXTEND_CONTROLLER',
33
34
  text: 'Extend With Controller',
34
35
  handler: async overlays => await handler(overlays[0], rta, DialogNames.CONTROLLER_EXTENSION),
35
- icon: 'sap-icon://create-form'
36
+ icon: 'sap-icon://create-form',
37
+ enabled: overlays => isControllerExtensionEnabled(overlays, syncViewsIds)
36
38
  });
37
39
  };
38
40
 
41
+ /**
42
+ * Handler for enablement of Extend With Controller context menu entry
43
+ *
44
+ * @param overlays Control overlays
45
+ * @param syncViewsIds Runtime Authoring
46
+ *
47
+ * @returns boolean
48
+ */
49
+ const isControllerExtensionEnabled = (overlays, syncViewsIds) => {
50
+ const clickedControlId = FlUtils.getViewForControl(overlays[0].getElement()).getId();
51
+ return overlays.length <= 1 && !syncViewsIds.includes(clickedControlId);
52
+ };
53
+
39
54
  /**
40
55
  * Handler for new context menu entry
41
56
  *
@@ -70,6 +85,7 @@ sap.ui.define(["sap/ui/core/Fragment", "./controllers/AddFragment.controller", "
70
85
  };
71
86
  __exports.DialogNames = DialogNames;
72
87
  __exports.initDialogs = initDialogs;
88
+ __exports.isControllerExtensionEnabled = isControllerExtensionEnabled;
73
89
  __exports.handler = handler;
74
90
  return __exports;
75
91
  });
@@ -3,11 +3,16 @@ import type Dialog from 'sap/m/Dialog';
3
3
 
4
4
  /** sap.ui.core */
5
5
  import Fragment from 'sap/ui/core/Fragment';
6
- import type UI5Element from 'sap/ui/core/Element';
6
+ import UI5Element from 'sap/ui/core/Element';
7
7
 
8
8
  /** sap.ui.rta */
9
9
  import type RuntimeAuthoring from 'sap/ui/rta/RuntimeAuthoring';
10
10
 
11
+ /** sap.ui.fl */
12
+ import FlUtils from 'sap/ui/fl/Utils';
13
+
14
+ import ElementOverlay from 'sap/ui/dt/ElementOverlay';
15
+
11
16
  import AddFragment from './controllers/AddFragment.controller';
12
17
  import ControllerExtension from './controllers/ControllerExtension.controller';
13
18
  import { ExtensionPointData } from './extension-point';
@@ -25,8 +30,9 @@ type Controller = AddFragment | ControllerExtension | ExtensionPoint;
25
30
  * Adds a new item to the context menu
26
31
  *
27
32
  * @param rta Runtime Authoring
33
+ * @param syncViewsIds Ids of all application sync views
28
34
  */
29
- export const initDialogs = (rta: RuntimeAuthoring): void => {
35
+ export const initDialogs = (rta: RuntimeAuthoring, syncViewsIds: string[]): void => {
30
36
  const contextMenu = rta.getDefaultPlugins().contextMenu;
31
37
 
32
38
  contextMenu.addMenuItem({
@@ -40,10 +46,25 @@ export const initDialogs = (rta: RuntimeAuthoring): void => {
40
46
  id: 'EXTEND_CONTROLLER',
41
47
  text: 'Extend With Controller',
42
48
  handler: async (overlays: UI5Element[]) => await handler(overlays[0], rta, DialogNames.CONTROLLER_EXTENSION),
43
- icon: 'sap-icon://create-form'
49
+ icon: 'sap-icon://create-form',
50
+ enabled: (overlays: ElementOverlay[]) => isControllerExtensionEnabled(overlays, syncViewsIds)
44
51
  });
45
52
  };
46
53
 
54
+ /**
55
+ * Handler for enablement of Extend With Controller context menu entry
56
+ *
57
+ * @param overlays Control overlays
58
+ * @param syncViewsIds Runtime Authoring
59
+ *
60
+ * @returns boolean
61
+ */
62
+ export const isControllerExtensionEnabled = (overlays: ElementOverlay[], syncViewsIds: string[]): boolean => {
63
+ const clickedControlId = FlUtils.getViewForControl(overlays[0].getElement()).getId();
64
+
65
+ return overlays.length <= 1 && !syncViewsIds.includes(clickedControlId);
66
+ };
67
+
47
68
  /**
48
69
  * Handler for new context menu entry
49
70
  *
@@ -1,12 +1,13 @@
1
1
  'use strict';
2
2
  sap.ui.define([
3
3
  'sap/base/Log',
4
+ 'sap/ui/core/ElementRegistry',
4
5
  '../cpe/init',
5
6
  './init-dialogs',
6
7
  'open/ux/preview/client/thirdparty/@sap-ux-private/control-property-editor-common',
7
8
  'sap/ui/VersionInfo',
8
9
  './ui5-version-utils'
9
- ], function (log, __init, ___init_dialogs, ___sap_ux_private_control_property_editor_common, VersionInfo, ___ui5_version_utils) {
10
+ ], function (log, UI5ElementRegistry, __init, ___init_dialogs, ___sap_ux_private_control_property_editor_common, VersionInfo, ___ui5_version_utils) {
10
11
  'use strict';
11
12
  function _interopRequireDefault(obj) {
12
13
  return obj && obj.__esModule && typeof obj.default !== 'undefined' ? obj.default : obj;
@@ -51,7 +52,8 @@ sap.ui.define([
51
52
  }
52
53
  }
53
54
  });
54
- initDialogs(rta);
55
+ const syncViewsIds = getAllSyncViewsIds();
56
+ initDialogs(rta, syncViewsIds);
55
57
  if (minor > 77) {
56
58
  const ExtensionPointService = (await __ui5_require_async('open/ux/preview/client/adp/extension-point')).default;
57
59
  const extPointService = new ExtensionPointService(rta);
@@ -60,9 +62,30 @@ sap.ui.define([
60
62
  await init(rta);
61
63
  const ui5VersionValidationMsg = getUI5VersionValidationMessage(version);
62
64
  if (ui5VersionValidationMsg) {
63
- sendAction(showMessage(ui5VersionValidationMsg));
65
+ sendAction(showMessage({
66
+ message: ui5VersionValidationMsg,
67
+ shouldHideIframe: true
68
+ }));
69
+ return;
70
+ }
71
+ if (syncViewsIds.length > 0) {
72
+ sendAction(showMessage({
73
+ message: 'Have in mind that synchronous views are detected for this application and controller extensions are not supported for such views. Controller extension functionality on these views will be disabled.',
74
+ shouldHideIframe: false
75
+ }));
64
76
  }
65
77
  log.debug('ADP init executed.');
66
78
  };
79
+ function getAllSyncViewsIds() {
80
+ const elements = UI5ElementRegistry.all();
81
+ const syncViewIds = [];
82
+ Object.entries(elements).forEach(_ref => {
83
+ let [key, ui5Element] = _ref;
84
+ if (ui5Element?.getMetadata()?.getName()?.includes('XMLView') && ui5Element?.oAsyncState === undefined) {
85
+ syncViewIds.push(key);
86
+ }
87
+ });
88
+ return syncViewIds;
89
+ }
67
90
  return __exports;
68
91
  });
@@ -1,5 +1,6 @@
1
1
  import log from 'sap/base/Log';
2
2
  import type RuntimeAuthoring from 'sap/ui/rta/RuntimeAuthoring';
3
+ import UI5ElementRegistry from 'sap/ui/core/ElementRegistry';
3
4
 
4
5
  import init from '../cpe/init';
5
6
  import { initDialogs } from './init-dialogs';
@@ -13,6 +14,7 @@ import {
13
14
  import { ActionHandler } from '../cpe/types';
14
15
  import VersionInfo from 'sap/ui/VersionInfo';
15
16
  import { getUI5VersionValidationMessage } from './ui5-version-utils';
17
+ import UI5Element from 'sap/ui/dt/Element';
16
18
 
17
19
  export default async function (rta: RuntimeAuthoring) {
18
20
  const { version } = (await VersionInfo.load()) as { version: string };
@@ -44,23 +46,50 @@ export default async function (rta: RuntimeAuthoring) {
44
46
  }
45
47
  );
46
48
 
47
- // initialize fragment content menu entry
48
- initDialogs(rta);
49
+ const syncViewsIds = getAllSyncViewsIds();
50
+ initDialogs(rta, syncViewsIds);
49
51
 
50
- // initialize extension point service
51
52
  if (minor > 77) {
52
53
  const ExtensionPointService = (await import('open/ux/preview/client/adp/extension-point')).default;
53
54
  const extPointService = new ExtensionPointService(rta);
54
55
  extPointService.init(subscribe);
55
56
  }
56
57
 
57
- // also initialize the editor
58
58
  await init(rta);
59
-
60
59
  const ui5VersionValidationMsg = getUI5VersionValidationMessage(version);
61
60
 
62
61
  if (ui5VersionValidationMsg) {
63
- sendAction(showMessage(ui5VersionValidationMsg));
62
+ sendAction(showMessage({ message: ui5VersionValidationMsg, shouldHideIframe: true }));
63
+
64
+ return;
64
65
  }
66
+ if (syncViewsIds.length > 0) {
67
+ sendAction(
68
+ showMessage({
69
+ message:
70
+ 'Have in mind that synchronous views are detected for this application and controller extensions are not supported for such views. Controller extension functionality on these views will be disabled.',
71
+ shouldHideIframe: false
72
+ })
73
+ );
74
+ }
75
+
65
76
  log.debug('ADP init executed.');
66
77
  }
78
+
79
+ /**
80
+ *
81
+ * Get Ids for all sync views
82
+ *
83
+ * @returns array of Ids for application sync views
84
+ */
85
+ function getAllSyncViewsIds(): string[] {
86
+ const elements = UI5ElementRegistry.all() as Record<string, UI5Element>;
87
+ const syncViewIds: string[] = [];
88
+ Object.entries(elements).forEach(([key, ui5Element]) => {
89
+ if (ui5Element?.getMetadata()?.getName()?.includes('XMLView') && ui5Element?.oAsyncState === undefined) {
90
+ syncViewIds.push(key);
91
+ }
92
+ });
93
+
94
+ return syncViewIds;
95
+ }
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.13.28",
12
+ "version": "0.13.30",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -27,8 +27,8 @@
27
27
  "mem-fs-editor": "9.4.0",
28
28
  "@sap-ux/logger": "0.5.1",
29
29
  "@sap-ux/btp-utils": "0.14.4",
30
- "@sap-ux/adp-tooling": "0.9.27",
31
- "@sap-ux/control-property-editor-sources": "npm:@sap-ux/control-property-editor@0.4.19",
30
+ "@sap-ux/adp-tooling": "0.9.28",
31
+ "@sap-ux/control-property-editor-sources": "npm:@sap-ux/control-property-editor@0.4.20",
32
32
  "@sap-ux/project-access": "1.19.14"
33
33
  },
34
34
  "devDependencies": {
@@ -45,8 +45,8 @@
45
45
  "supertest": "6.3.3",
46
46
  "@sap-ux-private/playwright": "0.0.3",
47
47
  "dotenv": "16.3.1",
48
- "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.9.8",
49
- "@sap-ux/axios-extension": "1.12.0",
48
+ "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.9.9",
49
+ "@sap-ux/axios-extension": "1.12.1",
50
50
  "@sap-ux/store": "0.5.0",
51
51
  "@sap-ux/i18n": "0.0.6"
52
52
  },