@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
@@ -11,27 +11,28 @@ import { LoadingSpinner } from './loading-spinner.js';
11
11
  import { OrganisationUnitNodeChildren } from './organisation-unit-node-children.js';
12
12
  import { useOpenState } from './use-open-state.js';
13
13
  import { useOrgData } from './use-org-data/index.js';
14
- export const OrganisationUnitNode = ({
15
- autoExpandLoadingError,
16
- dataTest,
17
- disableSelection,
18
- displayName,
19
- expanded,
20
- highlighted,
21
- id,
22
- isUserDataViewFallback,
23
- path,
24
- renderNodeLabel,
25
- rootId,
26
- selected,
27
- singleSelection,
28
- filter,
29
- suppressAlphabeticalSorting,
30
- onChange,
31
- onChildrenLoaded,
32
- onCollapse,
33
- onExpand
34
- }) => {
14
+ export const OrganisationUnitNode = _ref => {
15
+ let {
16
+ autoExpandLoadingError,
17
+ dataTest,
18
+ disableSelection,
19
+ displayName,
20
+ expanded,
21
+ highlighted,
22
+ id,
23
+ isUserDataViewFallback,
24
+ path,
25
+ renderNodeLabel,
26
+ rootId,
27
+ selected,
28
+ singleSelection,
29
+ filter,
30
+ suppressAlphabeticalSorting,
31
+ onChange,
32
+ onChildrenLoaded,
33
+ onCollapse,
34
+ onExpand
35
+ } = _ref;
35
36
  const orgData = useOrgData(id, {
36
37
  isUserDataViewFallback,
37
38
  displayName
@@ -59,7 +60,7 @@ export const OrganisationUnitNode = ({
59
60
  onExpand,
60
61
  onCollapse
61
62
  });
62
- const isSelected = !!selected.find(curPath => curPath.match(new RegExp(`${strippedPath}$`)));
63
+ const isSelected = !!selected.find(curPath => curPath.match(new RegExp("".concat(strippedPath, "$"))));
63
64
  const labelContent = renderNodeLabel({
64
65
  disableSelection,
65
66
  hasChildren,
@@ -83,7 +84,7 @@ export const OrganisationUnitNode = ({
83
84
  checked: isSelected,
84
85
  rootId: rootId,
85
86
  onChange: onChange,
86
- dataTest: `${dataTest}-label`,
87
+ dataTest: "".concat(dataTest, "-label"),
87
88
  selected: selected,
88
89
  hasChildren: hasChildren,
89
90
  highlighted: isHighlighted,
@@ -106,7 +107,7 @@ export const OrganisationUnitNode = ({
106
107
  const showPlaceholder = hasChildren && !open && !orgData.error;
107
108
  const showChildNodes = hasChildren && open && !orgData.error;
108
109
  return /*#__PURE__*/React.createElement(Node, {
109
- dataTest: `${dataTest}-node`,
110
+ dataTest: "".concat(dataTest, "-node"),
110
111
  open: open,
111
112
  onOpen: onToggleOpen,
112
113
  onClose: onToggleOpen,
@@ -115,7 +116,7 @@ export const OrganisationUnitNode = ({
115
116
  }, orgData.error && /*#__PURE__*/React.createElement(ErrorMessage, {
116
117
  dataTest: dataTest
117
118
  }, i18n.t('Could not load children')), showPlaceholder && /*#__PURE__*/React.createElement("span", {
118
- "data-test": `${dataTest}-placeholder`
119
+ "data-test": "".concat(dataTest, "-placeholder")
119
120
  }), showChildNodes && /*#__PURE__*/React.createElement(OrganisationUnitNodeChildren // Prevent cirular imports
120
121
  , {
121
122
  OrganisationUnitNode: OrganisationUnitNode,
@@ -10,14 +10,15 @@ import { useEffect, useState } from 'react';
10
10
  * @returns {Object}
11
11
  */
12
12
 
13
- export const useOpenState = ({
14
- path,
15
- expanded,
16
- onExpand,
17
- onCollapse,
18
- errorMessage,
19
- autoExpandLoadingError
20
- }) => {
13
+ export const useOpenState = _ref => {
14
+ let {
15
+ path,
16
+ expanded,
17
+ onExpand,
18
+ onCollapse,
19
+ errorMessage,
20
+ autoExpandLoadingError
21
+ } = _ref;
21
22
  const autoExpand = autoExpandLoadingError && !!errorMessage;
22
23
  const [openedOnceDueToError, setOpenedOnce] = useState(!!errorMessage);
23
24
  useEffect(() => {
@@ -3,10 +3,13 @@ import { useMemo, useEffect, useRef } from 'react';
3
3
  import { sortNodeChildrenAlphabetically } from '../helpers/index.js';
4
4
  const ORG_DATA_QUERY = {
5
5
  orgUnit: {
6
- resource: `organisationUnits`,
7
- id: ({
8
- id
9
- }) => id,
6
+ resource: "organisationUnits",
7
+ id: _ref => {
8
+ let {
9
+ id
10
+ } = _ref;
11
+ return id;
12
+ },
10
13
  params: {
11
14
  fields: 'children[id,path,displayName]'
12
15
  }
@@ -20,11 +23,12 @@ const ORG_DATA_QUERY = {
20
23
  * @returns {Object}
21
24
  */
22
25
 
23
- export const useOrgChildren = ({
24
- node,
25
- suppressAlphabeticalSorting,
26
- onComplete
27
- }) => {
26
+ export const useOrgChildren = _ref2 => {
27
+ let {
28
+ node,
29
+ suppressAlphabeticalSorting,
30
+ onComplete
31
+ } = _ref2;
28
32
  const onCompleteCalledRef = useRef(false);
29
33
  const {
30
34
  called,
@@ -4,9 +4,11 @@ import React from 'react';
4
4
  import { useOrgChildren } from './use-org-children.js';
5
5
  describe('OrganisationUnitTree - useOrgChildren', () => {
6
6
  const dataProviderData = {
7
- organisationUnits: jest.fn((type, {
8
- id
9
- }) => {
7
+ organisationUnits: jest.fn((type, _ref) => {
8
+ let {
9
+ id
10
+ } = _ref;
11
+
10
12
  if (id === 'A0000000000') {
11
13
  return {
12
14
  children: [{
@@ -18,15 +20,18 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
18
20
  };
19
21
  }
20
22
 
21
- return Promise.reject(`No org unit with id "${id}"`);
23
+ return Promise.reject("No org unit with id \"".concat(id, "\""));
22
24
  })
23
25
  };
24
26
 
25
- const wrapper = ({
26
- children
27
- }) => /*#__PURE__*/React.createElement(CustomDataProvider, {
28
- data: dataProviderData
29
- }, children);
27
+ const wrapper = _ref2 => {
28
+ let {
29
+ children
30
+ } = _ref2;
31
+ return /*#__PURE__*/React.createElement(CustomDataProvider, {
32
+ data: dataProviderData
33
+ }, children);
34
+ };
30
35
 
31
36
  const node = {
32
37
  id: 'A0000000000',
@@ -77,15 +82,18 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
77
82
  });
78
83
  });
79
84
  it('should provide the error', async () => {
80
- const errorWrapper = ({
81
- children
82
- }) => /*#__PURE__*/React.createElement(CustomDataProvider, {
83
- data: {
84
- organisationUnits: async () => {
85
- throw new Error('Error message');
85
+ const errorWrapper = _ref3 => {
86
+ let {
87
+ children
88
+ } = _ref3;
89
+ return /*#__PURE__*/React.createElement(CustomDataProvider, {
90
+ data: {
91
+ organisationUnits: async () => {
92
+ throw new Error('Error message');
93
+ }
86
94
  }
87
- }
88
- }, children);
95
+ }, children);
96
+ };
89
97
 
90
98
  const {
91
99
  result,
@@ -129,9 +137,11 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
129
137
  });
130
138
  it("should sort the node's children alphabetically by default", async () => {
131
139
  const dataProviderDataWithUnsortedChildren = {
132
- organisationUnits: jest.fn((type, {
133
- id
134
- }) => {
140
+ organisationUnits: jest.fn((type, _ref4) => {
141
+ let {
142
+ id
143
+ } = _ref4;
144
+
135
145
  if (id === 'A0000000000') {
136
146
  return {
137
147
  children: [{
@@ -148,15 +158,18 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
148
158
  };
149
159
  }
150
160
 
151
- return Promise.reject(`No org unit with id "${id}"`);
161
+ return Promise.reject("No org unit with id \"".concat(id, "\""));
152
162
  })
153
163
  };
154
164
 
155
- const wrapperWithUnsortedChildren = ({
156
- children
157
- }) => /*#__PURE__*/React.createElement(CustomDataProvider, {
158
- data: dataProviderDataWithUnsortedChildren
159
- }, children);
165
+ const wrapperWithUnsortedChildren = _ref5 => {
166
+ let {
167
+ children
168
+ } = _ref5;
169
+ return /*#__PURE__*/React.createElement(CustomDataProvider, {
170
+ data: dataProviderDataWithUnsortedChildren
171
+ }, children);
172
+ };
160
173
 
161
174
  const {
162
175
  result,
@@ -186,11 +199,13 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
186
199
  }]
187
200
  });
188
201
  });
189
- it(`should not sort the node's children alphabetically when "suppressAlphabeticalSorting" is true`, async () => {
202
+ it("should not sort the node's children alphabetically when \"suppressAlphabeticalSorting\" is true", async () => {
190
203
  const dataProviderDataWithUnsortedChildren = {
191
- organisationUnits: jest.fn((type, {
192
- id
193
- }) => {
204
+ organisationUnits: jest.fn((type, _ref6) => {
205
+ let {
206
+ id
207
+ } = _ref6;
208
+
194
209
  if (id === 'A0000000000') {
195
210
  return {
196
211
  children: [{
@@ -207,15 +222,18 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
207
222
  };
208
223
  }
209
224
 
210
- return Promise.reject(`No org unit with id "${id}"`);
225
+ return Promise.reject("No org unit with id \"".concat(id, "\""));
211
226
  })
212
227
  };
213
228
 
214
- const wrapperWithUnsortedChildren = ({
215
- children
216
- }) => /*#__PURE__*/React.createElement(CustomDataProvider, {
217
- data: dataProviderDataWithUnsortedChildren
218
- }, children);
229
+ const wrapperWithUnsortedChildren = _ref7 => {
230
+ let {
231
+ children
232
+ } = _ref7;
233
+ return /*#__PURE__*/React.createElement(CustomDataProvider, {
234
+ data: dataProviderDataWithUnsortedChildren
235
+ }, children);
236
+ };
219
237
 
220
238
  const options = {
221
239
  node: { ...node,
@@ -247,11 +265,13 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
247
265
  }]
248
266
  });
249
267
  });
250
- it(`should not sort the node's children alphabetically when "suppressAlphabeticalSorting" is true`, async () => {
268
+ it("should not sort the node's children alphabetically when \"suppressAlphabeticalSorting\" is true", async () => {
251
269
  const dataProviderDataWithUnsortedChildren = {
252
- organisationUnits: jest.fn((type, {
253
- id
254
- }) => {
270
+ organisationUnits: jest.fn((type, _ref8) => {
271
+ let {
272
+ id
273
+ } = _ref8;
274
+
255
275
  if (id === 'A0000000000') {
256
276
  return {
257
277
  children: [{
@@ -268,15 +288,18 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
268
288
  };
269
289
  }
270
290
 
271
- return Promise.reject(`No org unit with id "${id}"`);
291
+ return Promise.reject("No org unit with id \"".concat(id, "\""));
272
292
  })
273
293
  };
274
294
 
275
- const wrapperWithUnsortedChildren = ({
276
- children
277
- }) => /*#__PURE__*/React.createElement(CustomDataProvider, {
278
- data: dataProviderDataWithUnsortedChildren
279
- }, children);
295
+ const wrapperWithUnsortedChildren = _ref9 => {
296
+ let {
297
+ children
298
+ } = _ref9;
299
+ return /*#__PURE__*/React.createElement(CustomDataProvider, {
300
+ data: dataProviderDataWithUnsortedChildren
301
+ }, children);
302
+ };
280
303
 
281
304
  const options = {
282
305
  node: { ...node,
@@ -1,16 +1,22 @@
1
1
  import { useDataQuery } from '@dhis2/app-runtime';
2
2
  const ORG_DATA_QUERY = {
3
3
  orgUnit: {
4
- resource: `organisationUnits`,
5
- id: ({
6
- id
7
- }) => id,
8
- params: ({
9
- isUserDataViewFallback
10
- }) => ({
11
- isUserDataViewFallback,
12
- fields: ['path', 'children::size']
13
- })
4
+ resource: "organisationUnits",
5
+ id: _ref => {
6
+ let {
7
+ id
8
+ } = _ref;
9
+ return id;
10
+ },
11
+ params: _ref2 => {
12
+ let {
13
+ isUserDataViewFallback
14
+ } = _ref2;
15
+ return {
16
+ isUserDataViewFallback,
17
+ fields: ['path', 'children::size']
18
+ };
19
+ }
14
20
  }
15
21
  };
16
22
  /**
@@ -21,10 +27,12 @@ const ORG_DATA_QUERY = {
21
27
  * @returns {Object}
22
28
  */
23
29
 
24
- export const useOrgData = (id, {
25
- displayName,
26
- isUserDataViewFallback
27
- }) => {
30
+ export const useOrgData = (id, _ref3) => {
31
+ let {
32
+ displayName,
33
+ isUserDataViewFallback
34
+ } = _ref3;
35
+
28
36
  if (!displayName) {
29
37
  throw new Error('"displayName" is required');
30
38
  }
@@ -5,7 +5,11 @@ import { useOrgData } from './use-org-data.js';
5
5
  describe('OrganisationUnitTree - useOrgData', () => {
6
6
  // @TODO: Figure out why this is necessary at all...
7
7
  const origError = console.error;
8
- jest.spyOn(console, 'error').mockImplementation((...args) => {
8
+ jest.spyOn(console, 'error').mockImplementation(function () {
9
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
10
+ args[_key] = arguments[_key];
11
+ }
12
+
9
13
  const [err] = args;
10
14
 
11
15
  if (!err.toString().match(/^Warning: An update to/)) {
@@ -16,9 +20,11 @@ describe('OrganisationUnitTree - useOrgData', () => {
16
20
  console.error.mockRestore();
17
21
  });
18
22
  const dataProviderData = {
19
- organisationUnits: jest.fn((type, {
20
- id
21
- }) => {
23
+ organisationUnits: jest.fn((type, _ref) => {
24
+ let {
25
+ id
26
+ } = _ref;
27
+
22
28
  if (id === 'A0000000000') {
23
29
  return {
24
30
  id: 'A0000000000',
@@ -27,15 +33,18 @@ describe('OrganisationUnitTree - useOrgData', () => {
27
33
  };
28
34
  }
29
35
 
30
- return Promise.reject(`No org unit with id "${id}"`);
36
+ return Promise.reject("No org unit with id \"".concat(id, "\""));
31
37
  })
32
38
  };
33
39
 
34
- const wrapper = ({
35
- children
36
- }) => /*#__PURE__*/React.createElement(CustomDataProvider, {
37
- data: dataProviderData
38
- }, children);
40
+ const wrapper = _ref2 => {
41
+ let {
42
+ children
43
+ } = _ref2;
44
+ return /*#__PURE__*/React.createElement(CustomDataProvider, {
45
+ data: dataProviderData
46
+ }, children);
47
+ };
39
48
 
40
49
  it('should respond with `loading: true`, `error: null` and `data: { displayName, id }` initially', () => {
41
50
  const {
@@ -75,15 +84,18 @@ describe('OrganisationUnitTree - useOrgData', () => {
75
84
  });
76
85
  });
77
86
  it('should provide the error', async () => {
78
- const errorWrapper = ({
79
- children
80
- }) => /*#__PURE__*/React.createElement(CustomDataProvider, {
81
- data: {
82
- organisationUnits: async () => {
83
- throw new Error('Error message');
87
+ const errorWrapper = _ref3 => {
88
+ let {
89
+ children
90
+ } = _ref3;
91
+ return /*#__PURE__*/React.createElement(CustomDataProvider, {
92
+ data: {
93
+ organisationUnits: async () => {
94
+ throw new Error('Error message');
95
+ }
84
96
  }
85
- }
86
- }, children);
97
+ }, children);
98
+ };
87
99
 
88
100
  const {
89
101
  result,
@@ -1,3 +1,6 @@
1
- export const defaultRenderNodeLabel = ({
2
- label
3
- }) => label;
1
+ export const defaultRenderNodeLabel = _ref => {
2
+ let {
3
+ label
4
+ } = _ref;
5
+ return label;
6
+ };
@@ -4,5 +4,5 @@ export const filterRootIds = (filter, rootIds) => {
4
4
  return rootIds;
5
5
  }
6
6
 
7
- return rootIds.filter(rootId => isPathIncluded(filter, `/${rootId}`));
7
+ return rootIds.filter(rootId => isPathIncluded(filter, "/".concat(rootId)));
8
8
  };
@@ -11,28 +11,29 @@ import { useExpanded } from './use-expanded/index.js';
11
11
  import { useForceReload } from './use-force-reload.js';
12
12
  import { useRootOrgData } from './use-root-org-data/index.js';
13
13
 
14
- const OrganisationUnitTree = ({
15
- onChange,
16
- roots,
17
- autoExpandLoadingError,
18
- dataTest,
19
- disableSelection,
20
- forceReload,
21
- highlighted,
22
- isUserDataViewFallback,
23
- initiallyExpanded,
24
- filter,
25
- renderNodeLabel,
26
- selected,
27
- singleSelection,
28
- suppressAlphabeticalSorting,
29
- expanded: expandedControlled,
30
- handleExpand: handleExpandControlled,
31
- handleCollapse: handleCollapseControlled,
32
- onExpand,
33
- onCollapse,
34
- onChildrenLoaded
35
- }) => {
14
+ const OrganisationUnitTree = _ref => {
15
+ let {
16
+ onChange,
17
+ roots,
18
+ autoExpandLoadingError,
19
+ dataTest,
20
+ disableSelection,
21
+ forceReload,
22
+ highlighted,
23
+ isUserDataViewFallback,
24
+ initiallyExpanded,
25
+ filter,
26
+ renderNodeLabel,
27
+ selected,
28
+ singleSelection,
29
+ suppressAlphabeticalSorting,
30
+ expanded: expandedControlled,
31
+ handleExpand: handleExpandControlled,
32
+ handleCollapse: handleCollapseControlled,
33
+ onExpand,
34
+ onCollapse,
35
+ onChildrenLoaded
36
+ } = _ref;
36
37
  const rootIds = filterRootIds(filter, Array.isArray(roots) ? roots : [roots]);
37
38
  const reloadId = useForceReload(forceReload);
38
39
  const [prevReloadId, setPrevReloadId] = useState(reloadId);
@@ -1,15 +1,18 @@
1
1
  import PropTypes from 'prop-types';
2
2
  import React from 'react';
3
3
  import i18n from '../locales/index.js';
4
- export const RootError = ({
5
- dataTest,
6
- error
7
- }) => /*#__PURE__*/React.createElement("div", {
8
- "data-test": dataTest
9
- }, i18n.t('Error: {{ ERRORMESSAGE }}', {
10
- ERRORMESSAGE: error,
11
- nsSeparator: '>'
12
- }));
4
+ export const RootError = _ref => {
5
+ let {
6
+ dataTest,
7
+ error
8
+ } = _ref;
9
+ return /*#__PURE__*/React.createElement("div", {
10
+ "data-test": dataTest
11
+ }, i18n.t('Error: {{ ERRORMESSAGE }}', {
12
+ ERRORMESSAGE: error,
13
+ nsSeparator: '>'
14
+ }));
15
+ };
13
16
  RootError.defaultProps = {
14
17
  dataTest: 'dhis2-uiwidgets-orgunittree-error'
15
18
  };
@@ -2,16 +2,19 @@ import _JSXStyle from "styled-jsx/style";
2
2
  import { CircularLoader } from '@dhis2-ui/loader';
3
3
  import PropTypes from 'prop-types';
4
4
  import React from 'react';
5
- export const RootLoading = ({
6
- dataTest
7
- }) => /*#__PURE__*/React.createElement("div", {
8
- "data-test": dataTest,
9
- className: "jsx-814846266"
10
- }, /*#__PURE__*/React.createElement(CircularLoader, {
11
- small: true
12
- }), /*#__PURE__*/React.createElement(_JSXStyle, {
13
- id: "814846266"
14
- }, ["div.jsx-814846266{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;}"]));
5
+ export const RootLoading = _ref => {
6
+ let {
7
+ dataTest
8
+ } = _ref;
9
+ return /*#__PURE__*/React.createElement("div", {
10
+ "data-test": dataTest,
11
+ className: "jsx-814846266"
12
+ }, /*#__PURE__*/React.createElement(CircularLoader, {
13
+ small: true
14
+ }), /*#__PURE__*/React.createElement(_JSXStyle, {
15
+ id: "814846266"
16
+ }, ["div.jsx-814846266{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;}"]));
17
+ };
15
18
  RootLoading.defaultProps = {
16
19
  dataTest: 'dhis2-uiwidgets-orgunittree-loading'
17
20
  };
@@ -6,16 +6,20 @@
6
6
  * @param {Function} [args.onCollapse]
7
7
  * @returns {{ handleExpand: Function, handleCollapse: Function }}
8
8
  */
9
- export const createExpandHandlers = ({
10
- expanded,
11
- setExpanded,
12
- onExpand,
13
- onCollapse
14
- }) => {
15
- const handleExpand = ({
16
- path,
17
- ...rest
18
- }) => {
9
+ export const createExpandHandlers = _ref => {
10
+ let {
11
+ expanded,
12
+ setExpanded,
13
+ onExpand,
14
+ onCollapse
15
+ } = _ref;
16
+
17
+ const handleExpand = _ref2 => {
18
+ let {
19
+ path,
20
+ ...rest
21
+ } = _ref2;
22
+
19
23
  if (!expanded.includes(path)) {
20
24
  setExpanded([...expanded, path]);
21
25
 
@@ -28,10 +32,11 @@ export const createExpandHandlers = ({
28
32
  }
29
33
  };
30
34
 
31
- const handleCollapse = ({
32
- path,
33
- ...rest
34
- }) => {
35
+ const handleCollapse = _ref3 => {
36
+ let {
37
+ path,
38
+ ...rest
39
+ } = _ref3;
35
40
  const pathIndex = expanded.indexOf(path);
36
41
 
37
42
  if (pathIndex !== -1) {
@@ -8,14 +8,15 @@ import { createExpandHandlers } from './create-expand-handlers.js';
8
8
  * @returns {{ expanded: string[], handleExpand: Function, handleCollapse: Function }}
9
9
  */
10
10
 
11
- export const useExpanded = ({
12
- initiallyExpanded,
13
- onExpand,
14
- onCollapse,
15
- expandedControlled,
16
- handleExpandControlled,
17
- handleCollapseControlled
18
- }) => {
11
+ export const useExpanded = _ref => {
12
+ let {
13
+ initiallyExpanded,
14
+ onExpand,
15
+ onCollapse,
16
+ expandedControlled,
17
+ handleExpandControlled,
18
+ handleCollapseControlled
19
+ } = _ref;
19
20
  const isControlled = !!expandedControlled;
20
21
  const allInitiallyExpandedPaths = isControlled ? [] : getAllExpandedPaths(initiallyExpanded);
21
22
  const [expanded, setExpanded] = useState(allInitiallyExpandedPaths);