@dhis2-ui/header-bar 8.4.17 → 8.5.0-beta.2

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 (53) hide show
  1. package/build/cjs/__e2e__/header-bar.stories.e2e.js +40 -0
  2. package/build/cjs/__e2e__/stories/common.js +99 -32
  3. package/build/cjs/__e2e__/stories/with-debug-info-edge-cases.js +45 -0
  4. package/build/cjs/__e2e__/stories/with-update-available-notification.js +38 -0
  5. package/build/cjs/apps.js +1 -1
  6. package/build/cjs/debug-info/debug-info-menu-item.js +67 -0
  7. package/build/cjs/debug-info/debug-info-modal.js +59 -0
  8. package/build/cjs/debug-info/debug-info-table.js +47 -0
  9. package/build/cjs/debug-info/use-debug-info.js +28 -0
  10. package/build/cjs/features/the_headerbar_should_display_app_update_notification/index.js +34 -0
  11. package/build/cjs/features/the_headerbar_should_display_app_update_notification.feature +22 -0
  12. package/build/cjs/features/the_headerbar_should_display_debug_version_infos/index.js +69 -0
  13. package/build/cjs/features/the_headerbar_should_display_debug_version_infos.feature +52 -0
  14. package/build/cjs/header-bar-context.js +46 -0
  15. package/build/cjs/header-bar.js +22 -11
  16. package/build/cjs/header-bar.stories.js +70 -72
  17. package/build/cjs/locales/en/translations.json +12 -1
  18. package/build/cjs/profile/use-on-doc-click.js +30 -0
  19. package/build/cjs/profile/use-on-doc-click.test.js +42 -0
  20. package/build/cjs/profile-menu/index.js +18 -0
  21. package/build/cjs/{profile → profile-menu}/profile-header.js +0 -0
  22. package/build/cjs/{profile → profile-menu}/profile-menu.js +23 -15
  23. package/build/cjs/profile-menu/update-notification.js +70 -0
  24. package/build/cjs/profile.js +52 -62
  25. package/build/es/__e2e__/header-bar.stories.e2e.js +5 -3
  26. package/build/es/__e2e__/stories/common.js +96 -33
  27. package/build/es/__e2e__/stories/with-debug-info-edge-cases.js +22 -0
  28. package/build/es/__e2e__/stories/with-update-available-notification.js +19 -0
  29. package/build/es/apps.js +1 -1
  30. package/build/es/debug-info/debug-info-menu-item.js +48 -0
  31. package/build/es/debug-info/debug-info-modal.js +41 -0
  32. package/build/es/debug-info/debug-info-table.js +35 -0
  33. package/build/es/debug-info/use-debug-info.js +15 -0
  34. package/build/es/features/the_headerbar_should_display_app_update_notification/index.js +31 -0
  35. package/build/es/features/the_headerbar_should_display_app_update_notification.feature +22 -0
  36. package/build/es/features/the_headerbar_should_display_debug_version_infos/index.js +66 -0
  37. package/build/es/features/the_headerbar_should_display_debug_version_infos.feature +52 -0
  38. package/build/es/header-bar-context.js +25 -0
  39. package/build/es/header-bar.js +21 -11
  40. package/build/es/header-bar.stories.js +65 -71
  41. package/build/es/locales/en/translations.json +12 -1
  42. package/build/es/profile/use-on-doc-click.js +20 -0
  43. package/build/es/profile/use-on-doc-click.test.js +38 -0
  44. package/build/es/profile-menu/index.js +1 -0
  45. package/build/es/{profile → profile-menu}/profile-header.js +0 -0
  46. package/build/es/{profile → profile-menu}/profile-menu.js +23 -17
  47. package/build/es/profile-menu/update-notification.js +51 -0
  48. package/build/es/profile.js +49 -64
  49. package/package.json +15 -13
  50. package/build/cjs/features/the_headerbar_displays_instance_and_app_infos/index.js +0 -15
  51. package/build/cjs/features/the_headerbar_displays_instance_and_app_infos.feature +0 -29
  52. package/build/es/features/the_headerbar_displays_instance_and_app_infos/index.js +0 -12
  53. package/build/es/features/the_headerbar_displays_instance_and_app_infos.feature +0 -29
@@ -75,6 +75,42 @@ Object.defineProperty(exports, "WithSpecialAppNameCharacters", {
75
75
  return _withSpecialAppNameCharacter.WithSpecialAppNameCharacters;
76
76
  }
77
77
  });
78
+ Object.defineProperty(exports, "WithUnknownAppName", {
79
+ enumerable: true,
80
+ get: function () {
81
+ return _withDebugInfoEdgeCases.WithUnknownAppName;
82
+ }
83
+ });
84
+ Object.defineProperty(exports, "WithUnknownAppNameAndVersion", {
85
+ enumerable: true,
86
+ get: function () {
87
+ return _withDebugInfoEdgeCases.WithUnknownAppNameAndVersion;
88
+ }
89
+ });
90
+ Object.defineProperty(exports, "WithUnknownAppVersion", {
91
+ enumerable: true,
92
+ get: function () {
93
+ return _withDebugInfoEdgeCases.WithUnknownAppVersion;
94
+ }
95
+ });
96
+ Object.defineProperty(exports, "WithUnknownInstanceVersion", {
97
+ enumerable: true,
98
+ get: function () {
99
+ return _withDebugInfoEdgeCases.WithUnknownInstanceVersion;
100
+ }
101
+ });
102
+ Object.defineProperty(exports, "WithUpdateAvailableNotification", {
103
+ enumerable: true,
104
+ get: function () {
105
+ return _withUpdateAvailableNotification.WithUpdateAvailableNotification;
106
+ }
107
+ });
108
+ Object.defineProperty(exports, "WithUpdateAvailableNotificationNoAppName", {
109
+ enumerable: true,
110
+ get: function () {
111
+ return _withUpdateAvailableNotification.WithUpdateAvailableNotificationNoAppName;
112
+ }
113
+ });
78
114
  Object.defineProperty(exports, "ZeroUnreadInterpretations", {
79
115
  enumerable: true,
80
116
  get: function () {
@@ -119,6 +155,10 @@ var _zeroUnreadInterpretations = require("./stories/zero-unread-interpretations.
119
155
 
120
156
  var _zeroUnreadMessages = require("./stories/zero-unread-messages.js");
121
157
 
158
+ var _withUpdateAvailableNotification = require("./stories/with-update-available-notification.js");
159
+
160
+ var _withDebugInfoEdgeCases = require("./stories/with-debug-info-edge-cases.js");
161
+
122
162
  var _default = {
123
163
  title: 'HeaderBarTesting',
124
164
  component: _index.HeaderBar
@@ -7,7 +7,13 @@ exports.providerConfig = exports.modulesWithSpecialCharacters = exports.defaultM
7
7
 
8
8
  var _appRuntime = require("@dhis2/app-runtime");
9
9
 
10
- var _react = _interopRequireDefault(require("react"));
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
+
12
+ var _react = _interopRequireWildcard(require("react"));
13
+
14
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
+
16
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
11
17
 
12
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
19
 
@@ -278,36 +284,6 @@ exports.modulesWithSpecialCharacters = modulesWithSpecialCharacters;
278
284
  const applicationTitle = 'Foobar';
279
285
  exports.applicationTitle = applicationTitle;
280
286
  const dataProviderData = {
281
- 'system/info': {
282
- contextPath: 'https://debug.dhis2.org/dev',
283
- userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36',
284
- calendar: 'iso8601',
285
- dateFormat: 'yyyy-mm-dd',
286
- serverDate: '2021-10-06T08:06:15.256',
287
- serverTimeZoneId: 'Etc/UTC',
288
- serverTimeZoneDisplayName: 'Coordinated Universal Time',
289
- lastAnalyticsTableSuccess: '2021-09-18T10:24:03.536',
290
- intervalSinceLastAnalyticsTableSuccess: '429 h, 42 m, 11 s',
291
- lastAnalyticsTableRuntime: '520835',
292
- lastSystemMonitoringSuccess: '2019-03-26T17:07:15.418',
293
- version: '2.38-SNAPSHOT',
294
- revision: '6607c3c',
295
- buildTime: '2021-10-05T17:13:00.000',
296
- jasperReportsVersion: '6.3.1',
297
- environmentVariable: 'DHIS2_HOME',
298
- databaseInfo: {
299
- spatialSupport: true
300
- },
301
- encryption: false,
302
- emailConfigured: false,
303
- redisEnabled: false,
304
- systemId: 'eed3d451-4ff5-4193-b951-ffcc68954299',
305
- systemName: 'DHIS 2 Demo - Sierra Leone',
306
- instanceBaseUrl: 'https://debug.dhis2.org/dev',
307
- clusterHostname: '',
308
- isMetadataVersionEnabled: true,
309
- metadataSyncEnabled: false
310
- },
311
287
  'systemSettings/applicationTitle': {
312
288
  applicationTitle
313
289
  },
@@ -346,15 +322,106 @@ const createDecoratorCustomDataProviderHeaderBar = function () {
346
322
 
347
323
  exports.createDecoratorCustomDataProviderHeaderBar = createDecoratorCustomDataProviderHeaderBar;
348
324
  const providerConfig = {
325
+ appName: 'TestApp',
326
+ appVersion: {
327
+ full: '101.2.3-beta.4',
328
+ major: 101,
329
+ minor: 2,
330
+ patch: 3,
331
+ tag: 'beta.4'
332
+ },
333
+ serverVersion: {
334
+ full: '2.39.2.1-SNAPSHOT',
335
+ major: 2,
336
+ minor: 39,
337
+ patch: 2,
338
+ hotfix: 1,
339
+ tag: 'SNAPSHOT'
340
+ },
341
+ systemInfo: {
342
+ contextPath: 'https://debug.dhis2.org/dev',
343
+ userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36',
344
+ calendar: 'iso8601',
345
+ dateFormat: 'yyyy-mm-dd',
346
+ serverDate: '2021-10-06T08:06:15.256',
347
+ serverTimeZoneId: 'Etc/UTC',
348
+ serverTimeZoneDisplayName: 'Coordinated Universal Time',
349
+ lastAnalyticsTableSuccess: '2021-09-18T10:24:03.536',
350
+ intervalSinceLastAnalyticsTableSuccess: '429 h, 42 m, 11 s',
351
+ lastAnalyticsTableRuntime: '520835',
352
+ lastSystemMonitoringSuccess: '2019-03-26T17:07:15.418',
353
+ version: '2.39.2.1-SNAPSHOT',
354
+ revision: '6607c3c',
355
+ buildTime: '2021-10-05T17:13:00.000',
356
+ jasperReportsVersion: '6.3.1',
357
+ environmentVariable: 'DHIS2_HOME',
358
+ databaseInfo: {
359
+ spatialSupport: true
360
+ },
361
+ encryption: false,
362
+ emailConfigured: false,
363
+ redisEnabled: false,
364
+ systemId: 'eed3d451-4ff5-4193-b951-ffcc68954299',
365
+ systemName: 'DHIS 2 Demo - Sierra Leone',
366
+ instanceBaseUrl: 'https://debug.dhis2.org/dev',
367
+ clusterHostname: '',
368
+ isMetadataVersionEnabled: true,
369
+ metadataSyncEnabled: false
370
+ },
349
371
  baseUrl: 'https://domain.tld/',
350
372
  apiVersion: ''
351
373
  };
352
374
  exports.providerConfig = providerConfig;
353
375
 
376
+ const MockAlert = _ref => {
377
+ let {
378
+ alert
379
+ } = _ref;
380
+ (0, _react.useEffect)(() => {
381
+ var _alert$options;
382
+
383
+ if ((_alert$options = alert.options) !== null && _alert$options !== void 0 && _alert$options.duration) {
384
+ var _alert$options2;
385
+
386
+ setTimeout(() => alert.remove(), (_alert$options2 = alert.options) === null || _alert$options2 === void 0 ? void 0 : _alert$options2.duration);
387
+ }
388
+ }, [alert]);
389
+ return /*#__PURE__*/_react.default.createElement("div", {
390
+ style: {
391
+ backgroundColor: '#CCC',
392
+ padding: 8
393
+ }
394
+ }, alert.message);
395
+ };
396
+
397
+ MockAlert.propTypes = {
398
+ alert: _propTypes.default.shape({
399
+ message: _propTypes.default.string,
400
+ options: _propTypes.default.shape({
401
+ duration: _propTypes.default.number
402
+ }),
403
+ remove: _propTypes.default.func
404
+ })
405
+ };
406
+
407
+ const MocklAlertStack = () => {
408
+ const alerts = (0, _appRuntime.useAlerts)();
409
+ return /*#__PURE__*/_react.default.createElement("div", {
410
+ style: {
411
+ position: 'absolute',
412
+ bottom: 16,
413
+ right: 16
414
+ }
415
+ }, alerts.map(alert => /*#__PURE__*/_react.default.createElement(MockAlert, {
416
+ key: alert.id,
417
+ alert: alert
418
+ })));
419
+ };
420
+
354
421
  const createDecoratorProvider = config => {
355
422
  return fn => /*#__PURE__*/_react.default.createElement(_appRuntime.Provider, {
356
423
  config: config || providerConfig
357
- }, fn());
424
+ }, fn(), /*#__PURE__*/_react.default.createElement(MocklAlertStack, null));
358
425
  };
359
426
 
360
427
  exports.createDecoratorProvider = createDecoratorProvider;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.WithUnknownInstanceVersion = exports.WithUnknownAppVersion = exports.WithUnknownAppNameAndVersion = exports.WithUnknownAppName = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ var _headerBar = require("../../header-bar.js");
11
+
12
+ var _common = require("./common.js");
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ const WithUnknownInstanceVersion = () => /*#__PURE__*/_react.default.createElement(_headerBar.HeaderBar, null);
17
+
18
+ exports.WithUnknownInstanceVersion = WithUnknownInstanceVersion;
19
+ WithUnknownInstanceVersion.decorators = [(0, _common.createDecoratorCustomDataProviderHeaderBar)(), (0, _common.createDecoratorProvider)({ ..._common.providerConfig,
20
+ systemInfo: { ..._common.providerConfig.systemInfo,
21
+ version: undefined
22
+ }
23
+ })];
24
+
25
+ const WithUnknownAppVersion = () => /*#__PURE__*/_react.default.createElement(_headerBar.HeaderBar, null);
26
+
27
+ exports.WithUnknownAppVersion = WithUnknownAppVersion;
28
+ WithUnknownAppVersion.decorators = [(0, _common.createDecoratorCustomDataProviderHeaderBar)(), (0, _common.createDecoratorProvider)({ ..._common.providerConfig,
29
+ appVersion: undefined
30
+ })];
31
+
32
+ const WithUnknownAppName = () => /*#__PURE__*/_react.default.createElement(_headerBar.HeaderBar, null);
33
+
34
+ exports.WithUnknownAppName = WithUnknownAppName;
35
+ WithUnknownAppName.decorators = [(0, _common.createDecoratorCustomDataProviderHeaderBar)(), (0, _common.createDecoratorProvider)({ ..._common.providerConfig,
36
+ appName: undefined
37
+ })];
38
+
39
+ const WithUnknownAppNameAndVersion = () => /*#__PURE__*/_react.default.createElement(_headerBar.HeaderBar, null);
40
+
41
+ exports.WithUnknownAppNameAndVersion = WithUnknownAppNameAndVersion;
42
+ WithUnknownAppNameAndVersion.decorators = [(0, _common.createDecoratorCustomDataProviderHeaderBar)(), (0, _common.createDecoratorProvider)({ ..._common.providerConfig,
43
+ appName: undefined,
44
+ appVersion: undefined
45
+ })];
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.WithUpdateAvailableNotificationNoAppName = exports.WithUpdateAvailableNotification = void 0;
7
+
8
+ var _react = _interopRequireWildcard(require("react"));
9
+
10
+ var _headerBar = require("../../header-bar.js");
11
+
12
+ var _common = require("./common.js");
13
+
14
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
+
16
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
+
18
+ const WithUpdateAvailableNotification = () => {
19
+ const [modalOpen, setModalOpen] = (0, _react.useState)(false);
20
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_headerBar.HeaderBar, {
21
+ updateAvailable: true,
22
+ onApplyAvailableUpdate: () => setModalOpen(true)
23
+ }), modalOpen && /*#__PURE__*/_react.default.createElement("div", null, "The callback was successful"));
24
+ };
25
+
26
+ exports.WithUpdateAvailableNotification = WithUpdateAvailableNotification;
27
+ WithUpdateAvailableNotification.decorators = [(0, _common.createDecoratorCustomDataProviderHeaderBar)(), (0, _common.createDecoratorProvider)({ ..._common.providerConfig,
28
+ appName: 'Data Visualizer'
29
+ })];
30
+
31
+ const WithUpdateAvailableNotificationNoAppName = () => /*#__PURE__*/_react.default.createElement(_headerBar.HeaderBar, {
32
+ updateAvailable: true
33
+ });
34
+
35
+ exports.WithUpdateAvailableNotificationNoAppName = WithUpdateAvailableNotificationNoAppName;
36
+ WithUpdateAvailableNotificationNoAppName.decorators = [(0, _common.createDecoratorCustomDataProviderHeaderBar)(), (0, _common.createDecoratorProvider)({ ..._common.providerConfig,
37
+ appName: undefined
38
+ })];
package/build/cjs/apps.js CHANGED
@@ -189,7 +189,7 @@ const Apps = _ref7 => {
189
189
  (0, _react.useEffect)(() => {
190
190
  document.addEventListener('click', onDocClick);
191
191
  return () => document.removeEventListener('click', onDocClick);
192
- }, []);
192
+ }, [onDocClick]);
193
193
  return /*#__PURE__*/_react.default.createElement("div", {
194
194
  ref: containerEl,
195
195
  "data-test": "headerbar-apps",
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DebugInfoMenuItem = void 0;
7
+
8
+ var _style = _interopRequireDefault(require("styled-jsx/style"));
9
+
10
+ var _menu = require("@dhis2-ui/menu");
11
+
12
+ var _uiConstants = require("@dhis2/ui-constants");
13
+
14
+ var _propTypes = _interopRequireDefault(require("prop-types"));
15
+
16
+ var _react = _interopRequireDefault(require("react"));
17
+
18
+ var _index = _interopRequireDefault(require("../locales/index.js"));
19
+
20
+ var _useDebugInfo = require("./use-debug-info.js");
21
+
22
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
+
24
+ const DebugInfoMenuItem = _ref => {
25
+ let {
26
+ hideProfileMenu,
27
+ showDebugInfoModal
28
+ } = _ref;
29
+ const debugInfo = (0, _useDebugInfo.useDebugInfo)();
30
+
31
+ const openDebugModal = () => {
32
+ hideProfileMenu();
33
+ showDebugInfoModal();
34
+ };
35
+
36
+ const debugInfoLabel = /*#__PURE__*/_react.default.createElement("div", {
37
+ className: _style.default.dynamic([["3534786758", [_uiConstants.colors.grey700]]]) + " " + "root"
38
+ }, /*#__PURE__*/_react.default.createElement("div", {
39
+ "data-test": "dhis2-ui-headerbar-instanceinfo",
40
+ className: _style.default.dynamic([["3534786758", [_uiConstants.colors.grey700]]]) + " " + "instance-info version"
41
+ }, debugInfo.dhis2_version ? _index.default.t('DHIS2 {{dhis2Version}}', {
42
+ dhis2Version: debugInfo.dhis2_version
43
+ }) : _index.default.t('DHIS2 version unknown')), /*#__PURE__*/_react.default.createElement("div", {
44
+ "data-test": "dhis2-ui-headerbar-appinfo",
45
+ className: _style.default.dynamic([["3534786758", [_uiConstants.colors.grey700]]]) + " " + "version"
46
+ }, debugInfo.app_name ? debugInfo.app_version ? "".concat(debugInfo.app_name, " ").concat(debugInfo.app_version) : _index.default.t('{{appName}} version unknown', {
47
+ appName: debugInfo.app_name
48
+ }) : debugInfo.app_version ? _index.default.t('App {{appVersion}}', {
49
+ appVersion: debugInfo.app_version
50
+ }) : _index.default.t('App version unknown')), /*#__PURE__*/_react.default.createElement(_style.default, {
51
+ id: "3534786758",
52
+ dynamic: [_uiConstants.colors.grey700]
53
+ }, [".root.__jsx-style-dynamic-selector{color:".concat(_uiConstants.colors.grey700, ";font-style:italic;font-size:14px;line-height:17px;}"), ".instance-info.__jsx-style-dynamic-selector{margin-bottom:4px;}", ".version.__jsx-style-dynamic-selector{white-space:no-wrap;}"]));
54
+
55
+ return /*#__PURE__*/_react.default.createElement(_menu.MenuItem, {
56
+ dense: true,
57
+ onClick: openDebugModal,
58
+ label: debugInfoLabel,
59
+ dataTest: "dhis2-ui-headerbar-debuginfo"
60
+ });
61
+ };
62
+
63
+ exports.DebugInfoMenuItem = DebugInfoMenuItem;
64
+ DebugInfoMenuItem.propTypes = {
65
+ hideProfileMenu: _propTypes.default.func.isRequired,
66
+ showDebugInfoModal: _propTypes.default.func.isRequired
67
+ };
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DebugInfoModal = DebugInfoModal;
7
+
8
+ var _button = require("@dhis2-ui/button");
9
+
10
+ var _modal = require("@dhis2-ui/modal");
11
+
12
+ var _appRuntime = require("@dhis2/app-runtime");
13
+
14
+ var _propTypes = _interopRequireDefault(require("prop-types"));
15
+
16
+ var _react = _interopRequireDefault(require("react"));
17
+
18
+ var _index = _interopRequireDefault(require("../locales/index.js"));
19
+
20
+ var _debugInfoTable = require("./debug-info-table.js");
21
+
22
+ var _useDebugInfo = require("./use-debug-info.js");
23
+
24
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
+
26
+ function DebugInfoModal(_ref) {
27
+ let {
28
+ onClose
29
+ } = _ref;
30
+ const debugInfo = (0, _useDebugInfo.useFormattedDebugInfo)();
31
+ const {
32
+ show: showClipboardAlert
33
+ } = (0, _appRuntime.useAlert)('Debug information copied to clipboard', {
34
+ duration: 3000
35
+ });
36
+
37
+ const copyDebugInfo = () => {
38
+ navigator.clipboard.writeText(debugInfo);
39
+ onClose();
40
+ showClipboardAlert();
41
+ };
42
+
43
+ return /*#__PURE__*/_react.default.createElement(_modal.Modal, {
44
+ position: "middle",
45
+ dataTest: "dhis2-ui-headerbar-debuginfomodal"
46
+ }, /*#__PURE__*/_react.default.createElement(_modal.ModalTitle, null, _index.default.t('Debug info')), /*#__PURE__*/_react.default.createElement(_modal.ModalContent, null, /*#__PURE__*/_react.default.createElement(_debugInfoTable.DebugInfoTable, null)), /*#__PURE__*/_react.default.createElement(_modal.ModalActions, null, /*#__PURE__*/_react.default.createElement(_button.ButtonStrip, {
47
+ end: true
48
+ }, /*#__PURE__*/_react.default.createElement(_button.Button, {
49
+ onClick: () => onClose()
50
+ }, _index.default.t('Close')), /*#__PURE__*/_react.default.createElement(_button.Button, {
51
+ primary: true,
52
+ onClick: copyDebugInfo,
53
+ dataTest: "dhis2-ui-headerbar-debuginfomodal-copybutton"
54
+ }, _index.default.t('Copy debug info')))));
55
+ }
56
+
57
+ DebugInfoModal.propTypes = {
58
+ onClose: _propTypes.default.func.isRequired
59
+ };
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DebugInfoTable = DebugInfoTable;
7
+
8
+ var _style = _interopRequireDefault(require("styled-jsx/style"));
9
+
10
+ var _uiConstants = require("@dhis2/ui-constants");
11
+
12
+ var _react = _interopRequireDefault(require("react"));
13
+
14
+ var _useDebugInfo = require("./use-debug-info.js");
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ const formatDebugInfoKey = key => {
19
+ const tokens = key.split('_');
20
+ return tokens.map(token => {
21
+ if (token.toLowerCase() === 'dhis2') {
22
+ return 'DHIS2';
23
+ } else {
24
+ return token[0].toUpperCase() + token.substr(1).toLowerCase();
25
+ }
26
+ }).join(' ');
27
+ };
28
+
29
+ function DebugInfoTable() {
30
+ const debugInfo = (0, _useDebugInfo.useDebugInfo)();
31
+ return /*#__PURE__*/_react.default.createElement("table", {
32
+ 'data-test': 'dhis2-ui-headerbar-debuginfotable',
33
+ className: _style.default.dynamic([["865651843", [_uiConstants.colors.grey700]]])
34
+ }, /*#__PURE__*/_react.default.createElement("tbody", {
35
+ className: _style.default.dynamic([["865651843", [_uiConstants.colors.grey700]]])
36
+ }, Object.keys(debugInfo).map(key => /*#__PURE__*/_react.default.createElement("tr", {
37
+ key: key,
38
+ className: _style.default.dynamic([["865651843", [_uiConstants.colors.grey700]]])
39
+ }, /*#__PURE__*/_react.default.createElement("td", {
40
+ className: _style.default.dynamic([["865651843", [_uiConstants.colors.grey700]]]) + " " + "debug-info-key"
41
+ }, formatDebugInfoKey(key)), /*#__PURE__*/_react.default.createElement("td", {
42
+ className: _style.default.dynamic([["865651843", [_uiConstants.colors.grey700]]])
43
+ }, debugInfo[key])))), /*#__PURE__*/_react.default.createElement(_style.default, {
44
+ id: "865651843",
45
+ dynamic: [_uiConstants.colors.grey700]
46
+ }, ["table.__jsx-style-dynamic-selector{white-space:pre-wrap;font-size:14px;line-height:1.2;color:".concat(_uiConstants.colors.grey700, ";font-famile:Menlo,Courier,monospace !important;}"), "td.__jsx-style-dynamic-selector{padding:3px 16px 3px 0;}", ".debug-info-key.__jsx-style-dynamic-selector{font-weight:bold;}"]));
47
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useFormattedDebugInfo = exports.useDebugInfo = void 0;
7
+
8
+ var _appRuntime = require("@dhis2/app-runtime");
9
+
10
+ const useDebugInfo = () => {
11
+ const {
12
+ appName,
13
+ appVersion,
14
+ systemInfo
15
+ } = (0, _appRuntime.useConfig)();
16
+ return {
17
+ app_name: appName || null,
18
+ app_version: (appVersion === null || appVersion === void 0 ? void 0 : appVersion.full) || null,
19
+ dhis2_version: (systemInfo === null || systemInfo === void 0 ? void 0 : systemInfo.version) || null,
20
+ dhis2_revision: (systemInfo === null || systemInfo === void 0 ? void 0 : systemInfo.revision) || null
21
+ };
22
+ };
23
+
24
+ exports.useDebugInfo = useDebugInfo;
25
+
26
+ const useFormattedDebugInfo = () => JSON.stringify(useDebugInfo(), undefined, 2);
27
+
28
+ exports.useFormattedDebugInfo = useFormattedDebugInfo;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ var _steps = require("cypress-cucumber-preprocessor/steps");
4
+
5
+ (0, _steps.Given)('the HeaderBar is rendered without an available update', () => {
6
+ cy.visitStory('HeaderBarTesting', 'default');
7
+ });
8
+ (0, _steps.Given)('the HeaderBar is rendered with an available update', () => {
9
+ cy.visitStory('HeaderBarTesting', 'With Update Available Notification');
10
+ });
11
+ (0, _steps.Given)('the HeaderBar is rendered with no app name and an available update', () => {
12
+ cy.visitStory('HeaderBarTesting', 'With Update Available Notification No App Name');
13
+ });
14
+ (0, _steps.When)('the user opens the profile menu', () => {
15
+ cy.get('[data-test="headerbar-profile"] > button').click();
16
+ });
17
+ (0, _steps.Then)('the update notification should not be displayed', () => {
18
+ cy.get('[data-test="dhis2-ui-headerbar-updatenotification"]').should('not.exist');
19
+ });
20
+ (0, _steps.Then)('the update notification should be displayed', () => {
21
+ cy.get('[data-test="dhis2-ui-headerbar-updatenotification"]').should('contain', 'New Data Visualizer version available').should('contain', 'Click to reload');
22
+ });
23
+ (0, _steps.Then)('the update notification should be displayed without app name', () => {
24
+ cy.get('[data-test="dhis2-ui-headerbar-updatenotification"]').should('contain', 'New app version available').should('contain', 'Click to reload');
25
+ });
26
+ (0, _steps.When)('the user clicks the update notification', () => {
27
+ cy.get('[data-test="dhis2-ui-headerbar-updatenotification"]').click();
28
+ });
29
+ (0, _steps.Then)('the profile menu should not be shown', () => {
30
+ cy.get('[data-test="headerbar-profile-menu"]').should('not.exist');
31
+ });
32
+ (0, _steps.Then)('a callback should display a test div', () => {
33
+ cy.contains('The callback was successful').should('be.visible');
34
+ });
@@ -0,0 +1,22 @@
1
+ Feature: The HeaderBar should display app update notification
2
+
3
+ Scenario: No app update is available
4
+ Given the HeaderBar is rendered without an available update
5
+ When the user opens the profile menu
6
+ Then the update notification should not be displayed
7
+
8
+ Scenario: An app update is available
9
+ Given the HeaderBar is rendered with an available update
10
+ When the user opens the profile menu
11
+ Then the update notification should be displayed
12
+
13
+ Scenario: A callback is executed when the user click on the update notification
14
+ Given the HeaderBar is rendered with an available update
15
+ When the user opens the profile menu
16
+ When the user clicks the update notification
17
+ Then a callback should display a test div
18
+
19
+ Scenario: An app update is available but not app name was specified
20
+ Given the HeaderBar is rendered with no app name and an available update
21
+ When the user opens the profile menu
22
+ Then the update notification should be displayed without app name
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ var _steps = require("cypress-cucumber-preprocessor/steps");
4
+
5
+ (0, _steps.Given)('the HeaderBar is rendered without an instance version in runtime context', () => {
6
+ cy.visitStory('HeaderBarTesting', 'With Unknown Instance Version');
7
+ });
8
+ (0, _steps.Given)('the HeaderBar is rendered with an app name and app version in runtime context', () => {
9
+ cy.visitStory('HeaderBarTesting', 'default');
10
+ });
11
+ (0, _steps.Given)('the HeaderBar is rendered without app name in runtime context', () => {
12
+ cy.visitStory('HeaderBarTesting', 'With Unknown App Name');
13
+ });
14
+ (0, _steps.Given)('the HeaderBar is rendered with an app name but without app version in runtime context', () => {
15
+ cy.visitStory('HeaderBarTesting', 'With Unknown App Version');
16
+ });
17
+ (0, _steps.Given)('the HeaderBar is rendered without app name or app version in runtime context', () => {
18
+ cy.visitStory('HeaderBarTesting', 'With Unknown App Name And Version');
19
+ });
20
+ (0, _steps.When)('the user opens the profile menu', () => {
21
+ cy.get('[data-test="headerbar-profile"] > button').click();
22
+ });
23
+ (0, _steps.Then)("the app's name and version should be displayed", () => {
24
+ cy.get('[data-test="dhis2-ui-headerbar-appinfo"]').should('contain', 'TestApp 101.2.3-beta.4');
25
+ });
26
+ (0, _steps.Then)("the app's name with unknown version should be displayed", () => {
27
+ cy.get('[data-test="dhis2-ui-headerbar-appinfo"]').should('contain', 'TestApp version unknown');
28
+ });
29
+ (0, _steps.Then)("the unknown app with app's version should be displayed", () => {
30
+ cy.get('[data-test="dhis2-ui-headerbar-appinfo"]').should('contain', 'App 101.2.3-beta.4');
31
+ });
32
+ (0, _steps.Then)('the unknown app with unknown version should be displayed', () => {
33
+ cy.get('[data-test="dhis2-ui-headerbar-appinfo"]').should('contain', 'App version unknown');
34
+ });
35
+ (0, _steps.Then)('the instance version should be displayed', () => {
36
+ cy.get('[data-test="dhis2-ui-headerbar-instanceinfo"]').should('contain', 'DHIS2 2.39.2.1-SNAPSHOT');
37
+ });
38
+ (0, _steps.Then)('the instance version should show as unknown', () => {
39
+ cy.get('[data-test="dhis2-ui-headerbar-instanceinfo"]').should('contain', 'DHIS2 version unknown');
40
+ });
41
+ (0, _steps.When)('the user clicks the debug info menu item', () => {
42
+ cy.get('[data-test="dhis2-ui-headerbar-debuginfo"] > a').click();
43
+ });
44
+ (0, _steps.Then)('the debug info modal should be shown', () => {
45
+ cy.get('[data-test="dhis2-ui-headerbar-debuginfomodal"]').should('be.visible');
46
+ });
47
+ (0, _steps.Then)('the debug info modal should not be shown', () => {
48
+ cy.get('[data-test="dhis2-ui-headerbar-debuginfomodal"]').should('not.exist');
49
+ });
50
+ (0, _steps.Then)('the debug info modal should contain debug info', () => {
51
+ cy.get('[data-test="dhis2-ui-headerbar-debuginfotable"]').should('contain', '2.39.2.1-SNAPSHOT' // DHIS2 version
52
+ ).should('contain', '6607c3c' // Revision
53
+ ).should('contain', 'TestApp' // App name
54
+ ).should('contain', '101.2.3-beta.4' // App version
55
+ );
56
+ });
57
+ (0, _steps.When)('the user clicks the copy debug info button', () => {
58
+ cy.contains('Copy debug info').click();
59
+ });
60
+ (0, _steps.Then)('the debug info should be copied to clipboard', () => {
61
+ cy.window().then(win => {
62
+ win.navigator.clipboard.readText().then(text => {
63
+ expect(text).to.contain('2.39.2.1-SNAPSHOT');
64
+ });
65
+ });
66
+ });
67
+ (0, _steps.Then)('the debug info copied to clipboard alert should be shown', () => {
68
+ cy.contains('Debug information copied to clipboard').should('exist');
69
+ });