@gridsuite/commons-ui 0.20.5 → 0.22.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.
@@ -211,13 +211,14 @@ var MuiVirtualizedTable = /*#__PURE__*/function (_React$PureComponent) {
211
211
  });
212
212
 
213
213
  _defineProperty(_assertThisInitialized(_this), "getRowClassName", function (_ref2) {
214
- var _clsx;
214
+ var _rowGetter, _clsx;
215
215
 
216
- var index = _ref2.index;
216
+ var index = _ref2.index,
217
+ rowGetter = _ref2.rowGetter;
217
218
  var _this$props2 = _this.props,
218
219
  classes = _this$props2.classes,
219
220
  onRowClick = _this$props2.onRowClick;
220
- return (0, _clsx3["default"])(classes.tableRow, classes.flexContainer, index % 2 === 0 && classes.rowBackgroundDark, index % 2 !== 0 && classes.rowBackgroundLight, (_clsx = {}, _clsx[classes.tableRowHover] = index !== -1 && onRowClick != null, _clsx));
221
+ return (0, _clsx3["default"])(classes.tableRow, classes.flexContainer, index % 2 === 0 && classes.rowBackgroundDark, index % 2 !== 0 && classes.rowBackgroundLight, ((_rowGetter = rowGetter(index)) === null || _rowGetter === void 0 ? void 0 : _rowGetter.notClickable) === true && classes.noClick, (_clsx = {}, _clsx[classes.tableRowHover] = index !== -1 && onRowClick != null, _clsx));
221
222
  });
222
223
 
223
224
  _defineProperty(_assertThisInitialized(_this), "cellRenderer", function (_ref3) {
@@ -429,11 +430,11 @@ var MuiVirtualizedTable = /*#__PURE__*/function (_React$PureComponent) {
429
430
  return index < reorderedIndex.length ? reorderedIndex[index] : 0;
430
431
  };
431
432
 
432
- var _rowGetter = function rowGetter(index) {
433
+ var _rowGetter2 = function rowGetter(index) {
433
434
  return _this2.props.rows[getIndexFor(index)];
434
435
  };
435
436
 
436
- var sizes = this.sizes(this.props.columns, this.props.rows, _rowGetter);
437
+ var sizes = this.sizes(this.props.columns, this.props.rows, _rowGetter2);
437
438
  var csvHeaders = this.csvHeaders(this.props.columns, this.props.exportCSVDataKeys);
438
439
  return /*#__PURE__*/_react["default"].createElement("div", {
439
440
  style: {
@@ -474,14 +475,20 @@ var MuiVirtualizedTable = /*#__PURE__*/function (_React$PureComponent) {
474
475
  className: classes.table
475
476
  }, tableProps, {
476
477
  rowCount: reorderedIndex.length,
477
- rowClassName: _this2.getRowClassName,
478
- rowGetter: function rowGetter(_ref6) {
478
+ rowClassName: function rowClassName(_ref6) {
479
479
  var index = _ref6.index;
480
- return _rowGetter(index);
480
+ return _this2.getRowClassName({
481
+ index: index,
482
+ rowGetter: _rowGetter2
483
+ });
484
+ },
485
+ rowGetter: function rowGetter(_ref7) {
486
+ var index = _ref7.index;
487
+ return _rowGetter2(index);
481
488
  }
482
- }), columns.map(function (_ref7, index) {
483
- var dataKey = _ref7.dataKey,
484
- other = _objectWithoutPropertiesLoose(_ref7, _excluded2);
489
+ }), columns.map(function (_ref8, index) {
490
+ var dataKey = _ref8.dataKey,
491
+ other = _objectWithoutPropertiesLoose(_ref8, _excluded2);
485
492
 
486
493
  return /*#__PURE__*/_react["default"].createElement(_reactVirtualized.Column, _extends({
487
494
  key: dataKey,
@@ -62,7 +62,7 @@ var OverflowableText = function OverflowableText(_ref) {
62
62
  }, [setOverflowed, element]);
63
63
  (0, _react.useEffect)(function () {
64
64
  checkOverflow();
65
- }, [checkOverflow]);
65
+ }, [checkOverflow, text]);
66
66
  return /*#__PURE__*/_react["default"].createElement(_material.Tooltip, {
67
67
  title: text || '',
68
68
  disableHoverListener: !overflowed,
@@ -87,7 +87,8 @@ var useStyles = (0, _makeStyles["default"])(function (theme) {
87
87
  return {
88
88
  grow: {
89
89
  flexGrow: 1,
90
- display: 'flex'
90
+ display: 'flex',
91
+ overflow: 'hidden'
91
92
  },
92
93
  logo: {
93
94
  flexShrink: 0,
@@ -227,6 +228,7 @@ var TopBar = function TopBar(_ref) {
227
228
  onEquipmentLabellingClick = _ref.onEquipmentLabellingClick,
228
229
  equipmentLabelling = _ref.equipmentLabelling,
229
230
  withElementsSearch = _ref.withElementsSearch,
231
+ searchDisabled = _ref.searchDisabled,
230
232
  searchingLabel = _ref.searchingLabel,
231
233
  onSearchTermChange = _ref.onSearchTermChange,
232
234
  _onSelectionChange = _ref.onSelectionChange,
@@ -331,15 +333,20 @@ var TopBar = function TopBar(_ref) {
331
333
  };
332
334
 
333
335
  (0, _react.useEffect)(function () {
334
- if (user && withElementsSearch) {
335
- document.addEventListener('keydown', function (e) {
336
+ if (user && withElementsSearch && !searchDisabled) {
337
+ var openSearch = function openSearch(e) {
336
338
  if (e.ctrlKey && e.key === 'f') {
337
339
  e.preventDefault();
338
340
  setDialogSearchOpen(true);
339
341
  }
340
- });
342
+ };
343
+
344
+ document.addEventListener('keydown', openSearch);
345
+ return function () {
346
+ return document.removeEventListener('keydown', openSearch);
347
+ };
341
348
  }
342
- }, [user, withElementsSearch]);
349
+ }, [user, withElementsSearch, searchDisabled]);
343
350
  return /*#__PURE__*/_react["default"].createElement(_AppBar["default"], {
344
351
  position: "static",
345
352
  color: "default",
@@ -383,7 +390,8 @@ var TopBar = function TopBar(_ref) {
383
390
  renderElement: renderElement
384
391
  }), /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
385
392
  color: "inherit",
386
- onClick: handleClickElementSearch
393
+ onClick: handleClickElementSearch,
394
+ disabled: searchDisabled
387
395
  }, /*#__PURE__*/_react["default"].createElement(_Search["default"], null)))), user && /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
388
396
  "aria-controls": "apps-menu",
389
397
  "aria-haspopup": "true",
@@ -616,6 +624,7 @@ TopBar.propTypes = process.env.NODE_ENV !== "production" ? {
616
624
  onEquipmentLabellingClick: _propTypes["default"].func,
617
625
  equipmentLabelling: _propTypes["default"].bool,
618
626
  withElementsSearch: _propTypes["default"].bool,
627
+ searchDisabled: _propTypes["default"].bool,
619
628
  searchingLabel: _propTypes["default"].string,
620
629
  onSearchTermChange: _propTypes["default"].func,
621
630
  onSelectionChange: _propTypes["default"].func,
@@ -41,6 +41,8 @@ function initializeAuthenticationDev(dispatch, isSilentRenew) {
41
41
  return Promise.resolve(userManager);
42
42
  }
43
43
 
44
+ var accessTokenExpiringNotificationTime = 60; // seconds
45
+
44
46
  function initializeAuthenticationProd(dispatch, isSilentRenew, idpSettings) {
45
47
  return idpSettings.then(function (r) {
46
48
  return r.json();
@@ -74,10 +76,23 @@ function initializeAuthenticationProd(dispatch, isSilentRenew, idpSettings) {
74
76
  var expires_in = parseInt(matched_expires[0].split('=')[1]);
75
77
  var now = parseInt(Date.now() / 1000);
76
78
  var exp = decoded.exp;
79
+ var idTokenExpiresIn = exp - now;
80
+ var minAccesstokenOrIdtokenOrIdpSettingsExpiresIn = expires_in;
81
+ var newExpireReplaceReason;
82
+
83
+ if (idTokenExpiresIn < minAccesstokenOrIdtokenOrIdpSettingsExpiresIn) {
84
+ minAccesstokenOrIdtokenOrIdpSettingsExpiresIn = idTokenExpiresIn;
85
+ newExpireReplaceReason = 'idtoken.exp is earlier';
86
+ }
87
+
88
+ if (idpSettings.maxExpiresIn && idpSettings.maxExpiresIn < minAccesstokenOrIdtokenOrIdpSettingsExpiresIn) {
89
+ minAccesstokenOrIdtokenOrIdpSettingsExpiresIn = idpSettings.maxExpiresIn;
90
+ newExpireReplaceReason = 'idpSettings.maxExpiresIn is smaller';
91
+ }
77
92
 
78
- if (exp < now + expires_in) {
79
- var newhash = window.location.hash.replace(matched_expires[0], 'expires_in=' + (exp - now));
80
- console.debug('Replacing expires_in in window.location.hash because idtoken.exp is earlier. Before: ', window.location.hash, 'after: ', newhash);
93
+ if (newExpireReplaceReason) {
94
+ var newhash = window.location.hash.replace(matched_expires[0], 'expires_in=' + minAccesstokenOrIdtokenOrIdpSettingsExpiresIn);
95
+ console.debug('Replacing expires_in in window.location.hash to ' + minAccesstokenOrIdtokenOrIdpSettingsExpiresIn + ' because ' + newExpireReplaceReason + '. ', 'debug:', 'original expires_in: ' + expires_in + ', ', 'idTokenExpiresIn: ' + idTokenExpiresIn + '(idtoken exp: ' + exp + '), ', 'idpSettings maxExpiresIn: ' + idpSettings.maxExpiresIn);
81
96
  window.location.hash = newhash;
82
97
  }
83
98
  }
@@ -96,9 +111,10 @@ function initializeAuthenticationProd(dispatch, isSilentRenew, idpSettings) {
96
111
  response_type: 'id_token token',
97
112
  scope: idpSettings.scope,
98
113
  automaticSilentRenew: !isSilentRenew,
99
- accessTokenExpiringNotificationTime: 60
114
+ accessTokenExpiringNotificationTime: accessTokenExpiringNotificationTime
100
115
  };
101
116
  var userManager = new _oidcClient.UserManager(settings);
117
+ userManager.idpSettings = idpSettings; //store our settings in there as well to use it later
102
118
 
103
119
  if (!isSilentRenew) {
104
120
  handleUser(dispatch, userManager);
@@ -119,7 +135,11 @@ function logout(dispatch, userManagerInstance) {
119
135
  dispatch((0, _actions.setLoggedUser)(null));
120
136
  sessionStorage.removeItem(hackauthoritykey); //To remove when hack is removed
121
137
 
122
- return userManagerInstance.signoutRedirect().then(function () {
138
+ return userManagerInstance.signoutRedirect({
139
+ extraQueryParams: {
140
+ TargetResource: userManagerInstance.settings.post_logout_redirect_uri
141
+ }
142
+ }).then(function () {
123
143
  return console.debug('logged out');
124
144
  });
125
145
  }
@@ -160,8 +180,40 @@ function handleUser(dispatch, userManager) {
160
180
  dispatchUser(dispatch, userManager);
161
181
  });
162
182
  userManager.events.addSilentRenewError(function (error) {
163
- console.debug(error);
164
- logout(dispatch, userManager);
183
+ console.debug(error); // wait for accessTokenExpiringNotificationTime so that the user is expired
184
+ // otherwise the library tries to signin immediately when we do getUser()
185
+
186
+ window.setTimeout(function () {
187
+ userManager.getUser().then(function (user) {
188
+ var now = parseInt(Date.now() / 1000);
189
+ var exp = (0, _jwtDecode["default"])(user.id_token).exp;
190
+ var idTokenExpiresIn = exp - now;
191
+
192
+ if (idTokenExpiresIn < 0) {
193
+ 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
194
+
195
+ return logout(dispatch, userManager);
196
+ } else if (userManager.idpSettings.maxExpiresIn) {
197
+ if (idTokenExpiresIn < userManager.idpSettings.maxExpiresIn) {
198
+ // TODO here attempt last chance login ? snackbar to notify the user ? Popup ?
199
+ // for now we do the same thing as in the else block
200
+ console.log('Error in silent renew, but idtoken ALMOST expiring (expiring in' + idTokenExpiresIn + ') => last chance' + userManager.idpSettings.maxExpiresIn, error);
201
+ user.expires_in = userManager.idpSettings.maxExpiresIn;
202
+ userManager.storeUser(user).then(function () {
203
+ userManager.getUser();
204
+ });
205
+ } else {
206
+ console.log('Error in silent renew, but idtoken NOT expiring (expiring in' + idTokenExpiresIn + ') => postponing expiration to' + userManager.idpSettings.maxExpiresIn, error);
207
+ user.expires_in = userManager.idpSettings.maxExpiresIn;
208
+ userManager.storeUser(user).then(function () {
209
+ userManager.getUser();
210
+ });
211
+ }
212
+ } else {
213
+ console.log('Error in silent renew, unsupported configuration: token still valid for ' + idTokenExpiresIn + ' but maxExpiresIn is not configured:' + userManager.idpSettings.maxExpiresIn, error);
214
+ }
215
+ });
216
+ }, accessTokenExpiringNotificationTime * 1000);
165
217
  });
166
218
  console.debug('dispatch user');
167
219
  dispatchUser(dispatch, userManager);
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "@gridsuite/commons-ui",
3
- "version": "0.20.5",
3
+ "version": "0.22.1",
4
4
  "description": "common react components for gridsuite applications",
5
+ "engines": {
6
+ "npm": "<=6",
7
+ "node": "<=14"
8
+ },
5
9
  "main": "lib/index.js",
6
10
  "files": [
7
11
  "css",