@urbanos/react-discovery-ui 2.1.43

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 (316) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +118 -0
  3. package/lib/ReactDiscoveryUI.js +103 -0
  4. package/lib/ReactDiscoveryUI.scss +13 -0
  5. package/lib/assets/arrow.svg +6 -0
  6. package/lib/assets/blk-database.svg +48 -0
  7. package/lib/assets/chart.svg +1 -0
  8. package/lib/assets/down.png +0 -0
  9. package/lib/assets/down.svg +1 -0
  10. package/lib/assets/folder_icon.png +0 -0
  11. package/lib/assets/folder_icon.svg +1 -0
  12. package/lib/assets/ic_arrow.svg +15 -0
  13. package/lib/assets/loadingicon.svg +57 -0
  14. package/lib/assets/no_image.png +0 -0
  15. package/lib/assets/plus.png +0 -0
  16. package/lib/assets/plus.svg +1 -0
  17. package/lib/assets/user.svg +1 -0
  18. package/lib/auth/auth0-client-provider.js +37 -0
  19. package/lib/auth/auth0-client-provider.test.js +33 -0
  20. package/lib/auth/auth0-wrapper.js +155 -0
  21. package/lib/auth/auth0-wrapper.test.js +100 -0
  22. package/lib/components/auth0-login-zone/auth0-login-zone.js +147 -0
  23. package/lib/components/auth0-login-zone/auth0-login-zone.test.js +177 -0
  24. package/lib/components/auth0-login-zone/index.js +9 -0
  25. package/lib/components/code-editor/code-editor.css +173 -0
  26. package/lib/components/code-editor/code-editor.js +64 -0
  27. package/lib/components/code-editor/index.js +9 -0
  28. package/lib/components/collapsable-box/collapsable-box.js +81 -0
  29. package/lib/components/collapsable-box/collapsable-box.scss +39 -0
  30. package/lib/components/collapsable-box/collapsable-box.test.js +87 -0
  31. package/lib/components/collapsable-box/index.js +9 -0
  32. package/lib/components/data-card/data-card.js +63 -0
  33. package/lib/components/data-card/data-card.scss +93 -0
  34. package/lib/components/data-card/data-card.test.js +74 -0
  35. package/lib/components/data-card/index.js +9 -0
  36. package/lib/components/data-view/data-view.js +194 -0
  37. package/lib/components/data-view/data-view.scss +39 -0
  38. package/lib/components/data-view/data-view.test.js +155 -0
  39. package/lib/components/data-view/index.js +9 -0
  40. package/lib/components/dataset-api-doc/api-example.js +120 -0
  41. package/lib/components/dataset-api-doc/api-example.scss +84 -0
  42. package/lib/components/dataset-api-doc/api-example.test.js +88 -0
  43. package/lib/components/dataset-api-doc/dataset-api-doc.js +117 -0
  44. package/lib/components/dataset-api-doc/dataset-api-doc.scss +8 -0
  45. package/lib/components/dataset-api-doc/dataset-api-doc.test.js +42 -0
  46. package/lib/components/dataset-api-doc/index.js +9 -0
  47. package/lib/components/dataset-details/dataset-details.js +64 -0
  48. package/lib/components/dataset-details/dataset-details.scss +58 -0
  49. package/lib/components/dataset-details/dataset-details.test.js +38 -0
  50. package/lib/components/dataset-details/index.js +9 -0
  51. package/lib/components/dataset-dictionary/dataset-dictionary.js +127 -0
  52. package/lib/components/dataset-dictionary/dataset-dictionary.scss +42 -0
  53. package/lib/components/dataset-dictionary/dataset-dictionary.test.js +286 -0
  54. package/lib/components/dataset-dictionary/index.js +9 -0
  55. package/lib/components/dataset-list/dataset-list.js +22 -0
  56. package/lib/components/dataset-list/dataset-list.scss +9 -0
  57. package/lib/components/dataset-list/dataset-list.test.js +16 -0
  58. package/lib/components/dataset-list/index.js +9 -0
  59. package/lib/components/dataset-metadata/dataset-metadata.js +169 -0
  60. package/lib/components/dataset-metadata/dataset-metadata.scss +34 -0
  61. package/lib/components/dataset-metadata/dataset-metadata.test.js +24 -0
  62. package/lib/components/dataset-metadata/index.js +9 -0
  63. package/lib/components/dataset-preview/connector.js +26 -0
  64. package/lib/components/dataset-preview/dataset-preview.js +58 -0
  65. package/lib/components/dataset-preview/dataset-preview.scss +24 -0
  66. package/lib/components/dataset-preview/dataset-preview.test.js +34 -0
  67. package/lib/components/dataset-preview/index.js +9 -0
  68. package/lib/components/dataset-quality/dataset-quality.js +56 -0
  69. package/lib/components/dataset-quality/dataset-quality.scss +24 -0
  70. package/lib/components/dataset-quality/dataset-quality.test.js +34 -0
  71. package/lib/components/dataset-quality/index.js +9 -0
  72. package/lib/components/dataset-recommendations/connector.js +24 -0
  73. package/lib/components/dataset-recommendations/dataset-recommendations.js +47 -0
  74. package/lib/components/dataset-recommendations/dataset-recommendations.scss +17 -0
  75. package/lib/components/dataset-recommendations/dataset-recommendations.test.js +37 -0
  76. package/lib/components/dataset-recommendations/index.js +9 -0
  77. package/lib/components/detail-toggle-icon/detail-toggle-icon.js +41 -0
  78. package/lib/components/detail-toggle-icon/detail-toggle-icon.scss +13 -0
  79. package/lib/components/detail-toggle-icon/detail-toggle-icon.test.js +20 -0
  80. package/lib/components/detail-toggle-icon/index.js +9 -0
  81. package/lib/components/facet-list/facet-list.js +47 -0
  82. package/lib/components/facet-list/facet-list.scss +19 -0
  83. package/lib/components/facet-list/facet-list.test.js +94 -0
  84. package/lib/components/facet-list/index.js +9 -0
  85. package/lib/components/facet-sidebar/facet-sidebar.js +101 -0
  86. package/lib/components/facet-sidebar/facet-sidebar.scss +129 -0
  87. package/lib/components/facet-sidebar/facet-sidebar.test.js +93 -0
  88. package/lib/components/facet-sidebar/index.js +9 -0
  89. package/lib/components/generic-elements/alert-component/alert-component.js +51 -0
  90. package/lib/components/generic-elements/alert-component/alert-component.scss +26 -0
  91. package/lib/components/generic-elements/alert-component/alert-component.test.js +26 -0
  92. package/lib/components/generic-elements/alert-component/index.js +9 -0
  93. package/lib/components/generic-elements/arrow-button/arrow-button.js +30 -0
  94. package/lib/components/generic-elements/arrow-button/index.js +9 -0
  95. package/lib/components/generic-elements/auto-anchoring-popover/index.js +61 -0
  96. package/lib/components/generic-elements/back-button/back-button.js +14 -0
  97. package/lib/components/generic-elements/back-button/back-button.scss +14 -0
  98. package/lib/components/generic-elements/back-button/index.js +9 -0
  99. package/lib/components/generic-elements/call-to-action-button/call-to-action-button.js +118 -0
  100. package/lib/components/generic-elements/call-to-action-button/call-to-action-button.scss +19 -0
  101. package/lib/components/generic-elements/call-to-action-button/call-to-action-button.test.js +68 -0
  102. package/lib/components/generic-elements/call-to-action-button/index.js +9 -0
  103. package/lib/components/generic-elements/chart-icon/index.js +23 -0
  104. package/lib/components/generic-elements/checkbox/checkbox.js +50 -0
  105. package/lib/components/generic-elements/checkbox/checkbox.scss +44 -0
  106. package/lib/components/generic-elements/checkbox/checkbox.test.js +71 -0
  107. package/lib/components/generic-elements/checkbox/index.js +9 -0
  108. package/lib/components/generic-elements/error-component/error-component.js +21 -0
  109. package/lib/components/generic-elements/error-component/error-component.scss +16 -0
  110. package/lib/components/generic-elements/error-component/error-component.test.js +12 -0
  111. package/lib/components/generic-elements/error-component/index.js +9 -0
  112. package/lib/components/generic-elements/folder-icon/index.js +23 -0
  113. package/lib/components/generic-elements/generated-link/generated-link.js +25 -0
  114. package/lib/components/generic-elements/generated-link/index.js +13 -0
  115. package/lib/components/generic-elements/loading-element/index.js +9 -0
  116. package/lib/components/generic-elements/loading-element/loading-element.js +22 -0
  117. package/lib/components/generic-elements/loading-element/loading-element.scss +6 -0
  118. package/lib/components/generic-elements/loading-element/loading-element.test.js +11 -0
  119. package/lib/components/generic-elements/paginator/index.js +9 -0
  120. package/lib/components/generic-elements/paginator/paginator.js +84 -0
  121. package/lib/components/generic-elements/paginator/paginator.scss +38 -0
  122. package/lib/components/generic-elements/paginator/paginator.test.js +140 -0
  123. package/lib/components/generic-elements/plus-icon/index.js +21 -0
  124. package/lib/components/generic-elements/save-indicator/index.js +9 -0
  125. package/lib/components/generic-elements/save-indicator/save-indicator.js +39 -0
  126. package/lib/components/generic-elements/save-indicator/save-indicator.scss +31 -0
  127. package/lib/components/generic-elements/save-indicator/save-indicator.test.js +89 -0
  128. package/lib/components/generic-elements/search/index.js +9 -0
  129. package/lib/components/generic-elements/search/search.js +93 -0
  130. package/lib/components/generic-elements/search/search.scss +90 -0
  131. package/lib/components/generic-elements/search/search.test.js +41 -0
  132. package/lib/components/generic-elements/select/index.js +9 -0
  133. package/lib/components/generic-elements/select/select.js +44 -0
  134. package/lib/components/generic-elements/select/select.scss +22 -0
  135. package/lib/components/generic-elements/select/select.test.js +34 -0
  136. package/lib/components/generic-elements/share-link/index.js +9 -0
  137. package/lib/components/generic-elements/share-link/share-link.js +23 -0
  138. package/lib/components/generic-elements/share-link/share-link.scss +17 -0
  139. package/lib/components/generic-elements/share-link/share-link.test.js +28 -0
  140. package/lib/components/generic-elements/sql-icon/index.js +20 -0
  141. package/lib/components/generic-elements/tab-button/index.js +9 -0
  142. package/lib/components/generic-elements/tab-button/tab-button.js +25 -0
  143. package/lib/components/generic-elements/tab-button/tab-button.scss +27 -0
  144. package/lib/components/generic-elements/visualize-button/index.js +9 -0
  145. package/lib/components/generic-elements/visualize-button/visualize-button.js +37 -0
  146. package/lib/components/generic-elements/visualize-button/visualize-button.scss +14 -0
  147. package/lib/components/login-zone/connector.js +25 -0
  148. package/lib/components/login-zone/index.js +9 -0
  149. package/lib/components/login-zone/login-svgs-and-text.js +39 -0
  150. package/lib/components/login-zone/login-zone.js +21 -0
  151. package/lib/components/login-zone/login-zone.scss +115 -0
  152. package/lib/components/login-zone/login-zone.test.js +17 -0
  153. package/lib/components/login-zone/login.js +48 -0
  154. package/lib/components/login-zone/logout.js +39 -0
  155. package/lib/components/network-loading-element/connector.js +17 -0
  156. package/lib/components/network-loading-element/index.js +9 -0
  157. package/lib/components/network-loading-element/network-loading-element.js +23 -0
  158. package/lib/components/network-loading-element/network-loading-element.scss +21 -0
  159. package/lib/components/network-loading-element/network-loading-element.test.js +34 -0
  160. package/lib/components/organization/index.js +9 -0
  161. package/lib/components/organization/organization.js +27 -0
  162. package/lib/components/organization/organization.scss +32 -0
  163. package/lib/components/protected-route/protected-route.js +101 -0
  164. package/lib/components/protected-route/protected-route.scss +4 -0
  165. package/lib/components/protected-route/protected-route.test.js +63 -0
  166. package/lib/components/query-form/index.js +9 -0
  167. package/lib/components/query-form/query-form.js +262 -0
  168. package/lib/components/query-form/query-form.scss +167 -0
  169. package/lib/components/query-form/query-form.test.js +248 -0
  170. package/lib/components/recommendation-list/index.js +9 -0
  171. package/lib/components/recommendation-list/recommendation-list.js +72 -0
  172. package/lib/components/recommendation-list/recommendation-list.scss +61 -0
  173. package/lib/components/recommendation-list/recommendation-list.test.js +38 -0
  174. package/lib/components/remote-toggle/__snapshots__/remote-toggle.test.js.snap +3 -0
  175. package/lib/components/remote-toggle/index.js +13 -0
  176. package/lib/components/remote-toggle/remote-toggle.js +35 -0
  177. package/lib/components/remote-toggle/remote-toggle.scss +0 -0
  178. package/lib/components/remote-toggle/remote-toggle.test.js +10 -0
  179. package/lib/components/share/index.js +9 -0
  180. package/lib/components/share/share.js +109 -0
  181. package/lib/components/share/share.scss +66 -0
  182. package/lib/components/streaming-api-doc/index.js +9 -0
  183. package/lib/components/streaming-api-doc/streaming-api-doc.js +76 -0
  184. package/lib/components/streaming-api-doc/streaming-api-doc.scss +23 -0
  185. package/lib/components/streaming-api-doc/streaming-api-doc.test.js +24 -0
  186. package/lib/components/tooltip/index.js +9 -0
  187. package/lib/components/tooltip/tooltip.js +17 -0
  188. package/lib/components/tooltip/tooltip.scss +16 -0
  189. package/lib/components/tooltip/tooltip.test.js +19 -0
  190. package/lib/components/visualization-list-menu-item/index.js +9 -0
  191. package/lib/components/visualization-list-menu-item/visualization-list-menu-item.js +53 -0
  192. package/lib/components/visualization-list-menu-item/visualization-list-menu-item.scss +21 -0
  193. package/lib/components/visualization-list-menu-item/visualization-list-menu-item.test.js +42 -0
  194. package/lib/components/visualization-save-menu-item/index.js +9 -0
  195. package/lib/components/visualization-save-menu-item/visualization-save-menu-item.js +101 -0
  196. package/lib/components/visualization-save-menu-item/visualization-save-menu-item.scss +37 -0
  197. package/lib/components/visualization-save-menu-item/visualization-save-menu-item.test.js +185 -0
  198. package/lib/components/visualizations/geojson/connector.js +29 -0
  199. package/lib/components/visualizations/geojson/geojson-visualization.js +151 -0
  200. package/lib/components/visualizations/geojson/geojson-visualization.scss +24 -0
  201. package/lib/components/visualizations/geojson/geojson-visualization.test.js +238 -0
  202. package/lib/components/visualizations/geojson/index.js +9 -0
  203. package/lib/pages/apikey-view/apiKey-view.test.js +204 -0
  204. package/lib/pages/apikey-view/apikey-view.js +166 -0
  205. package/lib/pages/apikey-view/apikey-view.scss +340 -0
  206. package/lib/pages/apikey-view/connector.js +31 -0
  207. package/lib/pages/apikey-view/index.js +9 -0
  208. package/lib/pages/chart-view/chart-view.js +92 -0
  209. package/lib/pages/chart-view/chart-view.scss +35 -0
  210. package/lib/pages/chart-view/chart-view.test.js +206 -0
  211. package/lib/pages/chart-view/connector.js +30 -0
  212. package/lib/pages/chart-view/index.js +9 -0
  213. package/lib/pages/dataset-detail-view/connector.js +38 -0
  214. package/lib/pages/dataset-detail-view/dataset-detail-view-connector.test.js +42 -0
  215. package/lib/pages/dataset-detail-view/dataset-detail-view.js +99 -0
  216. package/lib/pages/dataset-detail-view/dataset-detail-view.scss +190 -0
  217. package/lib/pages/dataset-detail-view/dataset-detail-view.test.js +305 -0
  218. package/lib/pages/dataset-detail-view/index.js +9 -0
  219. package/lib/pages/dataset-list-view/connector.js +30 -0
  220. package/lib/pages/dataset-list-view/dataset-list-view.js +132 -0
  221. package/lib/pages/dataset-list-view/dataset-list-view.scss +242 -0
  222. package/lib/pages/dataset-list-view/dataset-list-view.test.js +162 -0
  223. package/lib/pages/dataset-list-view/index.js +9 -0
  224. package/lib/pages/dataset-view/connector.js +55 -0
  225. package/lib/pages/dataset-view/dataset-view-connector.test.js +78 -0
  226. package/lib/pages/dataset-view/dataset-view.js +175 -0
  227. package/lib/pages/dataset-view/dataset-view.scss +95 -0
  228. package/lib/pages/dataset-view/dataset-view.test.js +157 -0
  229. package/lib/pages/dataset-view/index.js +9 -0
  230. package/lib/pages/login-view/connector.js +25 -0
  231. package/lib/pages/login-view/index.js +9 -0
  232. package/lib/pages/login-view/login-view.js +83 -0
  233. package/lib/pages/login-view/login-view.scss +62 -0
  234. package/lib/pages/login-view/login-view.test.js +23 -0
  235. package/lib/pages/oauth-error-view/index.js +9 -0
  236. package/lib/pages/oauth-error-view/oauth-error-view.js +25 -0
  237. package/lib/pages/oauth-error-view/oauth-error-view.scss +13 -0
  238. package/lib/pages/oauth-error-view/oauth-error-view.test.js +13 -0
  239. package/lib/pages/oauth-view/connector.js +22 -0
  240. package/lib/pages/oauth-view/index.js +9 -0
  241. package/lib/pages/oauth-view/oauth-view.js +124 -0
  242. package/lib/pages/oauth-view/oauth-view.scss +7 -0
  243. package/lib/pages/oauth-view/oauth-view.test.js +195 -0
  244. package/lib/pages/query-view/connector.js +40 -0
  245. package/lib/pages/query-view/index.js +9 -0
  246. package/lib/pages/query-view/query-view.js +80 -0
  247. package/lib/pages/query-view/query-view.scss +39 -0
  248. package/lib/pages/query-view/query-view.test.js +104 -0
  249. package/lib/pages/user-profile-view/connector.js +39 -0
  250. package/lib/pages/user-profile-view/index.js +9 -0
  251. package/lib/pages/user-profile-view/user-profile-view.js +154 -0
  252. package/lib/pages/user-profile-view/user-profile-view.scss +81 -0
  253. package/lib/pages/user-profile-view/user-profile-view.test.js +129 -0
  254. package/lib/pages/visualization-view/connector.js +52 -0
  255. package/lib/pages/visualization-view/index.js +9 -0
  256. package/lib/pages/visualization-view/visualization-view-connector.test.js +62 -0
  257. package/lib/pages/visualization-view/visualization-view.js +128 -0
  258. package/lib/pages/visualization-view/visualization-view.scss +115 -0
  259. package/lib/pages/visualization-view/visualization-view.test.js +188 -0
  260. package/lib/routes.js +18 -0
  261. package/lib/search-params/search-params-manager.js +171 -0
  262. package/lib/search-params/search-params-manager.test.js +490 -0
  263. package/lib/store/actions.js +428 -0
  264. package/lib/store/dataset-selectors.js +47 -0
  265. package/lib/store/dataset-selectors.test.js +154 -0
  266. package/lib/store/query-selectors.js +53 -0
  267. package/lib/store/query-selectors.test.js +153 -0
  268. package/lib/store/reducers/index.js +20 -0
  269. package/lib/store/reducers/query-reducer.js +52 -0
  270. package/lib/store/reducers/query-reducer.test.js +89 -0
  271. package/lib/store/reducers/reducers.js +196 -0
  272. package/lib/store/reducers/reducers.test.js +309 -0
  273. package/lib/store/reducers/visualization-reducer.js +167 -0
  274. package/lib/store/reducers/visualization-reducer.test.js +426 -0
  275. package/lib/store/sagas/api-invoker.js +79 -0
  276. package/lib/store/sagas/api-invoker.test.js +139 -0
  277. package/lib/store/sagas/apiKey-saga.js +81 -0
  278. package/lib/store/sagas/apiKey-saga.test.js +57 -0
  279. package/lib/store/sagas/dataset-download-saga.js +43 -0
  280. package/lib/store/sagas/dataset-list-saga.js +49 -0
  281. package/lib/store/sagas/dataset-list-saga.test.js +72 -0
  282. package/lib/store/sagas/dataset-preview-saga.js +44 -0
  283. package/lib/store/sagas/dataset-query-saga.js +43 -0
  284. package/lib/store/sagas/dataset-recommendation-saga.js +40 -0
  285. package/lib/store/sagas/dataset-saga.js +50 -0
  286. package/lib/store/sagas/freestyle-query-saga.js +127 -0
  287. package/lib/store/sagas/freestyle-query-saga.test.js +145 -0
  288. package/lib/store/sagas/index.js +44 -0
  289. package/lib/store/sagas/login-saga.js +85 -0
  290. package/lib/store/sagas/login-saga.test.js +84 -0
  291. package/lib/store/sagas/logout-saga.js +96 -0
  292. package/lib/store/sagas/oauth-saga.js +78 -0
  293. package/lib/store/sagas/oauth-saga.test.js +51 -0
  294. package/lib/store/sagas/process-login-saga.js +62 -0
  295. package/lib/store/sagas/process-login-saga.test.js +83 -0
  296. package/lib/store/sagas/visualization-saga.js +371 -0
  297. package/lib/store/sagas/visualization-saga.test.js +388 -0
  298. package/lib/store/selectors.js +83 -0
  299. package/lib/store/visualization-selectors.js +85 -0
  300. package/lib/store/visualization-selectors.test.js +195 -0
  301. package/lib/styles/mixins.scss +117 -0
  302. package/lib/styles/variables.scss +41 -0
  303. package/lib/utils/file-type-utils.js +18 -0
  304. package/lib/utils/file-type-utils.test.js +29 -0
  305. package/lib/utils/geojson-utils.js +70 -0
  306. package/lib/utils/geojson-utils.test.js +129 -0
  307. package/lib/utils/http-clients.js +218 -0
  308. package/lib/utils/http-clients.test.js +88 -0
  309. package/lib/utils/index.js +34 -0
  310. package/lib/utils/modified-date-string-builder.js +29 -0
  311. package/lib/utils/modified-date-string-builder.test.js +93 -0
  312. package/lib/utils/query-string-builder.js +38 -0
  313. package/lib/utils/query-string-builder.test.js +33 -0
  314. package/lib/utils/recommendation-utils.js +12 -0
  315. package/lib/utils/recommendation-utils.test.js +9 -0
  316. package/package.json +172 -0
@@ -0,0 +1,33 @@
1
+ import { default as createAuth0Client } from '@auth0/auth0-spa-js'
2
+ import auth0ClientProvider from './auth0-client-provider'
3
+
4
+ jest.mock('@auth0/auth0-spa-js')
5
+
6
+ describe('auth0-client-provider', () => {
7
+ let client
8
+
9
+ beforeEach(async () => {
10
+ createAuth0Client
11
+ .mockReturnValueOnce(Promise.resolve('first-instance'))
12
+ .mockReturnValue(Promise.resolve('another-instance'))
13
+
14
+ client = await auth0ClientProvider.get()
15
+ })
16
+
17
+ it('initializes with the correct domain and client ID', () => {
18
+ expect(createAuth0Client).toBeCalledWith({
19
+ domain: window.AUTH0_DOMAIN,
20
+ client_id: window.DISCOVERY_AUTH0_CLIENT_ID,
21
+ audience: window.AUTH0_AUDIENCE,
22
+ redirect_uri: `${window.location.origin}/oauth`
23
+ })
24
+ })
25
+
26
+ describe('retrieving again', () => {
27
+ it('gets the same instance', async () => {
28
+ const client2 = await auth0ClientProvider.get()
29
+
30
+ expect(client2).toBe(client)
31
+ })
32
+ })
33
+ })
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _react = require("react");
9
+ var _auth0ClientProvider = _interopRequireDefault(require("../auth/auth0-client-provider"));
10
+ var _httpClients = require("../utils/http-clients");
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
13
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
14
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
15
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
16
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
17
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
18
+ function _regeneratorRuntime() { "use strict"; var r = _regenerator(), e = r.m(_regeneratorRuntime), t = (Object.getPrototypeOf ? Object.getPrototypeOf(e) : e.__proto__).constructor; function n(r) { var e = "function" == typeof r && r.constructor; return !!e && (e === t || "GeneratorFunction" === (e.displayName || e.name)); } var o = { throw: 1, return: 2, break: 3, continue: 3 }; function a(r) { var e, t; return function (n) { e || (e = { stop: function stop() { return t(n.a, 2); }, catch: function _catch() { return n.v; }, abrupt: function abrupt(r, e) { return t(n.a, o[r], e); }, delegateYield: function delegateYield(r, o, a) { return e.resultName = o, t(n.d, _regeneratorValues(r), a); }, finish: function finish(r) { return t(n.f, r); } }, t = function t(r, _t, o) { n.p = e.prev, n.n = e.next; try { return r(_t, o); } finally { e.next = n.n; } }), e.resultName && (e[e.resultName] = n.v, e.resultName = void 0), e.sent = n.v, e.next = n.n; try { return r.call(this, e); } finally { n.p = e.prev, n.n = e.next; } }; } return (_regeneratorRuntime = function _regeneratorRuntime() { return { wrap: function wrap(e, t, n, o) { return r.w(a(e), t, n, o && o.reverse()); }, isGeneratorFunction: n, mark: r.m, awrap: function awrap(r, e) { return new _OverloadYield(r, e); }, AsyncIterator: _regeneratorAsyncIterator, async: function async(r, e, t, o, u) { return (n(e) ? _regeneratorAsyncGen : _regeneratorAsync)(a(r), e, t, o, u); }, keys: _regeneratorKeys, values: _regeneratorValues }; })(); }
19
+ function _regeneratorValues(e) { if (null != e) { var t = e["function" == typeof Symbol && Symbol.iterator || "@@iterator"], r = 0; if (t) return t.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) return { next: function next() { return e && r >= e.length && (e = void 0), { value: e && e[r++], done: !e }; } }; } throw new TypeError(_typeof(e) + " is not iterable"); }
20
+ function _regeneratorKeys(e) { var n = Object(e), r = []; for (var t in n) r.unshift(t); return function e() { for (; r.length;) if ((t = r.pop()) in n) return e.value = t, e.done = !1, e; return e.done = !0, e; }; }
21
+ function _regeneratorAsync(n, e, r, t, o) { var a = _regeneratorAsyncGen(n, e, r, t, o); return a.next().then(function (n) { return n.done ? n.value : a.next(); }); }
22
+ function _regeneratorAsyncGen(r, e, t, o, n) { return new _regeneratorAsyncIterator(_regenerator().w(r, e, t, o), n || Promise); }
23
+ function _regeneratorAsyncIterator(t, e) { function n(r, o, i, f) { try { var c = t[r](o), u = c.value; return u instanceof _OverloadYield ? e.resolve(u.v).then(function (t) { n("next", t, i, f); }, function (t) { n("throw", t, i, f); }) : e.resolve(u).then(function (t) { c.value = t, i(c); }, function (t) { return n("throw", t, i, f); }); } catch (t) { f(t); } } var r; this.next || (_regeneratorDefine2(_regeneratorAsyncIterator.prototype), _regeneratorDefine2(_regeneratorAsyncIterator.prototype, "function" == typeof Symbol && Symbol.asyncIterator || "@asyncIterator", function () { return this; })), _regeneratorDefine2(this, "_invoke", function (t, o, i) { function f() { return new e(function (e, r) { n(t, i, e, r); }); } return r = r ? r.then(f, f) : f(); }, !0); }
24
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
25
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
26
+ function _OverloadYield(e, d) { this.v = e, this.k = d; }
27
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
28
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
29
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
30
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
31
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
32
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
33
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
34
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
35
+ var withAuth0 = function withAuth0(WrappedComponent) {
36
+ var Auth0Wrapper = function Auth0Wrapper(props) {
37
+ var _useState = (0, _react.useState)(),
38
+ _useState2 = _slicedToArray(_useState, 2),
39
+ isAuthenticated = _useState2[0],
40
+ setAuthenticated = _useState2[1];
41
+ var _useState3 = (0, _react.useState)(),
42
+ _useState4 = _slicedToArray(_useState3, 2),
43
+ isLoading = _useState4[0],
44
+ setLoading = _useState4[1];
45
+ var _useState5 = (0, _react.useState)(),
46
+ _useState6 = _slicedToArray(_useState5, 2),
47
+ auth0Client = _useState6[0],
48
+ setAuth0Client = _useState6[1];
49
+ var callbackState = {
50
+ path: window.location.pathname,
51
+ search: window.location.search
52
+ };
53
+ (0, _react.useEffect)(function () {
54
+ var connectAuth0 = /*#__PURE__*/function () {
55
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
56
+ var client, authenticated;
57
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
58
+ while (1) switch (_context.prev = _context.next) {
59
+ case 0:
60
+ setLoading(true);
61
+ _context.next = 3;
62
+ return _auth0ClientProvider.default.get();
63
+ case 3:
64
+ client = _context.sent;
65
+ setAuth0Client(client);
66
+ _context.next = 7;
67
+ return client.isAuthenticated();
68
+ case 7:
69
+ authenticated = _context.sent;
70
+ setAuthenticated(authenticated);
71
+ setLoading(false);
72
+ case 10:
73
+ case "end":
74
+ return _context.stop();
75
+ }
76
+ }, _callee);
77
+ }));
78
+ return function connectAuth0() {
79
+ return _ref.apply(this, arguments);
80
+ };
81
+ }();
82
+ connectAuth0();
83
+ }, []);
84
+ var handleRedirectCallback = /*#__PURE__*/function () {
85
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
86
+ var client, callbackReturn;
87
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
88
+ while (1) switch (_context2.prev = _context2.next) {
89
+ case 0:
90
+ setLoading(true);
91
+ _context2.next = 3;
92
+ return _auth0ClientProvider.default.get();
93
+ case 3:
94
+ client = _context2.sent;
95
+ _context2.next = 6;
96
+ return client.handleRedirectCallback();
97
+ case 6:
98
+ callbackReturn = _context2.sent;
99
+ setAuthenticated(true);
100
+ setLoading(false);
101
+ return _context2.abrupt("return", callbackReturn);
102
+ case 10:
103
+ case "end":
104
+ return _context2.stop();
105
+ }
106
+ }, _callee2);
107
+ }));
108
+ return function handleRedirectCallback() {
109
+ return _ref2.apply(this, arguments);
110
+ };
111
+ }();
112
+ var logout = /*#__PURE__*/function () {
113
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
114
+ var loggedOutReturn,
115
+ _args3 = arguments;
116
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
117
+ while (1) switch (_context3.prev = _context3.next) {
118
+ case 0:
119
+ _context3.next = 2;
120
+ return _httpClients.AuthenticatedHTTPClient.post('/api/v1/logged-out', '');
121
+ case 2:
122
+ loggedOutReturn = _context3.sent;
123
+ auth0Client.logout.apply(auth0Client, _args3);
124
+ return _context3.abrupt("return", loggedOutReturn);
125
+ case 5:
126
+ case "end":
127
+ return _context3.stop();
128
+ }
129
+ }, _callee3);
130
+ }));
131
+ return function logout() {
132
+ return _ref3.apply(this, arguments);
133
+ };
134
+ }();
135
+ var auth0Props = {
136
+ loginWithRedirect: function loginWithRedirect() {
137
+ for (var _len = arguments.length, p = new Array(_len), _key = 0; _key < _len; _key++) {
138
+ p[_key] = arguments[_key];
139
+ }
140
+ return auth0Client.loginWithRedirect(_objectSpread({
141
+ appState: callbackState
142
+ }, p));
143
+ },
144
+ logout: logout,
145
+ handleRedirectCallback: handleRedirectCallback,
146
+ isAuthenticated: isAuthenticated,
147
+ isLoading: isLoading
148
+ };
149
+ return /*#__PURE__*/React.createElement(WrappedComponent, _extends({
150
+ auth: auth0Props
151
+ }, props));
152
+ };
153
+ return Auth0Wrapper;
154
+ };
155
+ var _default = exports.default = withAuth0;
@@ -0,0 +1,100 @@
1
+ import { mount } from 'enzyme'
2
+ import { default as createAuth0Client } from '@auth0/auth0-spa-js'
3
+ import withAuth0 from './auth0-wrapper'
4
+ import { AuthenticatedHTTPClient } from '../utils/http-clients'
5
+
6
+ jest.mock('@auth0/auth0-spa-js')
7
+ jest.mock('axios')
8
+
9
+ const Wrapped = () => <div />
10
+
11
+ describe('Auth0 wrapper component', () => {
12
+ let subject, Auth0Wrapper
13
+ let loginWithRedirect, logout
14
+
15
+ beforeEach(() => {
16
+ createAuth0Client.mockImplementation(() => {
17
+ loginWithRedirect = jest.fn()
18
+ logout = jest.fn()
19
+
20
+ return Promise.resolve({
21
+ isAuthenticated: jest.fn(() => Promise.resolve(false)),
22
+ handleRedirectCallback: jest.fn(() => Promise.resolve({})),
23
+ loginWithRedirect,
24
+ logout
25
+ })
26
+ })
27
+
28
+ Auth0Wrapper = withAuth0(Wrapped)
29
+ subject = mount(<Auth0Wrapper />)
30
+ })
31
+
32
+ it('initializes the client with the correct values', () => {
33
+ expect(createAuth0Client).toBeCalledWith({
34
+ domain: window.AUTH0_DOMAIN,
35
+ client_id: window.DISCOVERY_AUTH0_CLIENT_ID,
36
+ audience: window.AUTH0_AUDIENCE,
37
+ redirect_uri: `${window.location.origin}/oauth`
38
+ })
39
+ })
40
+
41
+ it('passes a loading flag', () => {
42
+ const wrapped = subject.find(Wrapped)
43
+ expect(wrapped.props().auth.isLoading).not.toBeUndefined()
44
+ })
45
+
46
+ it('eventually passes the authenticated flag to the wrapped component', done => {
47
+ setTimeout(() => {
48
+ subject.update()
49
+ const wrapped = subject.find(Wrapped)
50
+ expect(wrapped.props().auth.isAuthenticated).toBe(false)
51
+ done()
52
+ })
53
+ })
54
+
55
+ describe('provided handleRedirectCallback', () => {
56
+ it('sets authenticated to true when called', done => {
57
+ let wrapped = subject.find(Wrapped)
58
+
59
+ wrapped.props().auth.handleRedirectCallback()
60
+
61
+ setTimeout(() => {
62
+ subject.update()
63
+ wrapped = subject.find(Wrapped)
64
+ expect(wrapped.props().auth.isAuthenticated).toBe(true)
65
+ done()
66
+ })
67
+ })
68
+ })
69
+
70
+ describe('provided logout', () => {
71
+ const returnTo = 'http://example.com'
72
+
73
+ beforeEach(() => {
74
+ AuthenticatedHTTPClient.post = jest.fn()
75
+ AuthenticatedHTTPClient.post.mockImplementationOnce(async () => ({
76
+ status: 200,
77
+ data: 'OK'
78
+ }))
79
+
80
+ subject.update()
81
+ const wrapped = subject.find(Wrapped)
82
+
83
+ wrapped.props().auth.logout({ returnTo })
84
+ })
85
+
86
+ it('calls auth0 logout', done => {
87
+ setTimeout(() => {
88
+ expect(logout).toHaveBeenCalledWith({ returnTo })
89
+ done()
90
+ })
91
+ })
92
+
93
+ it('calls logged-out endpoint on the API', done => {
94
+ setTimeout(() => {
95
+ expect(AuthenticatedHTTPClient.post).toHaveBeenCalledWith('/api/v1/logged-out', '')
96
+ done()
97
+ })
98
+ })
99
+ })
100
+ })
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.Auth0LoginZone = void 0;
7
+ var _propTypes = _interopRequireDefault(require("prop-types"));
8
+ require("../login-zone/login-zone.scss");
9
+ var _loginSvgsAndText = _interopRequireDefault(require("../login-zone/login-svgs-and-text"));
10
+ var _routes = _interopRequireDefault(require("../../routes"));
11
+ var _auth0Wrapper = _interopRequireDefault(require("../../auth/auth0-wrapper"));
12
+ var _loadingElement = _interopRequireDefault(require("../generic-elements/loading-element"));
13
+ var _react = require("react");
14
+ var _reactRouterDom = require("react-router-dom");
15
+ var _folderIcon = _interopRequireDefault(require("../generic-elements/folder-icon"));
16
+ var _ExitToApp = _interopRequireDefault(require("@material-ui/icons/ExitToApp"));
17
+ var _Backup = _interopRequireDefault(require("@material-ui/icons/Backup"));
18
+ var _VpnKey = _interopRequireDefault(require("@material-ui/icons/VpnKey"));
19
+ var _reactDeviceDetect = require("react-device-detect");
20
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
21
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
22
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
23
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
24
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
25
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
26
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
27
+ var returnTo = "".concat(window.location.origin).concat(_routes.default.oauth);
28
+ var Auth0LoginZone = exports.Auth0LoginZone = function Auth0LoginZone(_ref) {
29
+ var _ref$auth = _ref.auth,
30
+ isAuthenticated = _ref$auth.isAuthenticated,
31
+ isLoading = _ref$auth.isLoading,
32
+ loginWithRedirect = _ref$auth.loginWithRedirect,
33
+ logout = _ref$auth.logout;
34
+ var _useState = (0, _react.useState)(false),
35
+ _useState2 = _slicedToArray(_useState, 2),
36
+ isMenuToggled = _useState2[0],
37
+ setMenuToggled = _useState2[1];
38
+ var _useState3 = (0, _react.useState)(false),
39
+ _useState4 = _slicedToArray(_useState3, 2),
40
+ isMouseInMenu = _useState4[0],
41
+ setMouseInMenu = _useState4[1];
42
+ var wrapperRef = (0, _react.useRef)(null);
43
+ var mouseEnterMenu = function mouseEnterMenu() {
44
+ if (!_reactDeviceDetect.isMobile) {
45
+ setMouseInMenu(true);
46
+ }
47
+ };
48
+ var mouseExitMenu = function mouseExitMenu() {
49
+ if (!_reactDeviceDetect.isMobile) {
50
+ setMouseInMenu(false);
51
+ }
52
+ };
53
+ var toggleMenu = function toggleMenu() {
54
+ setMenuToggled(!isMenuToggled);
55
+ };
56
+ var clickOutMenu = function clickOutMenu() {
57
+ if (_reactDeviceDetect.isMobile) {
58
+ setMenuToggled(false);
59
+ }
60
+ };
61
+ var isMenuExpanded = isMenuToggled || isMouseInMenu;
62
+ var regenerateApiKeyFF = window.REGENERATE_API_KEY_FF;
63
+ useClickOutWatcher(wrapperRef, clickOutMenu);
64
+ if (isLoading) {
65
+ return /*#__PURE__*/React.createElement("login-zone", null, /*#__PURE__*/React.createElement(_loadingElement.default, null));
66
+ }
67
+ return /*#__PURE__*/React.createElement("login-zone", null, /*#__PURE__*/React.createElement("div", {
68
+ ref: wrapperRef
69
+ }, /*#__PURE__*/React.createElement("div", {
70
+ className: "login-block"
71
+ }, isAuthenticated ? /*#__PURE__*/React.createElement("button", {
72
+ className: isMenuExpanded ? 'action' : 'status',
73
+ onClick: toggleMenu,
74
+ onMouseEnter: mouseEnterMenu,
75
+ onMouseLeave: mouseExitMenu
76
+ }, /*#__PURE__*/React.createElement(_loginSvgsAndText.default, {
77
+ text: "My Account",
78
+ symbol: isMenuExpanded ? '▴' : '▾'
79
+ })) : /*#__PURE__*/React.createElement("button", {
80
+ className: "action clickable",
81
+ "data-testid": "login-button",
82
+ onClick: loginWithRedirect
83
+ }, /*#__PURE__*/React.createElement(_loginSvgsAndText.default, {
84
+ text: "Log in to your account",
85
+ symbol: "\u25B8"
86
+ }))), isAuthenticated && isMenuExpanded && /*#__PURE__*/React.createElement("div", {
87
+ className: "user-menu",
88
+ onMouseEnter: mouseEnterMenu,
89
+ onMouseLeave: mouseExitMenu
90
+ }, /*#__PURE__*/React.createElement("ul", null, /*#__PURE__*/React.createElement("li", {
91
+ className: "menu-item"
92
+ }, /*#__PURE__*/React.createElement(_folderIcon.default, null), /*#__PURE__*/React.createElement("span", {
93
+ className: "menu-text"
94
+ }, /*#__PURE__*/React.createElement(_reactRouterDom.Link, {
95
+ to: "/user",
96
+ rel: "noopener noreferrer"
97
+ }, "Workspaces"))), regenerateApiKeyFF === 'true' && /*#__PURE__*/React.createElement("li", {
98
+ className: "menu-item"
99
+ }, /*#__PURE__*/React.createElement(_VpnKey.default, null), /*#__PURE__*/React.createElement("span", {
100
+ className: "menu-text"
101
+ }, /*#__PURE__*/React.createElement(_reactRouterDom.Link, {
102
+ to: "/apiKey",
103
+ rel: "noopener noreferrer"
104
+ }, "API Key"))), window.CONTRIBUTE_HOST && /*#__PURE__*/React.createElement("li", {
105
+ className: "menu-item"
106
+ }, /*#__PURE__*/React.createElement(_Backup.default, null), /*#__PURE__*/React.createElement("span", {
107
+ className: "menu-text"
108
+ }, /*#__PURE__*/React.createElement("a", {
109
+ role: "link",
110
+ href: window.CONTRIBUTE_HOST
111
+ }, "My Datasets"))), /*#__PURE__*/React.createElement("li", {
112
+ className: "menu-item",
113
+ id: "logout-button",
114
+ onClick: function onClick() {
115
+ logout({
116
+ returnTo: returnTo
117
+ });
118
+ }
119
+ }, /*#__PURE__*/React.createElement(_ExitToApp.default, null), /*#__PURE__*/React.createElement("span", {
120
+ className: "menu-text"
121
+ }, /*#__PURE__*/React.createElement("a", {
122
+ role: "link",
123
+ href: "#"
124
+ }, "Log Out")))))));
125
+ };
126
+ function useClickOutWatcher(ref, callback) {
127
+ (0, _react.useEffect)(function () {
128
+ function handleClickOutside(event) {
129
+ if (ref.current && !ref.current.contains(event.target)) {
130
+ callback();
131
+ }
132
+ }
133
+ document.addEventListener('mousedown', handleClickOutside);
134
+ return function () {
135
+ document.removeEventListener('mousedown', handleClickOutside);
136
+ };
137
+ }, [ref]);
138
+ }
139
+ Auth0LoginZone.propTypes = {
140
+ auth: _propTypes.default.shape({
141
+ loginWithRedirect: _propTypes.default.func.isRequired,
142
+ logout: _propTypes.default.func.isRequired,
143
+ isAuthenticated: _propTypes.default.bool,
144
+ isLoading: _propTypes.default.bool
145
+ }).isRequired
146
+ };
147
+ var _default = exports.default = (0, _auth0Wrapper.default)(Auth0LoginZone);
@@ -0,0 +1,177 @@
1
+ import { mount } from 'enzyme'
2
+ import { Auth0LoginZone as Component } from './auth0-login-zone'
3
+ import LoadingElement from '../generic-elements/loading-element'
4
+ import { BrowserRouter as Router } from 'react-router-dom'
5
+ import * as device from 'react-device-detect'
6
+
7
+ describe('OauthLoginZone component', () => {
8
+ let subject, button, loginHandler, logoutHandler
9
+
10
+ beforeEach(() => {
11
+ loginHandler = jest.fn()
12
+ logoutHandler = jest.fn()
13
+ })
14
+
15
+ describe('unauthenticated', () => {
16
+ beforeEach(() => {
17
+ subject = createSubject({ isAuthenticated: false, loginWithRedirect: loginHandler, logout: logoutHandler })
18
+ button = subject.find('button')
19
+ })
20
+
21
+ it('has a login button', () => {
22
+ expect(button.length).toBe(1)
23
+ expect(button.text()).toMatch('Log in to your account')
24
+ })
25
+
26
+ it('logs in with redirect when the button is clicked', () => {
27
+ button.simulate('click')
28
+
29
+ expect(loginHandler).toHaveBeenCalled()
30
+ })
31
+
32
+ it('does not have a loading element', () => {
33
+ expect(subject.find(LoadingElement).length).toBe(0)
34
+ })
35
+ })
36
+
37
+ describe('authenticated', () => {
38
+ beforeEach(() => {
39
+ device.isMobile = false
40
+ subject = createSubject({ isAuthenticated: true, loginWithRedirect: loginHandler, logout: logoutHandler })
41
+ button = subject.find('button')
42
+ })
43
+
44
+ it('has an account dropdown', () => {
45
+ expect(button.length).toBe(1)
46
+ expect(button.text()).toMatch('My Account')
47
+ })
48
+
49
+ it('displays account dropdown on mouse enter', () => {
50
+ button.simulate('mouseEnter')
51
+ const menuItems = subject.find('li')
52
+ expect(menuItems.length).not.toBe(0)
53
+ })
54
+
55
+ describe('account menu', () => {
56
+ beforeEach(() => {
57
+ button.simulate('mouseEnter')
58
+ })
59
+
60
+ it('has the expected menu items', () => {
61
+ window.REGENERATE_API_KEY_FF = 'true'
62
+ subject = createSubject({ isAuthenticated: true, loginWithRedirect: loginHandler, logout: logoutHandler })
63
+ button = subject.find('button')
64
+ button.simulate('mouseEnter')
65
+ const menuItems = subject.find('li')
66
+ expect(menuItems.length).toBe(3)
67
+ expect(menuItems.at(0).text()).toMatch('Workspaces')
68
+ expect(menuItems.at(1).text()).toMatch('API Key')
69
+ expect(menuItems.at(2).text()).toMatch('Log Out')
70
+ })
71
+
72
+ it('does not contain API Key when FF is not active', () => {
73
+ window.REGENERATE_API_KEY_FF = 'false'
74
+ subject = createSubject({ isAuthenticated: true, loginWithRedirect: loginHandler, logout: logoutHandler })
75
+ button = subject.find('button')
76
+ button.simulate('mouseEnter')
77
+ const menuItems = subject.find('li')
78
+ expect(menuItems.length).toBe(2)
79
+ expect(menuItems.at(0).text()).toMatch('Workspaces')
80
+ expect(menuItems.at(1).text()).toMatch('Log Out')
81
+ })
82
+
83
+ it('logs out with the correct "returnTo" URL when the button is clicked', () => {
84
+ const logOut = subject.find('#logout-button')
85
+ logOut.simulate('click')
86
+
87
+ expect(logoutHandler).toHaveBeenCalledWith({ returnTo: `${window.location.origin}/oauth` })
88
+ })
89
+
90
+ it('has a link to the workspaces page', () => {
91
+ const link = subject.find('a')
92
+ expect(link.at(0).props().href).toMatch('/user')
93
+ })
94
+
95
+ it('has a link to the apikey page', () => {
96
+ window.REGENERATE_API_KEY_FF = 'true'
97
+ subject = createSubject({ isAuthenticated: true, loginWithRedirect: loginHandler, logout: logoutHandler })
98
+ button = subject.find('button')
99
+ button.simulate('mouseEnter')
100
+ const link = subject.find('a')
101
+ expect(link.at(1).props().href).toMatch('/apiKey')
102
+ })
103
+
104
+ it('does not have a loading element', () => {
105
+ expect(subject.find(LoadingElement).length).toBe(0)
106
+ })
107
+
108
+ it('closes on mouse exit', () => {
109
+ button.simulate('mouseLeave')
110
+ const menuItems = subject.find('li')
111
+ expect(menuItems.length).toBe(0)
112
+ })
113
+ })
114
+
115
+ describe('account menu on mobile', () => {
116
+ beforeEach(() => {
117
+ device.isMobile = true
118
+ subject = createSubject({ isAuthenticated: true, loginWithRedirect: loginHandler, logout: logoutHandler })
119
+ button = subject.find('button')
120
+ })
121
+
122
+ it('toggles account dropdown on mouse click', () => {
123
+ button.simulate('click')
124
+ let menuItems = subject.find('li')
125
+ expect(menuItems.length).not.toBe(0)
126
+
127
+ button.simulate('click')
128
+ menuItems = subject.find('li')
129
+ expect(menuItems.length).toBe(0)
130
+ })
131
+
132
+ it('does not display account dropdown on mouse enter', () => {
133
+ button.simulate('mouseEnter')
134
+ const menuItems = subject.find('li')
135
+ expect(menuItems.length).toBe(0)
136
+ })
137
+ })
138
+ })
139
+
140
+ describe('loading', () => {
141
+ beforeEach(() => {
142
+ subject = createSubject({ isLoading: true })
143
+ })
144
+
145
+ it('has a loading element', () => {
146
+ expect(subject.find(LoadingElement).length).toBe(1)
147
+ })
148
+
149
+ it('does not have a button', () => {
150
+ expect(subject.find('button').length).toBe(0)
151
+ })
152
+ })
153
+ })
154
+
155
+ const createSubject = (authProps = {}) => {
156
+ const defaultAuthProps = {
157
+ isAuthenticated: false,
158
+ isLoading: false,
159
+ loginWithRedirect: jest.fn(),
160
+ logout: jest.fn()
161
+ }
162
+
163
+ const auth0PropsWithDefaults = Object.assign({}, defaultAuthProps, authProps)
164
+
165
+ return mount(
166
+ <Router>
167
+ <Component
168
+ auth={{
169
+ isAuthenticated: auth0PropsWithDefaults.isAuthenticated,
170
+ isLoading: auth0PropsWithDefaults.isLoading,
171
+ loginWithRedirect: auth0PropsWithDefaults.loginWithRedirect,
172
+ logout: auth0PropsWithDefaults.logout
173
+ }}
174
+ />
175
+ </Router>
176
+ )
177
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _auth0LoginZone = _interopRequireDefault(require("./auth0-login-zone"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ var _default = exports.default = _auth0LoginZone.default;