@gridsuite/commons-ui 0.46.0 → 0.47.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.
Files changed (183) hide show
  1. package/README.md +0 -17
  2. package/dist/components/AuthenticationRouter/AuthenticationRouter.js +147 -0
  3. package/dist/components/CardErrorBoundary/card-error-boundary.js +110 -0
  4. package/dist/components/ElementSearchDialog/element-search-dialog.js +139 -0
  5. package/dist/components/ElementSearchDialog/equipment-item.js +77 -0
  6. package/dist/components/ElementSearchDialog/tag-renderer.js +34 -0
  7. package/dist/components/FlatParameters/FlatParameters.js +411 -0
  8. package/dist/components/Login/Login.js +78 -0
  9. package/dist/components/Login/Logout.js +69 -0
  10. package/dist/components/MuiVirtualizedTable/ColumnHeader.js +127 -0
  11. package/dist/components/MuiVirtualizedTable/KeyedColumnsRowIndexer.js +548 -0
  12. package/dist/components/MuiVirtualizedTable/MuiVirtualizedTable.js +790 -0
  13. package/dist/components/MultipleSelectionDialog/MultipleSelectionDialog.js +87 -0
  14. package/dist/components/OverflowableText/overflowable-text.js +87 -0
  15. package/dist/components/ReportViewer/filter-button.js +64 -0
  16. package/dist/components/ReportViewer/log-report-item.js +95 -0
  17. package/dist/components/ReportViewer/log-report.js +49 -0
  18. package/dist/components/ReportViewer/log-table.js +131 -0
  19. package/dist/components/ReportViewer/multi-select-list.js +40 -0
  20. package/dist/components/ReportViewer/report-item.js +112 -0
  21. package/dist/components/ReportViewer/report-tree-view-context.js +8 -0
  22. package/dist/components/ReportViewer/report-viewer.js +158 -0
  23. package/dist/components/ReportViewerDialog/report-viewer-dialog.js +61 -0
  24. package/dist/components/SignInCallbackHandler/SignInCallbackHandler.js +13 -0
  25. package/dist/components/SilentRenewCallbackHandler/SilentRenewCallbackHandler.js +16 -0
  26. package/dist/components/SnackbarProvider/SnackbarProvider.js +28 -0
  27. package/dist/components/TopBar/AboutDialog.js +467 -0
  28. package/dist/components/TopBar/GridLogo.js +71 -0
  29. package/dist/components/TopBar/TopBar.js +679 -0
  30. package/dist/components/TreeViewFinder/TreeViewFinder.js +288 -0
  31. package/dist/components/react-hook-form/autocomplete-input.js +96 -0
  32. package/dist/components/react-hook-form/booleans/boolean-input.js +49 -0
  33. package/dist/components/react-hook-form/booleans/checkbox-input.js +24 -0
  34. package/dist/components/react-hook-form/booleans/switch-input.js +24 -0
  35. package/dist/components/react-hook-form/error-management/error-input.js +42 -0
  36. package/dist/components/react-hook-form/error-management/field-error-alert.js +9 -0
  37. package/dist/components/react-hook-form/error-management/mid-form-error.js +20 -0
  38. package/dist/components/react-hook-form/numbers/float-input.js +51 -0
  39. package/dist/components/react-hook-form/numbers/integer-input.js +36 -0
  40. package/dist/components/react-hook-form/numbers/utils.js +10 -0
  41. package/dist/components/react-hook-form/radio-input.js +44 -0
  42. package/dist/components/react-hook-form/select-input.js +31 -0
  43. package/dist/components/react-hook-form/slider-input.js +43 -0
  44. package/dist/components/react-hook-form/text-input.js +94 -0
  45. package/dist/components/react-hook-form/utils/cancel-button.js +16 -0
  46. package/dist/components/react-hook-form/utils/field-label.js +12 -0
  47. package/dist/components/react-hook-form/utils/functions.js +36 -0
  48. package/dist/components/react-hook-form/utils/submit-button.js +23 -0
  49. package/dist/components/react-hook-form/utils/text-field-with-adornment.js +96 -0
  50. package/dist/components/translations/card-error-boundary-en.js +8 -0
  51. package/dist/components/translations/card-error-boundary-fr.js +8 -0
  52. package/dist/components/translations/common-button-en.js +7 -0
  53. package/dist/components/translations/common-button-fr.js +7 -0
  54. package/dist/components/translations/element-search-en.js +7 -0
  55. package/dist/components/translations/element-search-fr.js +7 -0
  56. package/dist/components/translations/equipment-search-en.js +21 -0
  57. package/dist/components/translations/equipment-search-fr.js +21 -0
  58. package/dist/components/translations/flat-parameters-en.js +8 -0
  59. package/dist/components/translations/flat-parameters-fr.js +8 -0
  60. package/dist/components/translations/login-en.js +14 -0
  61. package/dist/components/translations/login-fr.js +14 -0
  62. package/dist/components/translations/multiple-selection-dialog-en.js +8 -0
  63. package/dist/components/translations/multiple-selection-dialog-fr.js +8 -0
  64. package/dist/components/translations/report-viewer-en.js +8 -0
  65. package/dist/components/translations/report-viewer-fr.js +8 -0
  66. package/dist/components/translations/table-en.js +6 -0
  67. package/dist/components/translations/table-fr.js +6 -0
  68. package/dist/components/translations/top-bar-en.js +27 -0
  69. package/dist/components/translations/top-bar-fr.js +27 -0
  70. package/dist/components/translations/treeview-finder-en.js +12 -0
  71. package/dist/components/translations/treeview-finder-fr.js +12 -0
  72. package/dist/hooks/useDebounce.js +17 -0
  73. package/{es/components/ElementSearchDialog/index.js → dist/hooks/useIntlRef.d.ts} +2 -2
  74. package/dist/hooks/useIntlRef.js +13 -0
  75. package/dist/hooks/useSnackMessage.js +81 -0
  76. package/dist/index.d.ts +225 -0
  77. package/dist/index.js +154 -0
  78. package/dist/utils/AuthService.js +336 -0
  79. package/dist/utils/ElementType.js +38 -0
  80. package/dist/utils/EquipmentType.js +132 -0
  81. package/dist/utils/UserManagerMock.js +85 -0
  82. package/dist/utils/actions.js +71 -0
  83. package/dist/utils/algos.js +24 -0
  84. package/dist/utils/styles.js +13 -0
  85. package/package.json +36 -21
  86. package/es/components/AuthenticationRouter/AuthenticationRouter.js +0 -102
  87. package/es/components/AuthenticationRouter/index.js +0 -7
  88. package/es/components/CardErrorBoundary/card-error-boundary.js +0 -138
  89. package/es/components/CardErrorBoundary/index.js +0 -7
  90. package/es/components/ElementSearchDialog/element-search-dialog.js +0 -153
  91. package/es/components/ElementSearchDialog/equipment-item.js +0 -63
  92. package/es/components/ElementSearchDialog/tag-renderer.js +0 -29
  93. package/es/components/FlatParameters/FlatParameters.js +0 -448
  94. package/es/components/FlatParameters/index.js +0 -8
  95. package/es/components/Login/Login.js +0 -79
  96. package/es/components/Login/Logout.js +0 -78
  97. package/es/components/Login/index.js +0 -7
  98. package/es/components/MuiVirtualizedTable/ColumnHeader.js +0 -125
  99. package/es/components/MuiVirtualizedTable/KeyedColumnsRowIndexer.js +0 -619
  100. package/es/components/MuiVirtualizedTable/MuiVirtualizedTable.js +0 -780
  101. package/es/components/MuiVirtualizedTable/index.js +0 -9
  102. package/es/components/MultipleSelectionDialog/MultipleSelectionDialog.js +0 -95
  103. package/es/components/MultipleSelectionDialog/index.js +0 -8
  104. package/es/components/OverflowableText/index.js +0 -7
  105. package/es/components/OverflowableText/overflowable-text.js +0 -81
  106. package/es/components/ReportViewer/filter-button.js +0 -77
  107. package/es/components/ReportViewer/index.js +0 -7
  108. package/es/components/ReportViewer/log-report-item.js +0 -97
  109. package/es/components/ReportViewer/log-report.js +0 -63
  110. package/es/components/ReportViewer/log-table.js +0 -130
  111. package/es/components/ReportViewer/multi-select-list.js +0 -56
  112. package/es/components/ReportViewer/report-item.js +0 -131
  113. package/es/components/ReportViewer/report-tree-view-context.js +0 -13
  114. package/es/components/ReportViewer/report-viewer.js +0 -167
  115. package/es/components/ReportViewerDialog/index.js +0 -7
  116. package/es/components/ReportViewerDialog/report-viewer-dialog.js +0 -67
  117. package/es/components/SignInCallbackHandler/SignInCallbackHandler.js +0 -19
  118. package/es/components/SignInCallbackHandler/index.js +0 -7
  119. package/es/components/SilentRenewCallbackHandler/SilentRenewCallbackHandler.js +0 -19
  120. package/es/components/SilentRenewCallbackHandler/index.js +0 -7
  121. package/es/components/SnackbarProvider/SnackbarProvider.js +0 -39
  122. package/es/components/SnackbarProvider/index.js +0 -7
  123. package/es/components/TopBar/AboutDialog.js +0 -456
  124. package/es/components/TopBar/GridLogo.js +0 -73
  125. package/es/components/TopBar/TopBar.js +0 -487
  126. package/es/components/TopBar/index.js +0 -9
  127. package/es/components/TreeViewFinder/TreeViewFinder.js +0 -341
  128. package/es/components/TreeViewFinder/index.js +0 -7
  129. package/es/components/images/powsybl_logo.svg +0 -35
  130. package/es/components/react-hook-form/autocomplete-input.js +0 -110
  131. package/es/components/react-hook-form/booleans/boolean-input.js +0 -56
  132. package/es/components/react-hook-form/booleans/checkbox-input.js +0 -28
  133. package/es/components/react-hook-form/booleans/switch-input.js +0 -28
  134. package/es/components/react-hook-form/error-management/error-input.js +0 -50
  135. package/es/components/react-hook-form/error-management/field-error-alert.js +0 -22
  136. package/es/components/react-hook-form/error-management/mid-form-error.js +0 -25
  137. package/es/components/react-hook-form/numbers/float-input.js +0 -105
  138. package/es/components/react-hook-form/numbers/integer-input.js +0 -35
  139. package/es/components/react-hook-form/numbers/utils.js +0 -6
  140. package/es/components/react-hook-form/radio-input.js +0 -55
  141. package/es/components/react-hook-form/select-input.js +0 -40
  142. package/es/components/react-hook-form/slider-input.js +0 -48
  143. package/es/components/react-hook-form/text-input.js +0 -100
  144. package/es/components/react-hook-form/utils/cancel-button.js +0 -28
  145. package/es/components/react-hook-form/utils/field-label.js +0 -15
  146. package/es/components/react-hook-form/utils/functions.js +0 -42
  147. package/es/components/react-hook-form/utils/submit-button.js +0 -29
  148. package/es/components/react-hook-form/utils/text-field-with-adornment.js +0 -92
  149. package/es/components/translations/card-error-boundary-en.js +0 -13
  150. package/es/components/translations/card-error-boundary-fr.js +0 -13
  151. package/es/components/translations/common-button-en.js +0 -12
  152. package/es/components/translations/common-button-fr.js +0 -12
  153. package/es/components/translations/element-search-en.js +0 -12
  154. package/es/components/translations/element-search-fr.js +0 -12
  155. package/es/components/translations/equipment-search-en.js +0 -26
  156. package/es/components/translations/equipment-search-fr.js +0 -26
  157. package/es/components/translations/flat-parameters-en.js +0 -13
  158. package/es/components/translations/flat-parameters-fr.js +0 -13
  159. package/es/components/translations/inputs-en.js +0 -25
  160. package/es/components/translations/inputs-fr.js +0 -25
  161. package/es/components/translations/login-en.js +0 -19
  162. package/es/components/translations/login-fr.js +0 -19
  163. package/es/components/translations/multiple-selection-dialog-en.js +0 -13
  164. package/es/components/translations/multiple-selection-dialog-fr.js +0 -13
  165. package/es/components/translations/report-viewer-en.js +0 -13
  166. package/es/components/translations/report-viewer-fr.js +0 -13
  167. package/es/components/translations/table-en.js +0 -11
  168. package/es/components/translations/table-fr.js +0 -11
  169. package/es/components/translations/top-bar-en.js +0 -32
  170. package/es/components/translations/top-bar-fr.js +0 -32
  171. package/es/components/translations/treeview-finder-en.js +0 -17
  172. package/es/components/translations/treeview-finder-fr.js +0 -17
  173. package/es/hooks/useDebounce.js +0 -26
  174. package/es/hooks/useIntlRef.js +0 -22
  175. package/es/hooks/useSnackMessage.js +0 -81
  176. package/es/index.js +0 -71
  177. package/es/utils/AuthService.js +0 -312
  178. package/es/utils/ElementType.js +0 -53
  179. package/es/utils/EquipmentType.js +0 -133
  180. package/es/utils/UserManagerMock.js +0 -81
  181. package/es/utils/actions.js +0 -65
  182. package/es/utils/algos.js +0 -29
  183. package/es/utils/styles.js +0 -35
@@ -0,0 +1,336 @@
1
+ import { Log, UserManager } from "oidc-client";
2
+ import { UserManagerMock } from "./UserManagerMock.js";
3
+ import { setShowAuthenticationRouterLogin, setLoggedUser, setLogoutError, setUnauthorizedUserInfo, setUserValidationError, resetAuthenticationRouterError, setSignInCallbackError } from "./actions.js";
4
+ import jwtDecode from "jwt-decode";
5
+ window.OIDCLog = Log;
6
+ const hackAuthorityKey = "oidc.hack.authority";
7
+ const oidcHackReloadedKey = "gridsuite-oidc-hack-reloaded";
8
+ const pathKey = "powsybl-gridsuite-current-path";
9
+ function isIssuerErrorForCodeFlow(error) {
10
+ return error.message.includes("Invalid issuer in token");
11
+ }
12
+ function extractIssuerToSessionStorage(error) {
13
+ const issuer = error.message.split(" ").pop();
14
+ sessionStorage.setItem(hackAuthorityKey, issuer);
15
+ }
16
+ function reload() {
17
+ if (!sessionStorage.getItem(oidcHackReloadedKey)) {
18
+ sessionStorage.setItem(oidcHackReloadedKey, true);
19
+ console.log("Hack oidc, reload page to make login work");
20
+ window.location.reload();
21
+ }
22
+ }
23
+ function reloadTimerOnExpiresIn(user, userManager, expiresIn) {
24
+ user.expires_in = expiresIn;
25
+ userManager.storeUser(user).then(() => {
26
+ userManager.getUser();
27
+ });
28
+ }
29
+ function handleSigninSilent(dispatch, userManager) {
30
+ userManager.getUser().then((user) => {
31
+ if (user == null || getIdTokenExpiresIn(user) < 0) {
32
+ return userManager.signinSilent().catch((error) => {
33
+ dispatch(setShowAuthenticationRouterLogin(true));
34
+ const errorIssuerCodeFlow = isIssuerErrorForCodeFlow(error);
35
+ const errorIssuerImplicitFlow = error.message === "authority mismatch on settings vs. signin state";
36
+ if (errorIssuerCodeFlow) {
37
+ extractIssuerToSessionStorage(error);
38
+ }
39
+ if (errorIssuerCodeFlow || errorIssuerImplicitFlow) {
40
+ reload();
41
+ }
42
+ });
43
+ }
44
+ });
45
+ }
46
+ function initializeAuthenticationDev(dispatch, isSilentRenew, validateUser, isSigninCallback) {
47
+ let userManager = new UserManagerMock({});
48
+ if (!isSilentRenew) {
49
+ handleUser(dispatch, userManager, validateUser);
50
+ if (!isSigninCallback) {
51
+ handleSigninSilent(dispatch, userManager);
52
+ }
53
+ }
54
+ return Promise.resolve(userManager);
55
+ }
56
+ const accessTokenExpiringNotificationTime = 60;
57
+ function initializeAuthenticationProd(dispatch, isSilentRenew, idpSettings, validateUser, authorizationCodeFlowEnabled, isSigninCallback) {
58
+ return idpSettings.then((r) => r.json()).then((idpSettings2) => {
59
+ const regextoken = /id_token=[^&]*/;
60
+ const regexstate = /state=[^&]*/;
61
+ const regexexpires = /expires_in=[^&]*/;
62
+ let authority;
63
+ if (window.location.hash) {
64
+ const matched_id_token = window.location.hash.match(regextoken);
65
+ const matched_state = window.location.hash.match(regexstate);
66
+ if (matched_id_token != null && matched_state != null) {
67
+ const id_token = matched_id_token[0].split("=")[1];
68
+ const state = matched_state[0].split("=")[1];
69
+ const strState = localStorage.getItem("oidc." + state);
70
+ if (strState != null) {
71
+ const decoded = jwtDecode(id_token);
72
+ authority = decoded.iss;
73
+ const storedState = JSON.parse(strState);
74
+ console.debug(
75
+ "Replacing authority in storedState. Before: ",
76
+ storedState.authority,
77
+ "after: ",
78
+ authority
79
+ );
80
+ storedState.authority = authority;
81
+ localStorage.setItem(
82
+ "oidc." + state,
83
+ JSON.stringify(storedState)
84
+ );
85
+ sessionStorage.setItem(hackAuthorityKey, authority);
86
+ const matched_expires = window.location.hash.match(regexexpires);
87
+ if (matched_expires != null) {
88
+ const expires_in = parseInt(
89
+ matched_expires[0].split("=")[1]
90
+ );
91
+ window.location.hash = window.location.hash.replace(
92
+ matched_expires[0],
93
+ "expires_in=" + computeMinExpiresIn(
94
+ expires_in,
95
+ id_token,
96
+ idpSettings2.maxExpiresIn
97
+ )
98
+ );
99
+ }
100
+ }
101
+ }
102
+ }
103
+ authority = authority || sessionStorage.getItem(hackAuthorityKey) || idpSettings2.authority;
104
+ const responseSettings = authorizationCodeFlowEnabled ? { response_type: "code" } : {
105
+ response_type: "id_token token",
106
+ response_mode: "fragment"
107
+ };
108
+ const settings = {
109
+ authority,
110
+ client_id: idpSettings2.client_id,
111
+ redirect_uri: idpSettings2.redirect_uri,
112
+ post_logout_redirect_uri: idpSettings2.post_logout_redirect_uri,
113
+ silent_redirect_uri: idpSettings2.silent_redirect_uri,
114
+ scope: idpSettings2.scope,
115
+ automaticSilentRenew: !isSilentRenew,
116
+ accessTokenExpiringNotificationTime,
117
+ ...responseSettings
118
+ };
119
+ let userManager = new UserManager(settings);
120
+ userManager.idpSettings = idpSettings2;
121
+ userManager.authorizationCodeFlowEnabled = authorizationCodeFlowEnabled;
122
+ if (!isSilentRenew) {
123
+ handleUser(dispatch, userManager, validateUser);
124
+ if (!isSigninCallback) {
125
+ handleSigninSilent(dispatch, userManager);
126
+ }
127
+ }
128
+ return userManager;
129
+ }).catch((error) => {
130
+ console.debug("error when importing the idp settings", error);
131
+ dispatch(setShowAuthenticationRouterLogin(true));
132
+ throw error;
133
+ });
134
+ }
135
+ function computeMinExpiresIn(expiresIn, idToken, maxExpiresIn) {
136
+ const now = parseInt(Date.now() / 1e3);
137
+ const exp = jwtDecode(idToken).exp;
138
+ const idTokenExpiresIn = exp - now;
139
+ let newExpiresIn = expiresIn;
140
+ let newExpiresInReplaceReason;
141
+ if (expiresIn === void 0 || idTokenExpiresIn < newExpiresIn) {
142
+ newExpiresIn = idTokenExpiresIn;
143
+ newExpiresInReplaceReason = "idtoken.exp is earlier";
144
+ }
145
+ if (maxExpiresIn && maxExpiresIn < newExpiresIn) {
146
+ newExpiresIn = maxExpiresIn;
147
+ newExpiresInReplaceReason = "idpSettings.maxExpiresIn is smaller";
148
+ }
149
+ if (newExpiresInReplaceReason) {
150
+ console.debug(
151
+ "Replacing expiresIn in user to " + newExpiresIn + " because " + newExpiresInReplaceReason + ". ",
152
+ "debug:",
153
+ "original expires_in: " + expiresIn + ", ",
154
+ "idTokenExpiresIn: " + idTokenExpiresIn + ", idpSettings maxExpiresIn: " + maxExpiresIn
155
+ );
156
+ }
157
+ return newExpiresIn;
158
+ }
159
+ function login(location, userManagerInstance) {
160
+ sessionStorage.setItem(pathKey, location.pathname + location.search);
161
+ return userManagerInstance.signinRedirect().then(() => console.debug("login"));
162
+ }
163
+ function logout(dispatch, userManagerInstance) {
164
+ sessionStorage.removeItem(hackAuthorityKey);
165
+ return userManagerInstance.getUser().then((user) => {
166
+ if (user) {
167
+ return userManagerInstance.signoutRedirect({
168
+ extraQueryParams: {
169
+ TargetResource: userManagerInstance.settings.post_logout_redirect_uri
170
+ }
171
+ }).then(() => {
172
+ console.debug("logged out, window is closing...");
173
+ }).catch((e) => {
174
+ var _a;
175
+ console.log("Error during logout :", e);
176
+ dispatch(setLoggedUser(null));
177
+ dispatch(setLogoutError((_a = user == null ? void 0 : user.profile) == null ? void 0 : _a.name, { error: e }));
178
+ });
179
+ } else {
180
+ console.log("Error nobody to logout ");
181
+ }
182
+ });
183
+ }
184
+ function getIdTokenExpiresIn(user) {
185
+ const now = parseInt(Date.now() / 1e3);
186
+ const exp = jwtDecode(user.id_token).exp;
187
+ return exp - now;
188
+ }
189
+ function dispatchUser(dispatch, userManagerInstance, validateUser) {
190
+ return userManagerInstance.getUser().then((user) => {
191
+ if (user) {
192
+ if (getIdTokenExpiresIn(user) < 0) {
193
+ console.debug(
194
+ "User token is expired and will not be dispatched"
195
+ );
196
+ return;
197
+ }
198
+ let validateUserPromise = validateUser && validateUser(user) || Promise.resolve(true);
199
+ return validateUserPromise.then((valid) => {
200
+ var _a;
201
+ if (!valid) {
202
+ console.debug(
203
+ "User isn't authorized to log in and will not be dispatched"
204
+ );
205
+ return dispatch(
206
+ setUnauthorizedUserInfo((_a = user == null ? void 0 : user.profile) == null ? void 0 : _a.name, {})
207
+ );
208
+ }
209
+ console.debug(
210
+ "User has been successfully loaded from store."
211
+ );
212
+ if (userManagerInstance.authorizationCodeFlowEnabled) {
213
+ reloadTimerOnExpiresIn(
214
+ user,
215
+ userManagerInstance,
216
+ computeMinExpiresIn(
217
+ user.expires_in,
218
+ user.id_token,
219
+ userManagerInstance.idpSettings.maxExpiresIn
220
+ )
221
+ );
222
+ }
223
+ return dispatch(setLoggedUser(user));
224
+ }).catch((e) => {
225
+ var _a;
226
+ console.log("Error in dispatchUser", e);
227
+ return dispatch(
228
+ setUserValidationError((_a = user == null ? void 0 : user.profile) == null ? void 0 : _a.name, {
229
+ error: e
230
+ })
231
+ );
232
+ });
233
+ } else {
234
+ console.debug("You are not logged in.");
235
+ }
236
+ });
237
+ }
238
+ function getPreLoginPath() {
239
+ return sessionStorage.getItem(pathKey);
240
+ }
241
+ function navigateToPreLoginPath(navigate) {
242
+ const previousPath = getPreLoginPath();
243
+ navigate(previousPath);
244
+ }
245
+ function handleSigninCallback(dispatch, navigate, userManagerInstance) {
246
+ let reloadAfterNavigate = false;
247
+ userManagerInstance.signinRedirectCallback().catch(function(e) {
248
+ if (isIssuerErrorForCodeFlow(e)) {
249
+ extractIssuerToSessionStorage(e);
250
+ reloadAfterNavigate = true;
251
+ } else {
252
+ throw e;
253
+ }
254
+ }).then(function() {
255
+ dispatch(setSignInCallbackError(null));
256
+ navigateToPreLoginPath(navigate);
257
+ if (reloadAfterNavigate) {
258
+ reload();
259
+ }
260
+ }).catch(function(e) {
261
+ dispatch(setSignInCallbackError(e));
262
+ console.error(e);
263
+ });
264
+ }
265
+ function handleSilentRenewCallback(userManagerInstance) {
266
+ userManagerInstance.signinSilentCallback();
267
+ }
268
+ function handleUser(dispatch, userManager, validateUser) {
269
+ userManager.events.addUserLoaded((user) => {
270
+ console.debug("user loaded", user);
271
+ dispatchUser(dispatch, userManager, validateUser);
272
+ });
273
+ userManager.events.addSilentRenewError((error) => {
274
+ console.debug(error);
275
+ window.setTimeout(() => {
276
+ userManager.getUser().then((user) => {
277
+ if (!user) {
278
+ console.error(
279
+ "user is null at silent renew error, it shouldn't happen."
280
+ );
281
+ }
282
+ const idTokenExpiresIn = getIdTokenExpiresIn(user);
283
+ if (idTokenExpiresIn < 0) {
284
+ console.log(
285
+ "Error in silent renew, idtoken expired: " + idTokenExpiresIn + " => Logging out.",
286
+ error
287
+ );
288
+ dispatch(setShowAuthenticationRouterLogin(true));
289
+ dispatch(resetAuthenticationRouterError());
290
+ return dispatch(setLoggedUser(null));
291
+ } else if (userManager.idpSettings.maxExpiresIn) {
292
+ if (idTokenExpiresIn < userManager.idpSettings.maxExpiresIn) {
293
+ console.log(
294
+ "Error in silent renew, but idtoken ALMOST expiring (expiring in" + idTokenExpiresIn + ") => last chance, next error will logout",
295
+ "maxExpiresIn = " + userManager.idpSettings.maxExpiresIn,
296
+ "last renew attempt in " + idTokenExpiresIn - accessTokenExpiringNotificationTime + "seconds",
297
+ error
298
+ );
299
+ reloadTimerOnExpiresIn(
300
+ user,
301
+ userManager,
302
+ idTokenExpiresIn
303
+ );
304
+ } else {
305
+ console.log(
306
+ "Error in silent renew, but idtoken NOT expiring (expiring in" + idTokenExpiresIn + ") => postponing expiration to" + userManager.idpSettings.maxExpiresIn,
307
+ error
308
+ );
309
+ reloadTimerOnExpiresIn(
310
+ user,
311
+ userManager,
312
+ userManager.idpSettings.maxExpiresIn
313
+ );
314
+ }
315
+ } else {
316
+ console.log(
317
+ "Error in silent renew, unsupported configuration: token still valid for " + idTokenExpiresIn + " but maxExpiresIn is not configured:" + userManager.idpSettings.maxExpiresIn,
318
+ error
319
+ );
320
+ }
321
+ });
322
+ }, accessTokenExpiringNotificationTime * 1e3);
323
+ });
324
+ console.debug("dispatch user");
325
+ dispatchUser(dispatch, userManager, validateUser);
326
+ }
327
+ export {
328
+ dispatchUser,
329
+ getPreLoginPath,
330
+ handleSigninCallback,
331
+ handleSilentRenewCallback,
332
+ initializeAuthenticationDev,
333
+ initializeAuthenticationProd,
334
+ login,
335
+ logout
336
+ };
@@ -0,0 +1,38 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import "react";
3
+ import { Settings, Article, NoteAlt, OfflineBolt, LibraryBooksOutlined } from "@mui/icons-material";
4
+ const elementType = {
5
+ DIRECTORY: "DIRECTORY",
6
+ STUDY: "STUDY",
7
+ FILTER: "FILTER",
8
+ MODIFICATION: "MODIFICATION",
9
+ CONTINGENCY_LIST: "CONTINGENCY_LIST",
10
+ VOLTAGE_INIT_PARAMETERS: "VOLTAGE_INIT_PARAMETERS",
11
+ SECURITY_ANALYSIS_PARAMETERS: "SECURITY_ANALYSIS_PARAMETERS",
12
+ LOADFLOW_PARAMETERS: "LOADFLOW_PARAMETERS",
13
+ SENSITIVITY_PARAMETERS: "SENSITIVITY_PARAMETERS"
14
+ };
15
+ function getFileIcon(type, style) {
16
+ switch (type) {
17
+ case elementType.STUDY:
18
+ return /* @__PURE__ */ jsx(LibraryBooksOutlined, { sx: style });
19
+ case elementType.CONTINGENCY_LIST:
20
+ return /* @__PURE__ */ jsx(OfflineBolt, { sx: style });
21
+ case elementType.MODIFICATION:
22
+ return /* @__PURE__ */ jsx(NoteAlt, { sx: style });
23
+ case elementType.FILTER:
24
+ return /* @__PURE__ */ jsx(Article, { sx: style });
25
+ case elementType.VOLTAGE_INIT_PARAMETERS:
26
+ case elementType.SECURITY_ANALYSIS_PARAMETERS:
27
+ case elementType.LOADFLOW_PARAMETERS:
28
+ return /* @__PURE__ */ jsx(Settings, { sx: style });
29
+ case elementType.DIRECTORY:
30
+ return;
31
+ default:
32
+ console.warn("unknown type [" + type + "]");
33
+ }
34
+ }
35
+ export {
36
+ elementType,
37
+ getFileIcon
38
+ };
@@ -0,0 +1,132 @@
1
+ import { LIGHT_THEME } from "../components/TopBar/TopBar.js";
2
+ const TYPE_TAG_MAX_SIZE = "90px";
3
+ const VL_TAG_MAX_SIZE = "100px";
4
+ const equipmentStyles = {
5
+ equipmentOption: {
6
+ display: "flex",
7
+ gap: "20px",
8
+ width: "100%",
9
+ margin: "0px",
10
+ padding: "0px",
11
+ alignItems: "center",
12
+ justifyContent: "space-between"
13
+ },
14
+ equipmentTag: (theme) => ({
15
+ borderRadius: "10px",
16
+ padding: "4px",
17
+ fontSize: "x-small",
18
+ textAlign: "center",
19
+ color: theme === LIGHT_THEME ? "inherit" : "black"
20
+ }),
21
+ equipmentTypeTag: {
22
+ minWidth: TYPE_TAG_MAX_SIZE,
23
+ maxWidth: TYPE_TAG_MAX_SIZE,
24
+ background: "lightblue"
25
+ },
26
+ equipmentVlTag: {
27
+ width: VL_TAG_MAX_SIZE,
28
+ minWidth: VL_TAG_MAX_SIZE,
29
+ maxWidth: VL_TAG_MAX_SIZE,
30
+ background: "lightgray",
31
+ fontStyle: "italic"
32
+ },
33
+ result: {
34
+ width: "100%",
35
+ padding: "2px"
36
+ }
37
+ };
38
+ const EQUIPMENT_TYPE = {
39
+ SUBSTATION: {
40
+ name: "SUBSTATION",
41
+ tagLabel: "equipment_search/substationTag"
42
+ },
43
+ VOLTAGE_LEVEL: {
44
+ name: "VOLTAGE_LEVEL",
45
+ tagLabel: "equipment_search/voltageLevelTag"
46
+ },
47
+ LINE: {
48
+ name: "LINE",
49
+ tagLabel: "equipment_search/lineTag"
50
+ },
51
+ TWO_WINDINGS_TRANSFORMER: {
52
+ name: "TWO_WINDINGS_TRANSFORMER",
53
+ tagLabel: "equipment_search/2wtTag"
54
+ },
55
+ THREE_WINDINGS_TRANSFORMER: {
56
+ name: "THREE_WINDINGS_TRANSFORMER",
57
+ tagLabel: "equipment_search/3wtTag"
58
+ },
59
+ HVDC_LINE: {
60
+ name: "HVDC_LINE",
61
+ tagLabel: "equipment_search/hvdcLineTag"
62
+ },
63
+ GENERATOR: {
64
+ name: "GENERATOR",
65
+ tagLabel: "equipment_search/generatorTag"
66
+ },
67
+ BATTERY: {
68
+ name: "BATTERY",
69
+ tagLabel: "equipment_search/batteryTag"
70
+ },
71
+ LOAD: {
72
+ name: "LOAD",
73
+ tagLabel: "equipment_search/loadTag"
74
+ },
75
+ SHUNT_COMPENSATOR: {
76
+ name: "SHUNT_COMPENSATOR",
77
+ tagLabel: "equipment_search/shuntTag"
78
+ },
79
+ DANGLING_LINE: {
80
+ name: "DANGLING_LINE",
81
+ tagLabel: "equipment_search/lineTag"
82
+ },
83
+ STATIC_VAR_COMPENSATOR: {
84
+ name: "STATIC_VAR_COMPENSATOR",
85
+ tagLabel: "equipment_search/svcTag"
86
+ },
87
+ HVDC_CONVERTER_STATION: {
88
+ name: "HVDC_CONVERTER_STATION",
89
+ tagLabel: "equipment_search/hvdcStationTag"
90
+ },
91
+ BUSBAR_SECTION: {
92
+ name: "BUSBAR_SECTION",
93
+ tagLabel: "equipment_search/busbarSectionTag"
94
+ },
95
+ BUS: {
96
+ name: "BUS",
97
+ tagLabel: "equipment_search/busTag"
98
+ },
99
+ SWITCH: {
100
+ name: "SWITCH",
101
+ tagLabel: "equipment_search/switchTag"
102
+ }
103
+ };
104
+ const getEquipmentsInfosForSearchBar = (equipmentsInfos, getNameOrId) => {
105
+ return equipmentsInfos.flatMap((e) => {
106
+ let label = getNameOrId(e);
107
+ return e.type === "SUBSTATION" ? [
108
+ {
109
+ label,
110
+ id: e.id,
111
+ key: e.id,
112
+ type: e.type
113
+ }
114
+ ] : e.voltageLevels.map((vli) => {
115
+ return {
116
+ label,
117
+ id: e.id,
118
+ key: e.id + "_" + vli.id,
119
+ type: e.type,
120
+ voltageLevelLabel: getNameOrId(vli),
121
+ voltageLevelId: vli.id
122
+ };
123
+ });
124
+ });
125
+ };
126
+ export {
127
+ EQUIPMENT_TYPE,
128
+ TYPE_TAG_MAX_SIZE,
129
+ VL_TAG_MAX_SIZE,
130
+ equipmentStyles,
131
+ getEquipmentsInfosForSearchBar
132
+ };
@@ -0,0 +1,85 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ class Events {
8
+ constructor() {
9
+ __publicField(this, "userLoadedCallbacks", []);
10
+ }
11
+ addUserLoaded(callback) {
12
+ this.userLoadedCallbacks.push(callback);
13
+ }
14
+ addSilentRenewError(callback) {
15
+ }
16
+ }
17
+ class UserManagerMock {
18
+ constructor(settings) {
19
+ __publicField(this, "settings");
20
+ __publicField(this, "events");
21
+ __publicField(this, "user", {
22
+ profile: { name: "John Doe", email: "Jhon.Doe@rte-france.com" },
23
+ id_token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IllNRUxIVDBndmIwbXhvU0RvWWZvbWpxZmpZVSJ9.eyJhdWQiOiI5YzQwMjQ2MS1iMmFiLTQ3NjctOWRiMy02Njg1OWJiMGZjZDAiLCJpc3MiOiJodHRwczovL2xvZ2luLm1pY3Jvc29mdG9ubGluZS5jb20vNzUwMmRhZDUtZDY0Yy00NmM3LTlkNDctYjE2ZjU4MGZjZmE5L3YyLjAiLCJpYXQiOjE1ODUzMzEyNDksIm5iZiI6MTU4NTMzMTI0OSwiZXhwIjoyNTg1MzM1MTQ5LCJhaW8iOiJBV1FBbS84UEFBQUF3Q0xyTDRIUEUvTnVjOU9OdHN0SUV4cVpyMUlqa1FGbXJvUW5EUzJBaksyWnpneUhQTldPdkE3bitveHkvRzgxWElsb1A0TitsQjZINFJteElwakhNYVArTjIyTzVnMUFaR04yc1d6VHA5T3JWMDIvOXhndXJBMjZ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NvbSNjaGFtc2VkZGluZS5iZW5oYW1lZEBlbnNpLXVtYS50biIsInV0aSI6IlBQWHZMNVFsQzBtaDBqdjdzWjRiQUEiLCJ2ZXIiOiIxLjAiLCJ4bXNfc3QiOnsic3ViIjoick52Y1lyTElyUjduYkgyT0JYaDhZM1NOcGRLT3N3X01DZF9xdzRfbzQ0SSJ9LCJ4bXNfdGNkdCI6MTU4MjgyMDM1Mn0.W_ccOGW_AGdg37KSMi7LWHtvm3Mw5p1dHjgDIrUaXduKF2iLS4dCaPw7yeo4VjAcOyV6C0h6ABLDCtkwVt8BSDTIIU7DaT8k2bRbMCCq69BmeiYPsbp-yX6ywGCx5DHsnOLqI2oHbBQktA2Nmv9Va651Pbm3OpSPuGPdVimkFCcnisiGlUOej1ZMNwyVT6386O2pERPtxmFUt_D1dKLxBXxBNxLVUG5BG3bI7wMpBOHEUA5CbaBzYXmGrLMXVVbrj9OsF-WQ6aNoqsm9cicX6pJB60lFz1dxLeSgcFO7Zh2K3PFe4FnXCqAvNPadQMz_kJEO9_phlDV85c2MPqeXbA",
26
+ token_type: "Bearer",
27
+ scope: "scopes"
28
+ });
29
+ this.settings = settings;
30
+ this.events = new Events();
31
+ }
32
+ getUser() {
33
+ return Promise.resolve(
34
+ JSON.parse(sessionStorage.getItem("powsybl-gridsuite-mock-user"))
35
+ );
36
+ }
37
+ signinSilent() {
38
+ console.info("signinSilent..............");
39
+ const localStorageUser = JSON.parse(
40
+ localStorage.getItem("powsybl-gridsuite-mock-user")
41
+ );
42
+ if (localStorageUser === null) {
43
+ return Promise.reject(
44
+ new Error("End-User authentication required")
45
+ );
46
+ }
47
+ sessionStorage.setItem(
48
+ "powsybl-gridsuite-mock-user",
49
+ JSON.stringify(localStorageUser)
50
+ );
51
+ this.events.userLoadedCallbacks.forEach((c) => c(localStorageUser));
52
+ return Promise.resolve(localStorageUser);
53
+ }
54
+ signinSilentCallback() {
55
+ console.error(
56
+ "Unsupported, iframe signinSilentCallback in UserManagerMock (dev mode)"
57
+ );
58
+ return Promise.reject();
59
+ }
60
+ signinRedirect() {
61
+ localStorage.setItem(
62
+ "powsybl-gridsuite-mock-user",
63
+ JSON.stringify(this.user)
64
+ );
65
+ window.location = "./sign-in-callback";
66
+ return Promise.resolve(null);
67
+ }
68
+ signoutRedirect() {
69
+ sessionStorage.removeItem("powsybl-gridsuite-mock-user");
70
+ localStorage.removeItem("powsybl-gridsuite-mock-user");
71
+ window.location = ".";
72
+ return Promise.resolve(null);
73
+ }
74
+ signinRedirectCallback() {
75
+ sessionStorage.setItem(
76
+ "powsybl-gridsuite-mock-user",
77
+ JSON.stringify(this.user)
78
+ );
79
+ this.events.userLoadedCallbacks.forEach((c) => c(this.user));
80
+ return Promise.resolve("");
81
+ }
82
+ }
83
+ export {
84
+ UserManagerMock
85
+ };
@@ -0,0 +1,71 @@
1
+ const USER = "USER";
2
+ function setLoggedUser(user) {
3
+ return { type: USER, user };
4
+ }
5
+ const SIGNIN_CALLBACK_ERROR = "SIGNIN_CALLBACK_ERROR";
6
+ function setSignInCallbackError(signInCallbackError) {
7
+ return {
8
+ type: SIGNIN_CALLBACK_ERROR,
9
+ signInCallbackError
10
+ };
11
+ }
12
+ const UNAUTHORIZED_USER_INFO = "UNAUTHORIZED_USER_INFO";
13
+ function setUnauthorizedUserInfo(userName, unauthorizedUserInfo) {
14
+ return {
15
+ type: UNAUTHORIZED_USER_INFO,
16
+ authenticationRouterError: {
17
+ userName,
18
+ unauthorizedUserInfo
19
+ }
20
+ };
21
+ }
22
+ const LOGOUT_ERROR = "LOGOUT_ERROR";
23
+ function setLogoutError(userName, logoutError) {
24
+ return {
25
+ type: LOGOUT_ERROR,
26
+ authenticationRouterError: {
27
+ userName,
28
+ logoutError
29
+ }
30
+ };
31
+ }
32
+ const USER_VALIDATION_ERROR = "USER_VALIDATION_ERROR";
33
+ function setUserValidationError(userName, userValidationError) {
34
+ return {
35
+ type: USER_VALIDATION_ERROR,
36
+ authenticationRouterError: {
37
+ userName,
38
+ userValidationError
39
+ }
40
+ };
41
+ }
42
+ const RESET_AUTHENTICATION_ROUTER_ERROR = "RESET_AUTHENTICATION_ROUTER_ERROR";
43
+ function resetAuthenticationRouterError() {
44
+ return {
45
+ type: RESET_AUTHENTICATION_ROUTER_ERROR,
46
+ authenticationRouterError: null
47
+ };
48
+ }
49
+ const SHOW_AUTH_INFO_LOGIN = "SHOW_AUTH_INFO_LOGIN";
50
+ function setShowAuthenticationRouterLogin(showAuthenticationRouterLogin) {
51
+ return {
52
+ type: SHOW_AUTH_INFO_LOGIN,
53
+ showAuthenticationRouterLogin
54
+ };
55
+ }
56
+ export {
57
+ LOGOUT_ERROR,
58
+ RESET_AUTHENTICATION_ROUTER_ERROR,
59
+ SHOW_AUTH_INFO_LOGIN,
60
+ SIGNIN_CALLBACK_ERROR,
61
+ UNAUTHORIZED_USER_INFO,
62
+ USER,
63
+ USER_VALIDATION_ERROR,
64
+ resetAuthenticationRouterError,
65
+ setLoggedUser,
66
+ setLogoutError,
67
+ setShowAuthenticationRouterLogin,
68
+ setSignInCallbackError,
69
+ setUnauthorizedUserInfo,
70
+ setUserValidationError
71
+ };
@@ -0,0 +1,24 @@
1
+ function equalsArray(a, b) {
2
+ if (b === a) {
3
+ return true;
4
+ }
5
+ if (!b || !a) {
6
+ return false;
7
+ }
8
+ if (a.length !== b.length) {
9
+ return false;
10
+ }
11
+ for (var i = 0, l = a.length; i < l; i++) {
12
+ if (a[i] instanceof Array && b[i] instanceof Array) {
13
+ if (!equalsArray(a[i], b[i])) {
14
+ return false;
15
+ }
16
+ } else if (a[i] !== b[i]) {
17
+ return false;
18
+ }
19
+ }
20
+ return true;
21
+ }
22
+ export {
23
+ equalsArray
24
+ };