@soleil-se/app-util 2.3.0 → 2.4.0

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.
package/CHANGELOG.md CHANGED
@@ -4,12 +4,16 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [2.4.0] - 2020-05-26
8
+ ### Fixed
9
+ - `getViewUri` returns correct URI when in offline mode and in the Addons view.
10
+
7
11
  ## [2.3.0] - 2020-05-22
8
12
  ### Added
9
13
  - `renderApp` now accepts `req` as a setting to opimize script loading when multiple instances of the app exists. If `req` is present the script will only be loaded once in all browsers except IE11 that needs a unique script src for the currentScript polyfill to work.
10
14
 
11
15
  ### Fixed
12
- - ´noScript` in `renderApp` was not wrapped in a `<noscript>` tag.
16
+ - `noScript` in `renderApp` was not wrapped in a `<noscript>` tag.
13
17
 
14
18
  ## [2.2.0] - 2020-05-20
15
19
  ### Added
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soleil-se/app-util",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "Utility functions for Webapps.",
5
5
  "main": "./src/index.js",
6
6
  "author": "Soleil AB",
package/src/index.js CHANGED
@@ -102,9 +102,13 @@ export function renderApp(data, {
102
102
  * @returns {String} URI for route.
103
103
  */
104
104
  export function getRouteUri(route) {
105
- const currentPageId = PortletContextUtil.getCurrentPage().getIdentifier().replace('_sitePage', '');
106
- const currentPortletId = PortletContextUtil.getCurrentPortlet().getIdentifier();
107
- return `/appresource/${currentPageId}/${currentPortletId}/${route}`.replace(/\/\//g, '/');
105
+ const currentPage = PortletContextUtil.getCurrentPage();
106
+ if (currentPage && currentPortlet) {
107
+ const currentPageId = currentPage.getIdentifier().replace('_sitePage', '');
108
+ const currentPortletId = currentPortlet.getIdentifier();
109
+ return `/appresource/${currentPageId}/${currentPortletId}/${route}`.replace(/\/\//g, '/');
110
+ }
111
+ return '/';
108
112
  }
109
113
 
110
114
  /**
@@ -113,9 +117,18 @@ export function getRouteUri(route) {
113
117
  * @returns {String} URI for view.
114
118
  */
115
119
  export function getViewUri(route) {
116
- const currentPageUri = PropertyUtil.getString(PortletContextUtil.getCurrentPage(), 'URI');
117
- const currentPortletId = PortletContextUtil.getCurrentPortlet().getIdentifier();
118
- return `${currentPageUri}?sv.target=${currentPortletId}&sv.${currentPortletId}.route=${encodeURI(route)}`;
120
+ const currentPage = PortletContextUtil.getCurrentPage();
121
+ if (currentPage && currentPortlet) {
122
+ const currentPageId = currentPage.getIdentifier().replace('_sitePage', '');
123
+ const currentPageUri = PropertyUtil.getString(currentPage, 'URI');
124
+ const currentPortletId = PortletContextUtil.getCurrentPortlet().getIdentifier();
125
+ if (isOffline) {
126
+ return `/edit-offline/${currentPageId}?sv.target=${currentPortletId}&sv.${currentPortletId}.route=${encodeURI(route)}`;
127
+ }
128
+ return `${currentPageUri}?sv.target=${currentPortletId}&sv.${currentPortletId}.route=${encodeURI(route)}`;
129
+ }
130
+ const addonId = appInfo['jcr:uuid'];
131
+ return `/edit-web-app-offline/${addonId}?sv.target=${addonId}&sv.${addonId}.route=${encodeURI(route)}`;
119
132
  }
120
133
 
121
134
  export default {