@dhis2-ui/organisation-unit-tree 8.1.10 → 8.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/build/cjs/__e2e__/children_as_child_nodes.stories.e2e.js +11 -8
  2. package/build/cjs/__e2e__/common.js +53 -43
  3. package/build/cjs/__e2e__/controlled_expanded.stories.e2e.js +10 -7
  4. package/build/cjs/__e2e__/displaying_loading_error.stories.e2e.js +5 -1
  5. package/build/cjs/__e2e__/expanded.stories.e2e.js +35 -26
  6. package/build/cjs/__e2e__/force_reload.stories.e2e.js +21 -14
  7. package/build/cjs/__e2e__/highlight.stories.e2e.js +10 -7
  8. package/build/cjs/__e2e__/loading_state.stories.e2e.js +14 -7
  9. package/build/cjs/__e2e__/multi_selection.stories.e2e.js +11 -8
  10. package/build/cjs/__e2e__/no_selection.stories.e2e.js +21 -15
  11. package/build/cjs/__e2e__/path_based_filtering.stories.e2e.js +23 -17
  12. package/build/cjs/__e2e__/single_selection.stories.e2e.js +17 -10
  13. package/build/cjs/__e2e__/sub_unit_as_root.stories.e2e.js +6 -5
  14. package/build/cjs/__e2e__/tree_api.stories.e2e.js +22 -15
  15. package/build/cjs/__stories__/custom-expanded-imperative-open.js +9 -6
  16. package/build/cjs/__stories__/custom-node-label.js +6 -4
  17. package/build/cjs/__stories__/development-stories.js +7 -6
  18. package/build/cjs/__stories__/loading-error-grandchild.js +5 -1
  19. package/build/cjs/__stories__/loading.js +5 -1
  20. package/build/cjs/__stories__/multiple-roots.js +12 -9
  21. package/build/cjs/__stories__/root-error.js +5 -1
  22. package/build/cjs/__stories__/root-loading.js +5 -1
  23. package/build/cjs/__stories__/shared.js +82 -45
  24. package/build/cjs/features/controlled_expanded/index.js +8 -5
  25. package/build/cjs/features/expanded/index.js +1 -7
  26. package/build/cjs/features/path_based_filtering/index.js +2 -2
  27. package/build/cjs/features/sub_unit_as_root/index.js +1 -7
  28. package/build/cjs/get-all-expanded-paths/get-all-expanded-paths.js +1 -1
  29. package/build/cjs/helpers/is-path-included.js +1 -1
  30. package/build/cjs/helpers/left-trim-to-root-id.js +1 -1
  31. package/build/cjs/organisation-unit-node/compute-child-nodes.js +1 -1
  32. package/build/cjs/organisation-unit-node/error-message.js +13 -10
  33. package/build/cjs/organisation-unit-node/has-descendant-selected-paths.js +1 -1
  34. package/build/cjs/organisation-unit-node/label/disabled-selection-label.js +12 -9
  35. package/build/cjs/organisation-unit-node/label/icon-empty.js +22 -19
  36. package/build/cjs/organisation-unit-node/label/icon-folder-closed.js +28 -25
  37. package/build/cjs/organisation-unit-node/label/icon-folder-open.js +37 -34
  38. package/build/cjs/organisation-unit-node/label/icon-single.js +31 -28
  39. package/build/cjs/organisation-unit-node/label/icon.js +8 -6
  40. package/build/cjs/organisation-unit-node/label/iconized-checkbox.js +14 -12
  41. package/build/cjs/organisation-unit-node/label/label-container.js +16 -13
  42. package/build/cjs/organisation-unit-node/label/label.js +31 -27
  43. package/build/cjs/organisation-unit-node/label/single-selection-label.js +21 -18
  44. package/build/cjs/organisation-unit-node/organisation-unit-node-children.js +32 -29
  45. package/build/cjs/organisation-unit-node/organisation-unit-node.js +26 -25
  46. package/build/cjs/organisation-unit-node/use-open-state.js +9 -8
  47. package/build/cjs/organisation-unit-node/use-org-children.js +13 -9
  48. package/build/cjs/organisation-unit-node/use-org-children.test.js +69 -46
  49. package/build/cjs/organisation-unit-node/use-org-data/use-org-data.js +22 -14
  50. package/build/cjs/organisation-unit-node/use-org-data/use-org-data.test.js +30 -18
  51. package/build/cjs/organisation-unit-tree/default-render-node-label/default-render-node-label.js +6 -3
  52. package/build/cjs/organisation-unit-tree/filter-root-ids.js +1 -1
  53. package/build/cjs/organisation-unit-tree/organisation-unit-tree.js +23 -22
  54. package/build/cjs/organisation-unit-tree/root-error.js +12 -9
  55. package/build/cjs/organisation-unit-tree/root-loading.js +13 -10
  56. package/build/cjs/organisation-unit-tree/use-expanded/create-expand-handlers.js +19 -14
  57. package/build/cjs/organisation-unit-tree/use-expanded/use-expanded.js +9 -8
  58. package/build/cjs/organisation-unit-tree/use-root-org-data/patch-missing-display-name.js +2 -1
  59. package/build/cjs/organisation-unit-tree/use-root-org-data/use-root-org-data.js +14 -10
  60. package/build/cjs/organisation-unit-tree/use-root-org-data/use-root-org-unit.test.js +37 -20
  61. package/build/cjs/organisation-unit-tree.stories.js +32 -57
  62. package/build/cjs/prop-types.js +5 -5
  63. package/build/es/__e2e__/children_as_child_nodes.stories.e2e.js +11 -8
  64. package/build/es/__e2e__/common.js +52 -42
  65. package/build/es/__e2e__/controlled_expanded.stories.e2e.js +9 -6
  66. package/build/es/__e2e__/displaying_loading_error.stories.e2e.js +5 -1
  67. package/build/es/__e2e__/expanded.stories.e2e.js +34 -25
  68. package/build/es/__e2e__/force_reload.stories.e2e.js +21 -14
  69. package/build/es/__e2e__/highlight.stories.e2e.js +10 -7
  70. package/build/es/__e2e__/loading_state.stories.e2e.js +14 -7
  71. package/build/es/__e2e__/multi_selection.stories.e2e.js +11 -8
  72. package/build/es/__e2e__/no_selection.stories.e2e.js +21 -15
  73. package/build/es/__e2e__/path_based_filtering.stories.e2e.js +23 -17
  74. package/build/es/__e2e__/single_selection.stories.e2e.js +17 -10
  75. package/build/es/__e2e__/sub_unit_as_root.stories.e2e.js +5 -4
  76. package/build/es/__e2e__/tree_api.stories.e2e.js +22 -15
  77. package/build/es/__stories__/custom-expanded-imperative-open.js +9 -6
  78. package/build/es/__stories__/custom-node-label.js +6 -4
  79. package/build/es/__stories__/development-stories.js +6 -5
  80. package/build/es/__stories__/loading-error-grandchild.js +5 -1
  81. package/build/es/__stories__/loading.js +5 -1
  82. package/build/es/__stories__/multiple-roots.js +12 -9
  83. package/build/es/__stories__/root-error.js +5 -1
  84. package/build/es/__stories__/root-loading.js +5 -1
  85. package/build/es/__stories__/shared.js +82 -45
  86. package/build/es/features/controlled_expanded/index.js +8 -5
  87. package/build/es/features/expanded/index.js +1 -7
  88. package/build/es/features/path_based_filtering/index.js +2 -2
  89. package/build/es/features/sub_unit_as_root/index.js +1 -7
  90. package/build/es/get-all-expanded-paths/get-all-expanded-paths.js +1 -1
  91. package/build/es/helpers/is-path-included.js +1 -1
  92. package/build/es/helpers/left-trim-to-root-id.js +1 -1
  93. package/build/es/organisation-unit-node/compute-child-nodes.js +1 -1
  94. package/build/es/organisation-unit-node/error-message.js +13 -10
  95. package/build/es/organisation-unit-node/has-descendant-selected-paths.js +1 -1
  96. package/build/es/organisation-unit-node/label/disabled-selection-label.js +12 -9
  97. package/build/es/organisation-unit-node/label/icon-empty.js +22 -19
  98. package/build/es/organisation-unit-node/label/icon-folder-closed.js +28 -25
  99. package/build/es/organisation-unit-node/label/icon-folder-open.js +37 -34
  100. package/build/es/organisation-unit-node/label/icon-single.js +31 -28
  101. package/build/es/organisation-unit-node/label/icon.js +8 -6
  102. package/build/es/organisation-unit-node/label/iconized-checkbox.js +13 -12
  103. package/build/es/organisation-unit-node/label/label-container.js +16 -13
  104. package/build/es/organisation-unit-node/label/label.js +31 -27
  105. package/build/es/organisation-unit-node/label/single-selection-label.js +21 -18
  106. package/build/es/organisation-unit-node/organisation-unit-node-children.js +32 -29
  107. package/build/es/organisation-unit-node/organisation-unit-node.js +26 -25
  108. package/build/es/organisation-unit-node/use-open-state.js +9 -8
  109. package/build/es/organisation-unit-node/use-org-children.js +13 -9
  110. package/build/es/organisation-unit-node/use-org-children.test.js +69 -46
  111. package/build/es/organisation-unit-node/use-org-data/use-org-data.js +22 -14
  112. package/build/es/organisation-unit-node/use-org-data/use-org-data.test.js +30 -18
  113. package/build/es/organisation-unit-tree/default-render-node-label/default-render-node-label.js +6 -3
  114. package/build/es/organisation-unit-tree/filter-root-ids.js +1 -1
  115. package/build/es/organisation-unit-tree/organisation-unit-tree.js +23 -22
  116. package/build/es/organisation-unit-tree/root-error.js +12 -9
  117. package/build/es/organisation-unit-tree/root-loading.js +13 -10
  118. package/build/es/organisation-unit-tree/use-expanded/create-expand-handlers.js +19 -14
  119. package/build/es/organisation-unit-tree/use-expanded/use-expanded.js +9 -8
  120. package/build/es/organisation-unit-tree/use-root-org-data/patch-missing-display-name.js +2 -1
  121. package/build/es/organisation-unit-tree/use-root-org-data/use-root-org-data.js +14 -10
  122. package/build/es/organisation-unit-tree/use-root-org-data/use-root-org-unit.test.js +37 -20
  123. package/build/es/organisation-unit-tree.stories.js +2 -27
  124. package/build/es/prop-types.js +4 -4
  125. package/package.json +5 -5
@@ -8,11 +8,14 @@ storiesOf(namespace, module).add('Multiple selection', () => /*#__PURE__*/React.
8
8
  data: dataProviderData
9
9
  }, /*#__PURE__*/React.createElement(StatefulMultiSelectionWrapper, {
10
10
  onSelectionChange: newSelection => window.selection = newSelection
11
- }, ({
12
- selected,
13
- onChange
14
- }) => /*#__PURE__*/React.createElement(OrganisationUnitTree, {
15
- roots: "A0000000000",
16
- onChange: onChange,
17
- selected: selected
18
- }))));
11
+ }, _ref => {
12
+ let {
13
+ selected,
14
+ onChange
15
+ } = _ref;
16
+ return /*#__PURE__*/React.createElement(OrganisationUnitTree, {
17
+ roots: "A0000000000",
18
+ onChange: onChange,
19
+ selected: selected
20
+ });
21
+ })));
@@ -5,19 +5,25 @@ import { OrganisationUnitTree } from '../index.js';
5
5
  import { StatefulMultiSelectionWrapper, dataProviderData, namespace } from './common.js';
6
6
  storiesOf(namespace, module).add('No selection closed', () => /*#__PURE__*/React.createElement(CustomDataProvider, {
7
7
  data: dataProviderData
8
- }, /*#__PURE__*/React.createElement(StatefulMultiSelectionWrapper, null, ({
9
- onChange
10
- }) => /*#__PURE__*/React.createElement(OrganisationUnitTree, {
11
- disableSelection: true,
12
- roots: "A0000000000",
13
- onChange: onChange
14
- })))).add('No selection root opened', () => /*#__PURE__*/React.createElement(CustomDataProvider, {
8
+ }, /*#__PURE__*/React.createElement(StatefulMultiSelectionWrapper, null, _ref => {
9
+ let {
10
+ onChange
11
+ } = _ref;
12
+ return /*#__PURE__*/React.createElement(OrganisationUnitTree, {
13
+ disableSelection: true,
14
+ roots: "A0000000000",
15
+ onChange: onChange
16
+ });
17
+ }))).add('No selection root opened', () => /*#__PURE__*/React.createElement(CustomDataProvider, {
15
18
  data: dataProviderData
16
- }, /*#__PURE__*/React.createElement(StatefulMultiSelectionWrapper, null, ({
17
- onChange
18
- }) => /*#__PURE__*/React.createElement(OrganisationUnitTree, {
19
- disableSelection: true,
20
- roots: "A0000000000",
21
- onChange: onChange,
22
- initiallyExpanded: ['/A0000000000']
23
- }))));
19
+ }, /*#__PURE__*/React.createElement(StatefulMultiSelectionWrapper, null, _ref2 => {
20
+ let {
21
+ onChange
22
+ } = _ref2;
23
+ return /*#__PURE__*/React.createElement(OrganisationUnitTree, {
24
+ disableSelection: true,
25
+ roots: "A0000000000",
26
+ onChange: onChange,
27
+ initiallyExpanded: ['/A0000000000']
28
+ });
29
+ })));
@@ -6,25 +6,31 @@ import { StatefulMultiSelectionWrapper, dataProviderData, namespace } from './co
6
6
  window.allUnits = [];
7
7
 
8
8
  for (let i = 0; i < 7; ++i) {
9
- window.allUnits.push(`A000000000${i}`);
9
+ window.allUnits.push("A000000000".concat(i));
10
10
  }
11
11
 
12
12
  storiesOf(namespace, module).add('Filtered by 3-level-path', () => /*#__PURE__*/React.createElement(CustomDataProvider, {
13
13
  data: dataProviderData
14
- }, /*#__PURE__*/React.createElement(StatefulMultiSelectionWrapper, null, ({
15
- onChange
16
- }) => /*#__PURE__*/React.createElement(OrganisationUnitTree, {
17
- roots: "A0000000000",
18
- onChange: onChange,
19
- initiallyExpanded: ['/A0000000000', '/A0000000000/A0000000001', '/A0000000000/A0000000002'],
20
- filter: ['/A0000000000/A0000000001/A0000000003']
21
- })))).add('Filtered by 3-level-path and 2-level-path', () => /*#__PURE__*/React.createElement(CustomDataProvider, {
14
+ }, /*#__PURE__*/React.createElement(StatefulMultiSelectionWrapper, null, _ref => {
15
+ let {
16
+ onChange
17
+ } = _ref;
18
+ return /*#__PURE__*/React.createElement(OrganisationUnitTree, {
19
+ roots: "A0000000000",
20
+ onChange: onChange,
21
+ initiallyExpanded: ['/A0000000000', '/A0000000000/A0000000001', '/A0000000000/A0000000002'],
22
+ filter: ['/A0000000000/A0000000001/A0000000003']
23
+ });
24
+ }))).add('Filtered by 3-level-path and 2-level-path', () => /*#__PURE__*/React.createElement(CustomDataProvider, {
22
25
  data: dataProviderData
23
- }, /*#__PURE__*/React.createElement(StatefulMultiSelectionWrapper, null, ({
24
- onChange
25
- }) => /*#__PURE__*/React.createElement(OrganisationUnitTree, {
26
- roots: "A0000000000",
27
- onChange: onChange,
28
- initiallyExpanded: ['/A0000000000', '/A0000000000/A0000000001', '/A0000000000/A0000000002'],
29
- filter: ['/A0000000000/A0000000001/A0000000003', '/A0000000000/A0000000002']
30
- }))));
26
+ }, /*#__PURE__*/React.createElement(StatefulMultiSelectionWrapper, null, _ref2 => {
27
+ let {
28
+ onChange
29
+ } = _ref2;
30
+ return /*#__PURE__*/React.createElement(OrganisationUnitTree, {
31
+ roots: "A0000000000",
32
+ onChange: onChange,
33
+ initiallyExpanded: ['/A0000000000', '/A0000000000/A0000000001', '/A0000000000/A0000000002'],
34
+ filter: ['/A0000000000/A0000000001/A0000000003', '/A0000000000/A0000000002']
35
+ });
36
+ })));
@@ -4,7 +4,11 @@ import React from 'react';
4
4
  import { OrganisationUnitTree } from '../index.js';
5
5
  import { StatefulMultiSelectionWrapper, dataProviderData, namespace } from './common.js';
6
6
  const data = {
7
- organisationUnits: (...args) => {
7
+ organisationUnits: function () {
8
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
9
+ args[_key] = arguments[_key];
10
+ }
11
+
8
12
  const [, {
9
13
  id
10
14
  }] = args;
@@ -27,12 +31,15 @@ const data = {
27
31
  };
28
32
  storiesOf(namespace, module).add('Single selection', () => /*#__PURE__*/React.createElement(CustomDataProvider, {
29
33
  data: data
30
- }, /*#__PURE__*/React.createElement(StatefulMultiSelectionWrapper, null, ({
31
- selected,
32
- onChange
33
- }) => /*#__PURE__*/React.createElement(OrganisationUnitTree, {
34
- singleSelection: true,
35
- roots: ['A0000000000', 'A0000000001'],
36
- onChange: onChange,
37
- selected: selected
38
- }))));
34
+ }, /*#__PURE__*/React.createElement(StatefulMultiSelectionWrapper, null, _ref => {
35
+ let {
36
+ selected,
37
+ onChange
38
+ } = _ref;
39
+ return /*#__PURE__*/React.createElement(OrganisationUnitTree, {
40
+ singleSelection: true,
41
+ roots: ['A0000000000', 'A0000000001'],
42
+ onChange: onChange,
43
+ selected: selected
44
+ });
45
+ })));
@@ -5,10 +5,11 @@ export default {
5
5
  title: 'OrganisationUnitTree',
6
6
  decorators: [createDecoratorStatefulMultiSelection(), createDecoratorCustomDataProvider()]
7
7
  };
8
- export const MultipleRootSubAndOneMainOrgUnit = (_, {
9
- selected,
10
- onChange
11
- }) => {
8
+ export const MultipleRootSubAndOneMainOrgUnit = (_, _ref) => {
9
+ let {
10
+ selected,
11
+ onChange
12
+ } = _ref;
12
13
  const [filter, setFilter] = useState('');
13
14
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("input", {
14
15
  type: "input",
@@ -4,7 +4,11 @@ import React from 'react';
4
4
  import { OrganisationUnitTree } from '../index.js';
5
5
  import { StatefulMultiSelectionWrapper, dataProviderData, namespace } from './common.js';
6
6
  const customizedDataProviderData = {
7
- organisationUnits: (...args) => {
7
+ organisationUnits: function () {
8
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
9
+ args[_key] = arguments[_key];
10
+ }
11
+
8
12
  const [, {
9
13
  id,
10
14
  params
@@ -39,17 +43,20 @@ window.onExpand = window.Cypress && window.Cypress.cy.stub();
39
43
  window.onChildrenLoaded = window.Cypress && window.Cypress.cy.stub();
40
44
  storiesOf(namespace, module).add('Events', () => /*#__PURE__*/React.createElement(CustomDataProvider, {
41
45
  data: customizedDataProviderData
42
- }, /*#__PURE__*/React.createElement(StatefulMultiSelectionWrapper, null, ({
43
- selected,
44
- onChange
45
- }) => /*#__PURE__*/React.createElement(OrganisationUnitTree, {
46
- roots: "A0000000000",
47
- selected: selected,
48
- onChange: (...args) => {
49
- onChange(...args);
50
- window.onChange(...args);
51
- },
52
- onExpand: window.onExpand,
53
- onCollapse: window.onCollapse,
54
- onChildrenLoaded: window.onChildrenLoaded
55
- }))));
46
+ }, /*#__PURE__*/React.createElement(StatefulMultiSelectionWrapper, null, _ref => {
47
+ let {
48
+ selected,
49
+ onChange
50
+ } = _ref;
51
+ return /*#__PURE__*/React.createElement(OrganisationUnitTree, {
52
+ roots: "A0000000000",
53
+ selected: selected,
54
+ onChange: function () {
55
+ onChange(...arguments);
56
+ window.onChange(...arguments);
57
+ },
58
+ onExpand: window.onExpand,
59
+ onCollapse: window.onCollapse,
60
+ onChildrenLoaded: window.onChildrenLoaded
61
+ });
62
+ })));
@@ -7,17 +7,20 @@ export const CustomExpandedImperativeOpen = () => {
7
7
  const initiallyExpanded = getAllExpandedOrgUnitPaths([]);
8
8
  const [expanded, setExpanded] = useState(initiallyExpanded);
9
9
 
10
- const handleExpand = ({
11
- path
12
- }) => {
10
+ const handleExpand = _ref => {
11
+ let {
12
+ path
13
+ } = _ref;
14
+
13
15
  if (!expanded.includes(path)) {
14
16
  setExpanded([...expanded, path]);
15
17
  }
16
18
  };
17
19
 
18
- const handleCollapse = ({
19
- path
20
- }) => {
20
+ const handleCollapse = _ref2 => {
21
+ let {
22
+ path
23
+ } = _ref2;
21
24
  const pathIndex = expanded.indexOf(path);
22
25
 
23
26
  if (pathIndex !== -1) {
@@ -5,10 +5,12 @@ export const CustomNodeLabel = () => /*#__PURE__*/React.createElement(Organisati
5
5
  name: "Root org unit",
6
6
  roots: "A0000000000",
7
7
  initiallyExpanded: ['/A0000000000/A0000000001'],
8
- renderNodeLabel: ({
9
- label,
10
- node
11
- }) => {
8
+ renderNodeLabel: _ref => {
9
+ let {
10
+ label,
11
+ node
12
+ } = _ref;
13
+
12
14
  if (node.path !== '/A0000000000/A0000000001') {
13
15
  return label;
14
16
  }
@@ -4,11 +4,12 @@ import { DataProvider } from '@dhis2/app-runtime';
4
4
  import React, { useState } from 'react';
5
5
  import { OrganisationUnitTree } from '../index.js';
6
6
 
7
- const DX_onChange = (selected, setSelected, singleSelection) => ({
8
- id,
9
- path,
10
- checked
11
- }) => {
7
+ const DX_onChange = (selected, setSelected, singleSelection) => _ref => {
8
+ let {
9
+ id,
10
+ path,
11
+ checked
12
+ } = _ref;
12
13
  console.log('onChange', {
13
14
  path,
14
15
  id,
@@ -4,7 +4,11 @@ import { OrganisationUnitTree } from '../index.js';
4
4
  import { customData, onChange, onExpand, onCollapse, onChildrenLoaded } from './shared.js';
5
5
  export const LoadingErrorGrandchild = () => /*#__PURE__*/React.createElement(CustomDataProvider, {
6
6
  data: { ...customData,
7
- organisationUnits: (...args) => {
7
+ organisationUnits: function () {
8
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
9
+ args[_key] = arguments[_key];
10
+ }
11
+
8
12
  const [, {
9
13
  id
10
14
  }] = args;
@@ -4,7 +4,11 @@ import { OrganisationUnitTree } from '../index.js';
4
4
  import { customData, onChange } from './shared.js';
5
5
  export const Loading = () => /*#__PURE__*/React.createElement(CustomDataProvider, {
6
6
  data: { ...customData,
7
- organisationUnits: (...args) => {
7
+ organisationUnits: function () {
8
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
9
+ args[_key] = arguments[_key];
10
+ }
11
+
8
12
  const [, {
9
13
  id
10
14
  }] = args;
@@ -1,13 +1,16 @@
1
1
  import React from 'react';
2
2
  import { OrganisationUnitTree } from '../index.js';
3
3
  import { createDecoratorCustomDataProvider, createDecoratorStatefulMultiSelection } from './shared.js';
4
- export const MultipleRoots = (_, {
5
- onChange,
6
- selected
7
- }) => /*#__PURE__*/React.createElement(OrganisationUnitTree, {
8
- selected: selected,
9
- onChange: onChange,
10
- roots: ['A0000000000', 'A0000000001'],
11
- initiallyExpanded: ['/A0000000000/A0000000001']
12
- });
4
+ export const MultipleRoots = (_, _ref) => {
5
+ let {
6
+ onChange,
7
+ selected
8
+ } = _ref;
9
+ return /*#__PURE__*/React.createElement(OrganisationUnitTree, {
10
+ selected: selected,
11
+ onChange: onChange,
12
+ roots: ['A0000000000', 'A0000000001'],
13
+ initiallyExpanded: ['/A0000000000/A0000000001']
14
+ });
15
+ };
13
16
  MultipleRoots.decorators = [createDecoratorStatefulMultiSelection(), createDecoratorCustomDataProvider()];
@@ -4,7 +4,11 @@ import { OrganisationUnitTree } from '../index.js';
4
4
  import { customData, onChange } from './shared.js';
5
5
  export const RootError = () => /*#__PURE__*/React.createElement(CustomDataProvider, {
6
6
  data: { ...customData,
7
- organisationUnits: (...args) => {
7
+ organisationUnits: function () {
8
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
9
+ args[_key] = arguments[_key];
10
+ }
11
+
8
12
  const [, {
9
13
  id
10
14
  }] = args;
@@ -4,7 +4,11 @@ import { OrganisationUnitTree } from '../index.js';
4
4
  import { customData, onChange } from './shared.js';
5
5
  export const RootLoading = () => /*#__PURE__*/React.createElement(CustomDataProvider, {
6
6
  data: { ...customData,
7
- organisationUnits: (...args) => {
7
+ organisationUnits: function () {
8
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
9
+ args[_key] = arguments[_key];
10
+ }
11
+
8
12
  const [, {
9
13
  id
10
14
  }] = args;
@@ -2,37 +2,65 @@ import { CustomDataProvider } from '@dhis2/app-runtime';
2
2
  import PropTypes from 'prop-types';
3
3
  import React, { useState } from 'react';
4
4
  export const log = true;
5
- export const onChange = (...args) => log && console.log('onChange', ...args);
6
- export const onExpand = (...args) => log && console.log('onExpand', ...args);
7
- export const onCollapse = (...args) => log && console.log('onCollapse', ...args);
8
- export const onChildrenLoaded = (...args) => log && console.log('onChildrenLoaded', ...args);
9
-
10
- const createResponse = ({
11
- fields,
12
- id,
13
- path,
14
- displayName,
15
- children
16
- }) => ({ ...(fields.includes('id') ? {
17
- id
18
- } : {}),
19
- ...(fields.includes('path') ? {
20
- path
21
- } : {}),
22
- ...(fields.includes('displayName') ? {
23
- displayName
24
- } : {}),
25
- ...(fields.includes('children::size') ? {
26
- children: children.length
27
- } : {}),
28
- ...(fields.includes('children[id,path,displayName]') ? {
5
+ export const onChange = function () {
6
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
7
+ args[_key] = arguments[_key];
8
+ }
9
+
10
+ return log && console.log('onChange', ...args);
11
+ };
12
+ export const onExpand = function () {
13
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
14
+ args[_key2] = arguments[_key2];
15
+ }
16
+
17
+ return log && console.log('onExpand', ...args);
18
+ };
19
+ export const onCollapse = function () {
20
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
21
+ args[_key3] = arguments[_key3];
22
+ }
23
+
24
+ return log && console.log('onCollapse', ...args);
25
+ };
26
+ export const onChildrenLoaded = function () {
27
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
28
+ args[_key4] = arguments[_key4];
29
+ }
30
+
31
+ return log && console.log('onChildrenLoaded', ...args);
32
+ };
33
+
34
+ const createResponse = _ref => {
35
+ let {
36
+ fields,
37
+ id,
38
+ path,
39
+ displayName,
29
40
  children
30
- } : {})
31
- });
41
+ } = _ref;
42
+ return { ...(fields.includes('id') ? {
43
+ id
44
+ } : {}),
45
+ ...(fields.includes('path') ? {
46
+ path
47
+ } : {}),
48
+ ...(fields.includes('displayName') ? {
49
+ displayName
50
+ } : {}),
51
+ ...(fields.includes('children::size') ? {
52
+ children: children.length
53
+ } : {}),
54
+ ...(fields.includes('children[id,path,displayName]') ? {
55
+ children
56
+ } : {})
57
+ };
58
+ };
32
59
 
33
- export const getOrganisationUnitData = (id, {
34
- fields
35
- }) => {
60
+ export const getOrganisationUnitData = (id, _ref2) => {
61
+ let {
62
+ fields
63
+ } = _ref2;
36
64
  let data;
37
65
 
38
66
  if (id === 'A0000000000') {
@@ -142,10 +170,11 @@ export const getOrganisationUnitData = (id, {
142
170
  return data;
143
171
  };
144
172
  export const customData = {
145
- organisationUnits: (_, {
146
- id,
147
- params = {}
148
- }) => {
173
+ organisationUnits: (_, _ref3) => {
174
+ let {
175
+ id,
176
+ params = {}
177
+ } = _ref3;
149
178
  const data = getOrganisationUnitData(id, params);
150
179
 
151
180
  if (!data) {
@@ -155,14 +184,19 @@ export const customData = {
155
184
  return Promise.resolve(data);
156
185
  }
157
186
  };
158
- export const StatefulMultiSelectionWrapper = ({
159
- children,
160
- onSelectionChange = () => null
161
- }) => {
187
+ export const StatefulMultiSelectionWrapper = _ref4 => {
188
+ let {
189
+ children,
190
+ onSelectionChange = () => null
191
+ } = _ref4;
162
192
  const [selected, setSelected] = useState([]);
163
193
  return children({
164
194
  selected,
165
- onChange: (...args) => {
195
+ onChange: function () {
196
+ for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
197
+ args[_key5] = arguments[_key5];
198
+ }
199
+
166
200
  onChange(...args);
167
201
  const [{
168
202
  selected: newSelected
@@ -179,13 +213,16 @@ StatefulMultiSelectionWrapper.propTypes = {
179
213
  export const createDecoratorStatefulMultiSelection = args => {
180
214
  return Story => /*#__PURE__*/React.createElement(StatefulMultiSelectionWrapper, {
181
215
  onSelectionChange: args === null || args === void 0 ? void 0 : args.onSelectionChange
182
- }, ({
183
- selected,
184
- onChange
185
- }) => /*#__PURE__*/React.createElement(Story, {
186
- selected: selected,
187
- onChange: onChange
188
- }));
216
+ }, _ref5 => {
217
+ let {
218
+ selected,
219
+ onChange
220
+ } = _ref5;
221
+ return /*#__PURE__*/React.createElement(Story, {
222
+ selected: selected,
223
+ onChange: onChange
224
+ });
225
+ });
189
226
  };
190
227
  export const createDecoratorCustomDataProvider = args => {
191
228
  const data = (args === null || args === void 0 ? void 0 : args.data) || customData;
@@ -6,7 +6,7 @@ const expectOrgUnitsToBeDisplayed = ids => {
6
6
  fields: ['displayName']
7
7
  }).displayName);
8
8
  expandedLabels.forEach(label => {
9
- cy.get(`:contains("${label}")`).should('exist');
9
+ cy.get(":contains(\"".concat(label, "\")")).should('exist');
10
10
  });
11
11
  };
12
12
 
@@ -18,7 +18,7 @@ const expectOrgUnitsToNotBeDisplayed = ids => {
18
18
  return data.displayName;
19
19
  });
20
20
  expandedLabels.forEach(label => {
21
- cy.get(`:contains("${label}")`).should('not.exist');
21
+ cy.get(":contains(\"".concat(label, "\")")).should('not.exist');
22
22
  });
23
23
  };
24
24
 
@@ -53,9 +53,12 @@ Then('the path should close', () => {
53
53
  const curData = getOrganisationUnitData(cur, {
54
54
  fields: ['children[id,path,displayName]']
55
55
  });
56
- const childrenIds = curData.children.map(({
57
- id
58
- }) => id);
56
+ const childrenIds = curData.children.map(_ref => {
57
+ let {
58
+ id
59
+ } = _ref;
60
+ return id;
61
+ });
59
62
  return [...acc, ...childrenIds];
60
63
  }, []);
61
64
  expectOrgUnitsToNotBeDisplayed(hiddenChildrenIds);
@@ -1,13 +1,7 @@
1
1
  import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps';
2
2
 
3
3
  const getRootOrgUnitByLabel = label => {
4
- const rootOrgUnitLabelSelector = `
5
- [data-test="dhis2-uiwidgets-orgunittree"]
6
- > [data-test="dhis2-uiwidgets-orgunittree-node"]
7
- > [data-test="dhis2-uiwidgets-orgunittree-node-content"]
8
- > [data-test="dhis2-uiwidgets-orgunittree-node-label"]
9
- label
10
- `;
4
+ const rootOrgUnitLabelSelector = "\n [data-test=\"dhis2-uiwidgets-orgunittree\"]\n > [data-test=\"dhis2-uiwidgets-orgunittree-node\"]\n > [data-test=\"dhis2-uiwidgets-orgunittree-node-content\"]\n > [data-test=\"dhis2-uiwidgets-orgunittree-node-label\"]\n label\n ";
11
5
  return cy.contains(rootOrgUnitLabelSelector, label).parents('[data-test="dhis2-uiwidgets-orgunittree-node"]');
12
6
  };
13
7
 
@@ -52,8 +52,8 @@ Then('all other nodes are not rendered', async () => {
52
52
  cy.window().then(win => {
53
53
  const excludedUnitNumbers = win.allUnits.filter(unit => !displayedUnits.includes(unit)).map(id => parseInt(id.replace(/^.*(\d)$/, '$1'), 10) + 1);
54
54
  excludedUnitNumbers.forEach(number => {
55
- const label = `Org Unit ${number}`;
56
- cy.get(`[data-test="dhis2-uiwidgets-orgunittree-node-label"]:contains("${label}")`).should('not.exist');
55
+ const label = "Org Unit ".concat(number);
56
+ cy.get("[data-test=\"dhis2-uiwidgets-orgunittree-node-label\"]:contains(\"".concat(label, "\")")).should('not.exist');
57
57
  });
58
58
  });
59
59
  });
@@ -1,11 +1,5 @@
1
1
  import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps';
2
- const rootOrgUnitLabelSelector = `
3
- [data-test="dhis2-uiwidgets-orgunittree"]
4
- > [data-test="dhis2-uiwidgets-orgunittree-node"]
5
- > [data-test="dhis2-uiwidgets-orgunittree-node-content"]
6
- > [data-test="dhis2-uiwidgets-orgunittree-node-label"]
7
- label
8
- `;
2
+ const rootOrgUnitLabelSelector = "\n [data-test=\"dhis2-uiwidgets-orgunittree\"]\n > [data-test=\"dhis2-uiwidgets-orgunittree-node\"]\n > [data-test=\"dhis2-uiwidgets-orgunittree-node-content\"]\n > [data-test=\"dhis2-uiwidgets-orgunittree-node-label\"]\n label\n";
9
3
  Given('a sub org unit is a root org unit', () => {
10
4
  cy.visitStory('OrganisationUnitTree', 'multiple root sub and one main org unit');
11
5
  });
@@ -15,7 +15,7 @@ const extractAllPathsFromPath = path => {
15
15
  const segments = path.replace(/^\//, '').split('/');
16
16
  const withSubPaths = segments.map((segment, index) => {
17
17
  // take all segments from 0 to index and join them with the delimiter
18
- return `/${segments.slice(0, index + 1).join('/')}`;
18
+ return "/".concat(segments.slice(0, index + 1).join('/'));
19
19
  });
20
20
  return removeDuplicates(withSubPaths);
21
21
  };
@@ -9,7 +9,7 @@ export const isPathIncluded = (includedPaths, path) => {
9
9
  return true;
10
10
  }
11
11
 
12
- return includedPath.startsWith(`${path}/`);
12
+ return includedPath.startsWith("".concat(path, "/"));
13
13
  });
14
14
  return isIncluded;
15
15
  };
@@ -1,3 +1,3 @@
1
1
  export const leftTrimToRootId = (path, rootId) => {
2
- return path.replace(new RegExp(`^.*(/${rootId})`), '$1');
2
+ return path.replace(new RegExp("^.*(/".concat(rootId, ")")), '$1');
3
3
  };
@@ -22,6 +22,6 @@ export const computeChildNodes = (node, filter) => {
22
22
  }
23
23
 
24
24
  return node.children.filter(child => {
25
- return isPathIncluded(filter, `${node.path}/${child.id}`);
25
+ return isPathIncluded(filter, "".concat(node.path, "/").concat(child.id));
26
26
  });
27
27
  };