@gridsuite/commons-ui 0.29.2 → 0.30.1

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,12 +1,15 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports["default"] = void 0;
4
+ exports["default"] = exports.KeyedColumnsRowIndexer = exports.CHANGE_WAYS = void 0;
5
5
 
6
6
  var _MuiVirtualizedTable = _interopRequireDefault(require("./MuiVirtualizedTable"));
7
7
 
8
8
  exports["default"] = _MuiVirtualizedTable["default"];
9
9
 
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
+ var _KeyedColumnsRowIndexer = require("./KeyedColumnsRowIndexer");
11
11
 
12
- module.exports = exports.default;
12
+ exports.KeyedColumnsRowIndexer = _KeyedColumnsRowIndexer.KeyedColumnsRowIndexer;
13
+ exports.CHANGE_WAYS = _KeyedColumnsRowIndexer.CHANGE_WAYS;
14
+
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.useSnackMessage = exports.useIntlRef = exports.useImportExportParams = exports.treeview_finder_fr = exports.treeview_finder_en = exports.top_bar_fr = exports.top_bar_en = exports.table_fr = exports.table_en = exports.setSignInCallbackError = exports.setShowAuthenticationRouterLogin = exports.setLoggedUser = exports.report_viewer_fr = exports.report_viewer_en = exports.logout = exports.login_fr = exports.login_en = exports.initializeAuthenticationProd = exports.initializeAuthenticationDev = exports.getPreLoginPath = exports.getFileIcon = exports.getEquipmentsInfosForSearchBar = exports.equipment_search_fr = exports.equipment_search_en = exports.equipmentStyles = exports.element_search_fr = exports.element_search_en = exports.elementType = exports.dispatchUser = exports.card_error_boundary_fr = exports.card_error_boundary_en = exports.USER_VALIDATION_ERROR = exports.USER = exports.UNAUTHORIZED_USER_INFO = exports.TreeViewFinder = exports.TopBar = exports.TagRenderer = exports.SnackbarProvider = exports.SIGNIN_CALLBACK_ERROR = exports.SHOW_AUTH_INFO_LOGIN = exports.ReportViewerDialog = exports.ReportViewer = exports.RESET_AUTHENTICATION_ROUTER_ERROR = exports.OverflowableText = exports.MuiVirtualizedTable = exports.LOGOUT_ERROR = exports.LIGHT_THEME = exports.LANG_SYSTEM = exports.LANG_FRENCH = exports.LANG_ENGLISH = exports.EquipmentItem = exports.ElementSearchDialog = exports.EQUIPMENT_TYPE = exports.DEFAULT_ROW_HEIGHT = exports.DEFAULT_HEADER_HEIGHT = exports.DEFAULT_CELL_PADDING = exports.DARK_THEME = exports.CardErrorBoundary = exports.AuthenticationRouter = void 0;
4
+ exports.useSnackMessage = exports.useIntlRef = exports.useImportExportParams = exports.treeview_finder_fr = exports.treeview_finder_en = exports.top_bar_fr = exports.top_bar_en = exports.table_fr = exports.table_en = exports.setSignInCallbackError = exports.setLoggedUser = exports.report_viewer_fr = exports.report_viewer_en = exports.logout = exports.login_fr = exports.login_en = exports.initializeAuthenticationProd = exports.initializeAuthenticationDev = exports.getPreLoginPath = exports.getFileIcon = exports.getEquipmentsInfosForSearchBar = exports.equipment_search_fr = exports.equipment_search_en = exports.equipmentStyles = exports.element_search_fr = exports.element_search_en = exports.elementType = exports.dispatchUser = exports.card_error_boundary_fr = exports.card_error_boundary_en = exports.USER_VALIDATION_ERROR = exports.USER = exports.UNAUTHORIZED_USER_INFO = exports.TreeViewFinder = exports.TopBar = exports.TagRenderer = exports.SnackbarProvider = exports.SIGNIN_CALLBACK_ERROR = exports.SHOW_AUTH_INFO_LOGIN = exports.ReportViewerDialog = exports.ReportViewer = exports.RESET_AUTHENTICATION_ROUTER_ERROR = exports.OverflowableText = exports.MuiVirtualizedTable = exports.LOGOUT_ERROR = exports.LIGHT_THEME = exports.LANG_SYSTEM = exports.LANG_FRENCH = exports.LANG_ENGLISH = exports.KeyedColumnsRowIndexer = exports.EquipmentItem = exports.ElementSearchDialog = exports.EQUIPMENT_TYPE = exports.DEFAULT_ROW_HEIGHT = exports.DEFAULT_HEADER_HEIGHT = exports.DEFAULT_CELL_PADDING = exports.DARK_THEME = exports.CardErrorBoundary = exports.CHANGE_WAYS = exports.AuthenticationRouter = void 0;
5
5
 
6
6
  var _TreeViewFinder = _interopRequireDefault(require("./components/TreeViewFinder"));
7
7
 
@@ -19,9 +19,11 @@ var _AuthenticationRouter = _interopRequireDefault(require("./components/Authent
19
19
 
20
20
  exports.AuthenticationRouter = _AuthenticationRouter["default"];
21
21
 
22
- var _MuiVirtualizedTable = _interopRequireDefault(require("./components/MuiVirtualizedTable"));
22
+ var _MuiVirtualizedTable = _interopRequireWildcard(require("./components/MuiVirtualizedTable"));
23
23
 
24
24
  exports.MuiVirtualizedTable = _MuiVirtualizedTable["default"];
25
+ exports.KeyedColumnsRowIndexer = _MuiVirtualizedTable.KeyedColumnsRowIndexer;
26
+ exports.CHANGE_WAYS = _MuiVirtualizedTable.CHANGE_WAYS;
25
27
 
26
28
  var _ReportViewer = _interopRequireDefault(require("./components/ReportViewer"));
27
29
 
@@ -83,7 +85,6 @@ exports.UNAUTHORIZED_USER_INFO = _actions.UNAUTHORIZED_USER_INFO;
83
85
  exports.LOGOUT_ERROR = _actions.LOGOUT_ERROR;
84
86
  exports.USER_VALIDATION_ERROR = _actions.USER_VALIDATION_ERROR;
85
87
  exports.RESET_AUTHENTICATION_ROUTER_ERROR = _actions.RESET_AUTHENTICATION_ROUTER_ERROR;
86
- exports.setShowAuthenticationRouterLogin = _actions.setShowAuthenticationRouterLogin;
87
88
  exports.SHOW_AUTH_INFO_LOGIN = _actions.SHOW_AUTH_INFO_LOGIN;
88
89
 
89
90
  var _reportViewerEn = _interopRequireDefault(require("./components/translations/report-viewer-en"));
@@ -31,11 +31,29 @@ window.OIDCLog = _oidcClient.Log;
31
31
  var hackauthoritykey = 'oidc.hack.authority';
32
32
  var pathKey = 'powsybl-gridsuite-current-path';
33
33
 
34
+ function handleSigninSilent(dispatch, userManager) {
35
+ userManager.getUser().then(function (user) {
36
+ if (user == null || getIdTokenExpiresIn(user) < 0) {
37
+ return userManager.signinSilent()["catch"](function (error) {
38
+ dispatch((0, _actions.setShowAuthenticationRouterLogin)(true));
39
+ var oidcHackReloaded = 'gridsuite-oidc-hack-reloaded';
40
+
41
+ if (!sessionStorage.getItem(oidcHackReloaded) && error.message === 'authority mismatch on settings vs. signin state') {
42
+ sessionStorage.setItem(oidcHackReloaded, true);
43
+ console.log('Hack oidc, reload page to make login work');
44
+ window.location.reload();
45
+ }
46
+ });
47
+ }
48
+ });
49
+ }
50
+
34
51
  function initializeAuthenticationDev(dispatch, isSilentRenew, validateUser) {
35
52
  var userManager = new _UserManagerMock.UserManagerMock({});
36
53
 
37
54
  if (!isSilentRenew) {
38
55
  handleUser(dispatch, userManager, validateUser);
56
+ handleSigninSilent(dispatch, userManager);
39
57
  }
40
58
 
41
59
  return Promise.resolve(userManager);
@@ -118,9 +136,14 @@ function initializeAuthenticationProd(dispatch, isSilentRenew, idpSettings, vali
118
136
 
119
137
  if (!isSilentRenew) {
120
138
  handleUser(dispatch, userManager, validateUser);
139
+ handleSigninSilent(dispatch, userManager);
121
140
  }
122
141
 
123
142
  return userManager;
143
+ })["catch"](function (error) {
144
+ console.debug('error when importing the idp settings', error);
145
+ dispatch((0, _actions.setShowAuthenticationRouterLogin)(true));
146
+ throw error;
124
147
  });
125
148
  }
126
149
 
@@ -136,6 +159,7 @@ function logout(dispatch, userManagerInstance) {
136
159
 
137
160
  return userManagerInstance.getUser().then(function (user) {
138
161
  if (user) {
162
+ // We don't need to check if token is valid at this point
139
163
  return userManagerInstance.signoutRedirect({
140
164
  extraQueryParams: {
141
165
  TargetResource: userManagerInstance.settings.post_logout_redirect_uri
@@ -158,10 +182,24 @@ function logout(dispatch, userManagerInstance) {
158
182
  });
159
183
  }
160
184
 
185
+ function getIdTokenExpiresIn(user) {
186
+ var now = parseInt(Date.now() / 1000);
187
+ var exp = (0, _jwtDecode["default"])(user.id_token).exp;
188
+ return exp - now;
189
+ }
190
+
161
191
  function dispatchUser(dispatch, userManagerInstance, validateUser) {
162
192
  return userManagerInstance.getUser().then(function (user) {
163
193
  if (user) {
164
- // without validateUser defined, valid user by default
194
+ // If session storage contains a expired token at initialization
195
+ // We do not dispatch the user
196
+ // Our explicit SigninSilent will attempt to connect once
197
+ if (getIdTokenExpiresIn(user) < 0) {
198
+ console.debug('User token is expired and will not be dispatched');
199
+ return;
200
+ } // without validateUser defined, valid user by default
201
+
202
+
165
203
  var validateUserPromise = validateUser && validateUser(user) || Promise.resolve(true);
166
204
  return validateUserPromise.then(function (valid) {
167
205
  if (!valid) {
@@ -171,15 +209,6 @@ function dispatchUser(dispatch, userManagerInstance, validateUser) {
171
209
  return dispatch((0, _actions.setUnauthorizedUserInfo)(user === null || user === void 0 ? void 0 : (_user$profile2 = user.profile) === null || _user$profile2 === void 0 ? void 0 : _user$profile2.name, {}));
172
210
  }
173
211
 
174
- var now = parseInt(Date.now() / 1000);
175
- var exp = (0, _jwtDecode["default"])(user.id_token).exp;
176
- var idTokenExpiresIn = exp - now;
177
-
178
- if (idTokenExpiresIn < 0) {
179
- console.debug('User token is expired and will not be dispatched');
180
- return;
181
- }
182
-
183
212
  console.debug('User has been successfully loaded from store.');
184
213
  return dispatch((0, _actions.setLoggedUser)(user));
185
214
  })["catch"](function (e) {
@@ -226,13 +255,14 @@ function handleUser(dispatch, userManager, validateUser) {
226
255
 
227
256
  window.setTimeout(function () {
228
257
  userManager.getUser().then(function (user) {
229
- var now = parseInt(Date.now() / 1000);
230
- var exp = (0, _jwtDecode["default"])(user.id_token).exp;
231
- var idTokenExpiresIn = exp - now;
258
+ if (!user) {
259
+ console.error("user is null at silent renew error, it shouldn't happen.");
260
+ }
261
+
262
+ var idTokenExpiresIn = getIdTokenExpiresIn(user);
232
263
 
233
264
  if (idTokenExpiresIn < 0) {
234
- console.log('Error in silent renew, idtoken expired: ' + idTokenExpiresIn + ' => Logging out.', error); // TODO here allow to continue to use the app but in some kind of frozen state because we can't make API calls anymore
235
- // remove the user from our app, but don't sso logout on all other apps
265
+ console.log('Error in silent renew, idtoken expired: ' + idTokenExpiresIn + ' => Logging out.', error); // remove the user from our app, but don't sso logout on all other apps
236
266
 
237
267
  dispatch((0, _actions.setShowAuthenticationRouterLogin)(true)); // logout during token expiration, show login without errors
238
268
 
@@ -258,7 +288,11 @@ function handleUser(dispatch, userManager, validateUser) {
258
288
  console.log('Error in silent renew, unsupported configuration: token still valid for ' + idTokenExpiresIn + ' but maxExpiresIn is not configured:' + userManager.idpSettings.maxExpiresIn, error);
259
289
  }
260
290
  });
261
- }, accessTokenExpiringNotificationTime * 1000);
291
+ }, accessTokenExpiringNotificationTime * 1000); // Should be min(accessTokenExpiringNotificationTime * 1000, idTokenExpiresIn) to avoid rare case
292
+ // when user connection is dying and you refresh the page between expiring and expired.
293
+ // but gateway has a DEFAULT_MAX_CLOCK_SKEW = 60s then the token is still valid for this time
294
+ // even if expired
295
+ // We accept to not manage this case further
262
296
  });
263
297
  console.debug('dispatch user');
264
298
  dispatchUser(dispatch, userManager, validateUser);
@@ -123,9 +123,9 @@ var EQUIPMENT_TYPE = {
123
123
  };
124
124
  exports.EQUIPMENT_TYPE = EQUIPMENT_TYPE;
125
125
 
126
- var getEquipmentsInfosForSearchBar = function getEquipmentsInfosForSearchBar(equipmentsInfos, equipmentLabelling) {
126
+ var getEquipmentsInfosForSearchBar = function getEquipmentsInfosForSearchBar(equipmentsInfos, getNameOrId) {
127
127
  return equipmentsInfos.flatMap(function (e) {
128
- var label = equipmentLabelling ? e.name : e.id;
128
+ var label = getNameOrId(e);
129
129
  return e.type === 'SUBSTATION' ? [{
130
130
  label: label,
131
131
  id: e.id,
@@ -137,7 +137,7 @@ var getEquipmentsInfosForSearchBar = function getEquipmentsInfosForSearchBar(equ
137
137
  id: e.id,
138
138
  key: e.id + '_' + vli.id,
139
139
  type: e.type,
140
- voltageLevelLabel: equipmentLabelling ? vli.name : vli.id,
140
+ voltageLevelLabel: getNameOrId(vli),
141
141
  voltageLevelId: vli.id
142
142
  };
143
143
  });
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.equalsArray = equalsArray;
5
+
6
+ /**
7
+ * Copyright (c) 2022, RTE (http://www.rte-france.com)
8
+ * This Source Code Form is subject to the terms of the Mozilla Public
9
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
10
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11
+ */
12
+ function equalsArray(a, b) {
13
+ if (b === a) return true;
14
+ if (!b || !a) return false;
15
+ if (a.length !== b.length) return false;
16
+
17
+ for (var i = 0, l = a.length; i < l; i++) {
18
+ if (a[i] instanceof Array && b[i] instanceof Array) {
19
+ if (!equalsArray(a[i], b[i])) return false;
20
+ } else if (a[i] !== b[i]) {
21
+ // Warning - two different object instances will never be equal: {x:20} != {x:20}
22
+ return false;
23
+ }
24
+ }
25
+
26
+ return true;
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gridsuite/commons-ui",
3
- "version": "0.29.2",
3
+ "version": "0.30.1",
4
4
  "description": "common react components for gridsuite applications",
5
5
  "engines": {
6
6
  "npm": "<=6",