@dhis2/analytics 24.9.1 → 24.9.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [24.9.2](https://github.com/dhis2/analytics/compare/v24.9.1...v24.9.2) (2023-03-14)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * deduplicate yarn.lock ([#1450](https://github.com/dhis2/analytics/issues/1450)) ([85781ef](https://github.com/dhis2/analytics/commit/85781efeb3f347eabb70ff0db327f888dfcb3da3))
7
+ * prevent wrong URL with duplicated path parts DHIS2-14789 ([#1449](https://github.com/dhis2/analytics/issues/1449)) ([7c5c2a6](https://github.com/dhis2/analytics/commit/7c5c2a6870f14f9a18c155ee7f7817a3055b6205))
8
+ * use connection status to handle local offline conditions ([#1443](https://github.com/dhis2/analytics/issues/1443)) ([df4bb97](https://github.com/dhis2/analytics/commit/df4bb97f52d9bc03555621beadfe929721500e31))
9
+
1
10
  ## [24.9.1](https://github.com/dhis2/analytics/compare/v24.9.0...v24.9.1) (2023-03-10)
2
11
 
3
12
 
@@ -5,6 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.GetLinkDialog = void 0;
7
7
 
8
+ var _style = _interopRequireDefault(require("styled-jsx/style"));
9
+
10
+ var _appRuntime = require("@dhis2/app-runtime");
11
+
8
12
  var _ui = require("@dhis2/ui");
9
13
 
10
14
  var _propTypes = _interopRequireDefault(require("prop-types"));
@@ -13,6 +17,8 @@ var _react = _interopRequireDefault(require("react"));
13
17
 
14
18
  var _index = _interopRequireDefault(require("../../locales/index.js"));
15
19
 
20
+ var _GetLinkDialogStyles = require("./GetLinkDialog.styles.js");
21
+
16
22
  var _utils = require("./utils.js");
17
23
 
18
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -23,13 +29,27 @@ const GetLinkDialog = _ref => {
23
29
  id,
24
30
  onClose
25
31
  } = _ref;
26
- // TODO simply use href from the visualization object?
27
- const appUrl = new URL((0, _utils.appPathFor)(type, id), "".concat(window.location.origin).concat(window.location.pathname));
32
+ const {
33
+ baseUrl
34
+ } = (0, _appRuntime.useConfig)(); // TODO simply use href from the visualization object?
35
+
36
+ const appUrl = new URL((0, _utils.appPathFor)(type, id), baseUrl);
28
37
  return /*#__PURE__*/_react.default.createElement(_ui.Modal, {
29
38
  onClose: onClose
30
- }, /*#__PURE__*/_react.default.createElement(_ui.ModalContent, null, /*#__PURE__*/_react.default.createElement("p", null, _index.default.t('Open in this app')), /*#__PURE__*/_react.default.createElement("a", {
31
- href: appUrl.href
32
- }, appUrl.href)), /*#__PURE__*/_react.default.createElement(_ui.ModalActions, null, /*#__PURE__*/_react.default.createElement(_ui.ButtonStrip, null, /*#__PURE__*/_react.default.createElement(_ui.Button, {
39
+ }, /*#__PURE__*/_react.default.createElement(_style.default, {
40
+ id: _GetLinkDialogStyles.styles.__hash
41
+ }, _GetLinkDialogStyles.styles), /*#__PURE__*/_react.default.createElement(_ui.ModalContent, null, /*#__PURE__*/_react.default.createElement("p", {
42
+ className: "jsx-".concat(_GetLinkDialogStyles.styles.__hash)
43
+ }, _index.default.t('Open in this app')), /*#__PURE__*/_react.default.createElement("div", {
44
+ className: "jsx-".concat(_GetLinkDialogStyles.styles.__hash) + " " + "link-container"
45
+ }, /*#__PURE__*/_react.default.createElement("a", {
46
+ href: appUrl.href,
47
+ className: "jsx-".concat(_GetLinkDialogStyles.styles.__hash)
48
+ }, appUrl.href), /*#__PURE__*/_react.default.createElement(_ui.Button, {
49
+ icon: /*#__PURE__*/_react.default.createElement(_ui.IconCopy24, null),
50
+ small: true,
51
+ onClick: () => navigator.clipboard.writeText(appUrl.href)
52
+ }))), /*#__PURE__*/_react.default.createElement(_ui.ModalActions, null, /*#__PURE__*/_react.default.createElement(_ui.ButtonStrip, null, /*#__PURE__*/_react.default.createElement(_ui.Button, {
33
53
  onClick: onClose,
34
54
  secondary: true
35
55
  }, _index.default.t('Close')))));
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.styles = void 0;
7
+
8
+ var _ui = require("@dhis2/ui");
9
+
10
+ const styles = [".link-container.jsx-844167137{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;gap:".concat(_ui.spacers.dp12, ";}")];
11
+ exports.styles = styles;
12
+ styles.__hash = "844167137";
@@ -12,6 +12,12 @@ var _utils = require("../utils.js");
12
12
 
13
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
14
 
15
+ const testBaseUrl = 'http://test.tld/test';
16
+ jest.mock('@dhis2/app-runtime', () => ({
17
+ useConfig: () => ({
18
+ baseUrl: testBaseUrl
19
+ })
20
+ }));
15
21
  describe('The FileMenu - GetLinkDialog component', () => {
16
22
  let shallowGetLinkDialog;
17
23
  let props;
@@ -38,10 +44,10 @@ describe('The FileMenu - GetLinkDialog component', () => {
38
44
  });
39
45
  it('renders a <a> tag containing the type and id props', () => {
40
46
  const href = getGetLinkDialogComponent(props).find('a').prop('href');
41
- expect(href).toMatch((0, _utils.appPathFor)(props.type, props.id));
47
+ expect(href).toMatch(new URL((0, _utils.appPathFor)(props.type, props.id), testBaseUrl).href);
42
48
  });
43
49
  it('calls the onClose callback when the Close button is clicked', () => {
44
- getGetLinkDialogComponent(props).find(_ui.Button).first().simulate('click');
50
+ getGetLinkDialogComponent(props).find(_ui.Button).at(1).simulate('click');
45
51
  expect(onClose).toHaveBeenCalled();
46
52
  });
47
53
  });
@@ -31,8 +31,8 @@ const OfflineTooltip = _ref => {
31
31
  children
32
32
  } = _ref;
33
33
  const {
34
- offline
35
- } = (0, _appRuntime.useOnlineStatus)();
34
+ isDisconnected: offline
35
+ } = (0, _appRuntime.useDhis2ConnectionStatus)();
36
36
  const notAllowed = disabled || disabledWhenOffline && offline;
37
37
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_ui.Tooltip, {
38
38
  content: content || _d2I18n.default.t('Not available offline'),
@@ -52,8 +52,8 @@ const TranslationModalActions = _ref2 => {
52
52
  saveButtonDisabled
53
53
  } = _ref2;
54
54
  const {
55
- offline
56
- } = (0, _appRuntime.useOnlineStatus)();
55
+ isDisconnected: offline
56
+ } = (0, _appRuntime.useDhis2ConnectionStatus)();
57
57
  return /*#__PURE__*/_react.default.createElement(_ui.ModalActions, null, /*#__PURE__*/_react.default.createElement(_ui.ButtonStrip, null, /*#__PURE__*/_react.default.createElement(_ui.Button, {
58
58
  secondary: true,
59
59
  onClick: onClose
@@ -1,7 +1,10 @@
1
- import { Modal, ModalContent, ModalActions, ButtonStrip, Button } from '@dhis2/ui';
1
+ import _JSXStyle from "styled-jsx/style";
2
+ import { useConfig } from '@dhis2/app-runtime';
3
+ import { Modal, ModalContent, ModalActions, ButtonStrip, Button, IconCopy24 } from '@dhis2/ui';
2
4
  import PropTypes from 'prop-types';
3
5
  import React from 'react';
4
6
  import i18n from '../../locales/index.js';
7
+ import { styles } from './GetLinkDialog.styles.js';
5
8
  import { supportedFileTypes, appPathFor } from './utils.js';
6
9
  export const GetLinkDialog = _ref => {
7
10
  let {
@@ -9,13 +12,27 @@ export const GetLinkDialog = _ref => {
9
12
  id,
10
13
  onClose
11
14
  } = _ref;
12
- // TODO simply use href from the visualization object?
13
- const appUrl = new URL(appPathFor(type, id), "".concat(window.location.origin).concat(window.location.pathname));
15
+ const {
16
+ baseUrl
17
+ } = useConfig(); // TODO simply use href from the visualization object?
18
+
19
+ const appUrl = new URL(appPathFor(type, id), baseUrl);
14
20
  return /*#__PURE__*/React.createElement(Modal, {
15
21
  onClose: onClose
16
- }, /*#__PURE__*/React.createElement(ModalContent, null, /*#__PURE__*/React.createElement("p", null, i18n.t('Open in this app')), /*#__PURE__*/React.createElement("a", {
17
- href: appUrl.href
18
- }, appUrl.href)), /*#__PURE__*/React.createElement(ModalActions, null, /*#__PURE__*/React.createElement(ButtonStrip, null, /*#__PURE__*/React.createElement(Button, {
22
+ }, /*#__PURE__*/React.createElement(_JSXStyle, {
23
+ id: styles.__hash
24
+ }, styles), /*#__PURE__*/React.createElement(ModalContent, null, /*#__PURE__*/React.createElement("p", {
25
+ className: "jsx-".concat(styles.__hash)
26
+ }, i18n.t('Open in this app')), /*#__PURE__*/React.createElement("div", {
27
+ className: "jsx-".concat(styles.__hash) + " " + "link-container"
28
+ }, /*#__PURE__*/React.createElement("a", {
29
+ href: appUrl.href,
30
+ className: "jsx-".concat(styles.__hash)
31
+ }, appUrl.href), /*#__PURE__*/React.createElement(Button, {
32
+ icon: /*#__PURE__*/React.createElement(IconCopy24, null),
33
+ small: true,
34
+ onClick: () => navigator.clipboard.writeText(appUrl.href)
35
+ }))), /*#__PURE__*/React.createElement(ModalActions, null, /*#__PURE__*/React.createElement(ButtonStrip, null, /*#__PURE__*/React.createElement(Button, {
19
36
  onClick: onClose,
20
37
  secondary: true
21
38
  }, i18n.t('Close')))));
@@ -0,0 +1,3 @@
1
+ import { spacers } from '@dhis2/ui';
2
+ export const styles = [".link-container.jsx-844167137{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;gap:".concat(spacers.dp12, ";}")];
3
+ styles.__hash = "844167137";
@@ -3,6 +3,12 @@ import { shallow } from 'enzyme';
3
3
  import React from 'react';
4
4
  import { GetLinkDialog } from '../GetLinkDialog.js';
5
5
  import { appPathFor } from '../utils.js';
6
+ const testBaseUrl = 'http://test.tld/test';
7
+ jest.mock('@dhis2/app-runtime', () => ({
8
+ useConfig: () => ({
9
+ baseUrl: testBaseUrl
10
+ })
11
+ }));
6
12
  describe('The FileMenu - GetLinkDialog component', () => {
7
13
  let shallowGetLinkDialog;
8
14
  let props;
@@ -29,10 +35,10 @@ describe('The FileMenu - GetLinkDialog component', () => {
29
35
  });
30
36
  it('renders a <a> tag containing the type and id props', () => {
31
37
  const href = getGetLinkDialogComponent(props).find('a').prop('href');
32
- expect(href).toMatch(appPathFor(props.type, props.id));
38
+ expect(href).toMatch(new URL(appPathFor(props.type, props.id), testBaseUrl).href);
33
39
  });
34
40
  it('calls the onClose callback when the Close button is clicked', () => {
35
- getGetLinkDialogComponent(props).find(Button).first().simulate('click');
41
+ getGetLinkDialogComponent(props).find(Button).at(1).simulate('click');
36
42
  expect(onClose).toHaveBeenCalled();
37
43
  });
38
44
  });
@@ -1,5 +1,5 @@
1
1
  import _JSXStyle from "styled-jsx/style";
2
- import { useOnlineStatus } from '@dhis2/app-runtime';
2
+ import { useDhis2ConnectionStatus } from '@dhis2/app-runtime';
3
3
  import i18n from '@dhis2/d2-i18n';
4
4
  import { Tooltip } from '@dhis2/ui';
5
5
  import cx from 'classnames';
@@ -15,8 +15,8 @@ const OfflineTooltip = _ref => {
15
15
  children
16
16
  } = _ref;
17
17
  const {
18
- offline
19
- } = useOnlineStatus();
18
+ isDisconnected: offline
19
+ } = useDhis2ConnectionStatus();
20
20
  const notAllowed = disabled || disabledWhenOffline && offline;
21
21
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Tooltip, {
22
22
  content: content || i18n.t('Not available offline'),
@@ -1,4 +1,4 @@
1
- import { useOnlineStatus } from '@dhis2/app-runtime';
1
+ import { useDhis2ConnectionStatus } from '@dhis2/app-runtime';
2
2
  import i18n from '@dhis2/d2-i18n';
3
3
  import { Button, ButtonStrip, ModalActions } from '@dhis2/ui';
4
4
  import PropTypes from 'prop-types';
@@ -37,8 +37,8 @@ export const TranslationModalActions = _ref2 => {
37
37
  saveButtonDisabled
38
38
  } = _ref2;
39
39
  const {
40
- offline
41
- } = useOnlineStatus();
40
+ isDisconnected: offline
41
+ } = useDhis2ConnectionStatus();
42
42
  return /*#__PURE__*/React.createElement(ModalActions, null, /*#__PURE__*/React.createElement(ButtonStrip, null, /*#__PURE__*/React.createElement(Button, {
43
43
  secondary: true,
44
44
  onClick: onClose
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2/analytics",
3
- "version": "24.9.1",
3
+ "version": "24.9.2",
4
4
  "main": "./build/cjs/index.js",
5
5
  "module": "./build/es/index.js",
6
6
  "exports": {
@@ -31,7 +31,7 @@
31
31
  "validate-push": "yarn test"
32
32
  },
33
33
  "devDependencies": {
34
- "@dhis2/app-runtime": "^3.4.4",
34
+ "@dhis2/app-runtime": "^3.9.0",
35
35
  "@dhis2/cli-app-scripts": "^9.0.1",
36
36
  "@dhis2/cli-style": "^10.4.1",
37
37
  "@dhis2/d2-i18n": "^1.1.0",