@dhis2-ui/organisation-unit-tree 10.16.3-alpha.1 → 10.16.4

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 (110) hide show
  1. package/build/cjs/__e2e__/children_as_child_nodes.js +8 -11
  2. package/build/cjs/__e2e__/common.js +19 -26
  3. package/build/cjs/__e2e__/controlled_expanded.js +7 -10
  4. package/build/cjs/__e2e__/displaying_loading_error.js +1 -4
  5. package/build/cjs/__e2e__/expanded.js +25 -34
  6. package/build/cjs/__e2e__/force_reload.js +15 -22
  7. package/build/cjs/__e2e__/get-organisation-unit-data.js +25 -29
  8. package/build/cjs/__e2e__/highlight.js +7 -10
  9. package/build/cjs/__e2e__/loading_state.js +7 -13
  10. package/build/cjs/__e2e__/multi_selection.js +8 -11
  11. package/build/cjs/__e2e__/no_selection.js +15 -21
  12. package/build/cjs/__e2e__/path_based_filtering.js +16 -22
  13. package/build/cjs/__e2e__/single_selection.js +10 -16
  14. package/build/cjs/__e2e__/sub_unit_as_root.js +5 -7
  15. package/build/cjs/__e2e__/tree_api.js +15 -21
  16. package/build/cjs/__stories__/custom-expanded-imperative-open.js +7 -10
  17. package/build/cjs/__stories__/custom-node-label.js +4 -5
  18. package/build/cjs/__stories__/development-stories.js +6 -8
  19. package/build/cjs/__stories__/force-reload-all.js +1 -2
  20. package/build/cjs/__stories__/loading-error-grandchild.js +1 -4
  21. package/build/cjs/__stories__/loading.js +1 -4
  22. package/build/cjs/__stories__/multiple-roots.js +9 -12
  23. package/build/cjs/__stories__/root-error.js +1 -4
  24. package/build/cjs/__stories__/root-loading.js +1 -4
  25. package/build/cjs/__stories__/shared.js +46 -79
  26. package/build/cjs/features/controlled_expanded/index.js +3 -6
  27. package/build/cjs/locales/index.js +49 -27
  28. package/build/cjs/organisation-unit-node/error-message.js +10 -13
  29. package/build/cjs/organisation-unit-node/label/disabled-selection-label.js +9 -12
  30. package/build/cjs/organisation-unit-node/label/icon-empty.js +19 -22
  31. package/build/cjs/organisation-unit-node/label/icon-folder-closed.js +25 -28
  32. package/build/cjs/organisation-unit-node/label/icon-folder-open.js +34 -37
  33. package/build/cjs/organisation-unit-node/label/icon-single.js +28 -31
  34. package/build/cjs/organisation-unit-node/label/icon.js +6 -7
  35. package/build/cjs/organisation-unit-node/label/iconized-checkbox.js +12 -13
  36. package/build/cjs/organisation-unit-node/label/label-container.js +13 -16
  37. package/build/cjs/organisation-unit-node/label/label.js +27 -30
  38. package/build/cjs/organisation-unit-node/label/single-selection-label.js +18 -21
  39. package/build/cjs/organisation-unit-node/organisation-unit-node-children.js +27 -29
  40. package/build/cjs/organisation-unit-node/organisation-unit-node.js +22 -23
  41. package/build/cjs/organisation-unit-node/use-open-state.js +8 -9
  42. package/build/cjs/organisation-unit-node/use-org-children.js +14 -21
  43. package/build/cjs/organisation-unit-node/use-org-children.test.js +40 -59
  44. package/build/cjs/organisation-unit-node/use-org-data/use-org-data.js +13 -20
  45. package/build/cjs/organisation-unit-node/use-org-data/use-org-data.test.js +17 -27
  46. package/build/cjs/organisation-unit-tree/default-render-node-label/default-render-node-label.js +3 -6
  47. package/build/cjs/organisation-unit-tree/organisation-unit-tree-root-error.js +9 -12
  48. package/build/cjs/organisation-unit-tree/organisation-unit-tree-root-loading.js +10 -13
  49. package/build/cjs/organisation-unit-tree/organisation-unit-tree.js +24 -26
  50. package/build/cjs/organisation-unit-tree/use-expanded/create-expand-handlers.js +14 -17
  51. package/build/cjs/organisation-unit-tree/use-expanded/use-expanded.js +8 -9
  52. package/build/cjs/organisation-unit-tree/use-root-org-data/patch-missing-display-name.js +1 -2
  53. package/build/cjs/organisation-unit-tree/use-root-org-data/use-root-org-data.js +10 -14
  54. package/build/cjs/organisation-unit-tree/use-root-org-data/use-root-org-unit.test.js +32 -46
  55. package/build/es/__e2e__/children_as_child_nodes.js +8 -11
  56. package/build/es/__e2e__/common.js +18 -24
  57. package/build/es/__e2e__/controlled_expanded.js +6 -8
  58. package/build/es/__e2e__/displaying_loading_error.js +1 -4
  59. package/build/es/__e2e__/expanded.js +25 -34
  60. package/build/es/__e2e__/force_reload.js +14 -20
  61. package/build/es/__e2e__/get-organisation-unit-data.js +25 -29
  62. package/build/es/__e2e__/highlight.js +7 -10
  63. package/build/es/__e2e__/loading_state.js +7 -13
  64. package/build/es/__e2e__/multi_selection.js +8 -11
  65. package/build/es/__e2e__/no_selection.js +15 -21
  66. package/build/es/__e2e__/path_based_filtering.js +16 -22
  67. package/build/es/__e2e__/single_selection.js +10 -16
  68. package/build/es/__e2e__/sub_unit_as_root.js +4 -5
  69. package/build/es/__e2e__/tree_api.js +15 -21
  70. package/build/es/__stories__/custom-expanded-imperative-open.js +6 -8
  71. package/build/es/__stories__/custom-node-label.js +4 -5
  72. package/build/es/__stories__/development-stories.js +5 -6
  73. package/build/es/__stories__/loading-error-grandchild.js +1 -4
  74. package/build/es/__stories__/loading.js +1 -4
  75. package/build/es/__stories__/multiple-roots.js +9 -12
  76. package/build/es/__stories__/root-error.js +1 -4
  77. package/build/es/__stories__/root-loading.js +1 -4
  78. package/build/es/__stories__/shared.js +45 -77
  79. package/build/es/features/controlled_expanded/index.js +3 -6
  80. package/build/es/locales/index.js +40 -18
  81. package/build/es/organisation-unit-node/error-message.js +10 -13
  82. package/build/es/organisation-unit-node/label/disabled-selection-label.js +9 -12
  83. package/build/es/organisation-unit-node/label/icon-empty.js +19 -22
  84. package/build/es/organisation-unit-node/label/icon-folder-closed.js +25 -28
  85. package/build/es/organisation-unit-node/label/icon-folder-open.js +34 -37
  86. package/build/es/organisation-unit-node/label/icon-single.js +28 -31
  87. package/build/es/organisation-unit-node/label/icon.js +6 -7
  88. package/build/es/organisation-unit-node/label/iconized-checkbox.js +12 -13
  89. package/build/es/organisation-unit-node/label/label-container.js +13 -16
  90. package/build/es/organisation-unit-node/label/label.js +27 -30
  91. package/build/es/organisation-unit-node/label/single-selection-label.js +18 -21
  92. package/build/es/organisation-unit-node/organisation-unit-node-children.js +27 -29
  93. package/build/es/organisation-unit-node/organisation-unit-node.js +22 -23
  94. package/build/es/organisation-unit-node/use-open-state.js +8 -9
  95. package/build/es/organisation-unit-node/use-org-children.js +14 -21
  96. package/build/es/organisation-unit-node/use-org-children.test.js +40 -59
  97. package/build/es/organisation-unit-node/use-org-data/use-org-data.js +13 -20
  98. package/build/es/organisation-unit-node/use-org-data/use-org-data.test.js +17 -27
  99. package/build/es/organisation-unit-tree/default-render-node-label/default-render-node-label.js +3 -6
  100. package/build/es/organisation-unit-tree/organisation-unit-tree-root-error.js +9 -12
  101. package/build/es/organisation-unit-tree/organisation-unit-tree-root-loading.js +10 -13
  102. package/build/es/organisation-unit-tree/organisation-unit-tree.js +23 -24
  103. package/build/es/organisation-unit-tree/use-expanded/create-expand-handlers.js +14 -17
  104. package/build/es/organisation-unit-tree/use-expanded/use-expanded.js +8 -9
  105. package/build/es/organisation-unit-tree/use-root-org-data/patch-missing-display-name.js +1 -2
  106. package/build/es/organisation-unit-tree/use-root-org-data/use-root-org-data.js +10 -14
  107. package/build/es/organisation-unit-tree/use-root-org-data/use-root-org-unit.test.js +32 -46
  108. package/package.json +6 -6
  109. package/src/locales/index.js +57 -18
  110. package/src/organisation-unit-tree/use-root-org-data/use-root-org-unit.test.js +14 -14
@@ -7,10 +7,9 @@ var _useOrgChildren = require("./use-org-children.js");
7
7
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
8
8
  describe('OrganisationUnitTree - useOrgChildren', () => {
9
9
  const dataProviderData = {
10
- organisationUnits: jest.fn((type, _ref) => {
11
- let {
12
- id
13
- } = _ref;
10
+ organisationUnits: jest.fn((type, {
11
+ id
12
+ }) => {
14
13
  if (id === 'A0000000000') {
15
14
  return {
16
15
  children: [{
@@ -24,14 +23,11 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
24
23
  return Promise.reject(`No org unit with id "${id}"`);
25
24
  })
26
25
  };
27
- const wrapper = _ref2 => {
28
- let {
29
- children
30
- } = _ref2;
31
- return /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
32
- data: dataProviderData
33
- }, children);
34
- };
26
+ const wrapper = ({
27
+ children
28
+ }) => /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
29
+ data: dataProviderData
30
+ }, children);
35
31
  const node = {
36
32
  id: 'A0000000000',
37
33
  path: '/A0000000000',
@@ -81,18 +77,15 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
81
77
  });
82
78
  });
83
79
  it('should provide the error', async () => {
84
- const errorWrapper = _ref3 => {
85
- let {
86
- children
87
- } = _ref3;
88
- return /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
89
- data: {
90
- organisationUnits: async () => {
91
- throw new Error('Error message');
92
- }
80
+ const errorWrapper = ({
81
+ children
82
+ }) => /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
83
+ data: {
84
+ organisationUnits: async () => {
85
+ throw new Error('Error message');
93
86
  }
94
- }, children);
95
- };
87
+ }
88
+ }, children);
96
89
  const {
97
90
  result
98
91
  } = (0, _react.renderHook)(() => (0, _useOrgChildren.useOrgChildren)({
@@ -134,10 +127,9 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
134
127
  });
135
128
  it("should sort the node's children alphabetically by default", async () => {
136
129
  const dataProviderDataWithUnsortedChildren = {
137
- organisationUnits: jest.fn((type, _ref4) => {
138
- let {
139
- id
140
- } = _ref4;
130
+ organisationUnits: jest.fn((type, {
131
+ id
132
+ }) => {
141
133
  if (id === 'A0000000000') {
142
134
  return {
143
135
  children: [{
@@ -156,14 +148,11 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
156
148
  return Promise.reject(`No org unit with id "${id}"`);
157
149
  })
158
150
  };
159
- const wrapperWithUnsortedChildren = _ref5 => {
160
- let {
161
- children
162
- } = _ref5;
163
- return /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
164
- data: dataProviderDataWithUnsortedChildren
165
- }, children);
166
- };
151
+ const wrapperWithUnsortedChildren = ({
152
+ children
153
+ }) => /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
154
+ data: dataProviderDataWithUnsortedChildren
155
+ }, children);
167
156
  const {
168
157
  result
169
158
  } = (0, _react.renderHook)(() => (0, _useOrgChildren.useOrgChildren)({
@@ -195,10 +184,9 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
195
184
  });
196
185
  it(`should not sort the node's children alphabetically when "suppressAlphabeticalSorting" is true`, async () => {
197
186
  const dataProviderDataWithUnsortedChildren = {
198
- organisationUnits: jest.fn((type, _ref6) => {
199
- let {
200
- id
201
- } = _ref6;
187
+ organisationUnits: jest.fn((type, {
188
+ id
189
+ }) => {
202
190
  if (id === 'A0000000000') {
203
191
  return {
204
192
  children: [{
@@ -217,14 +205,11 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
217
205
  return Promise.reject(`No org unit with id "${id}"`);
218
206
  })
219
207
  };
220
- const wrapperWithUnsortedChildren = _ref7 => {
221
- let {
222
- children
223
- } = _ref7;
224
- return /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
225
- data: dataProviderDataWithUnsortedChildren
226
- }, children);
227
- };
208
+ const wrapperWithUnsortedChildren = ({
209
+ children
210
+ }) => /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
211
+ data: dataProviderDataWithUnsortedChildren
212
+ }, children);
228
213
  const options = {
229
214
  node: {
230
215
  ...node,
@@ -258,10 +243,9 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
258
243
  });
259
244
  it(`should not sort the node's children alphabetically when "suppressAlphabeticalSorting" is true`, async () => {
260
245
  const dataProviderDataWithUnsortedChildren = {
261
- organisationUnits: jest.fn((type, _ref8) => {
262
- let {
263
- id
264
- } = _ref8;
246
+ organisationUnits: jest.fn((type, {
247
+ id
248
+ }) => {
265
249
  if (id === 'A0000000000') {
266
250
  return {
267
251
  children: [{
@@ -280,14 +264,11 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
280
264
  return Promise.reject(`No org unit with id "${id}"`);
281
265
  })
282
266
  };
283
- const wrapperWithUnsortedChildren = _ref9 => {
284
- let {
285
- children
286
- } = _ref9;
287
- return /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
288
- data: dataProviderDataWithUnsortedChildren
289
- }, children);
290
- };
267
+ const wrapperWithUnsortedChildren = ({
268
+ children
269
+ }) => /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
270
+ data: dataProviderDataWithUnsortedChildren
271
+ }, children);
291
272
  const options = {
292
273
  node: {
293
274
  ...node,
@@ -8,21 +8,15 @@ var _appRuntime = require("@dhis2/app-runtime");
8
8
  const ORG_DATA_QUERY = {
9
9
  orgUnit: {
10
10
  resource: `organisationUnits`,
11
- id: _ref => {
12
- let {
13
- id
14
- } = _ref;
15
- return id;
16
- },
17
- params: _ref2 => {
18
- let {
19
- isUserDataViewFallback
20
- } = _ref2;
21
- return {
22
- isUserDataViewFallback,
23
- fields: ['path', 'children::size']
24
- };
25
- }
11
+ id: ({
12
+ id
13
+ }) => id,
14
+ params: ({
15
+ isUserDataViewFallback
16
+ }) => ({
17
+ isUserDataViewFallback,
18
+ fields: ['path', 'children::size']
19
+ })
26
20
  }
27
21
  };
28
22
 
@@ -33,11 +27,10 @@ const ORG_DATA_QUERY = {
33
27
  * @param {bool} options.isUserDataViewFallback
34
28
  * @returns {Object}
35
29
  */
36
- const useOrgData = (id, _ref3) => {
37
- let {
38
- displayName,
39
- isUserDataViewFallback
40
- } = _ref3;
30
+ const useOrgData = (id, {
31
+ displayName,
32
+ isUserDataViewFallback
33
+ }) => {
41
34
  if (!displayName) {
42
35
  throw new Error('"displayName" is required');
43
36
  }
@@ -8,10 +8,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
8
8
  describe('OrganisationUnitTree - useOrgData', () => {
9
9
  // @TODO: Figure out why this is necessary at all...
10
10
  const origError = console.error;
11
- jest.spyOn(console, 'error').mockImplementation(function () {
12
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
13
- args[_key] = arguments[_key];
14
- }
11
+ jest.spyOn(console, 'error').mockImplementation((...args) => {
15
12
  const [err] = args;
16
13
  if (!err.toString().match(/^Warning: An update to/)) {
17
14
  origError(...args);
@@ -21,10 +18,9 @@ describe('OrganisationUnitTree - useOrgData', () => {
21
18
  console.error.mockRestore();
22
19
  });
23
20
  const dataProviderData = {
24
- organisationUnits: jest.fn((type, _ref) => {
25
- let {
26
- id
27
- } = _ref;
21
+ organisationUnits: jest.fn((type, {
22
+ id
23
+ }) => {
28
24
  if (id === 'A0000000000') {
29
25
  return {
30
26
  id: 'A0000000000',
@@ -35,14 +31,11 @@ describe('OrganisationUnitTree - useOrgData', () => {
35
31
  return Promise.reject(`No org unit with id "${id}"`);
36
32
  })
37
33
  };
38
- const wrapper = _ref2 => {
39
- let {
40
- children
41
- } = _ref2;
42
- return /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
43
- data: dataProviderData
44
- }, children);
45
- };
34
+ const wrapper = ({
35
+ children
36
+ }) => /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
37
+ data: dataProviderData
38
+ }, children);
46
39
  it('should respond with `loading: true`, `error: null` and `data: { displayName, id }` initially', () => {
47
40
  const {
48
41
  result
@@ -81,18 +74,15 @@ describe('OrganisationUnitTree - useOrgData', () => {
81
74
  });
82
75
  });
83
76
  it('should provide the error', async () => {
84
- const errorWrapper = _ref3 => {
85
- let {
86
- children
87
- } = _ref3;
88
- return /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
89
- data: {
90
- organisationUnits: async () => {
91
- throw new Error('Error message');
92
- }
77
+ const errorWrapper = ({
78
+ children
79
+ }) => /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
80
+ data: {
81
+ organisationUnits: async () => {
82
+ throw new Error('Error message');
93
83
  }
94
- }, children);
95
- };
84
+ }
85
+ }, children);
96
86
  const {
97
87
  result
98
88
  } = (0, _react.renderHook)(() => (0, _useOrgData.useOrgData)('A0000000000', {
@@ -4,10 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.defaultRenderNodeLabel = void 0;
7
- const defaultRenderNodeLabel = _ref => {
8
- let {
9
- label
10
- } = _ref;
11
- return label;
12
- };
7
+ const defaultRenderNodeLabel = ({
8
+ label
9
+ }) => label;
13
10
  exports.defaultRenderNodeLabel = defaultRenderNodeLabel;
@@ -8,18 +8,15 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _index = _interopRequireDefault(require("../locales/index.js"));
10
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- const OrganisationUnitTreeRootError = _ref => {
12
- let {
13
- dataTest = 'dhis2-uiwidgets-orgunittree-error',
14
- error
15
- } = _ref;
16
- return /*#__PURE__*/_react.default.createElement("div", {
17
- "data-test": dataTest
18
- }, _index.default.t('Error: {{ ERRORMESSAGE }}', {
19
- ERRORMESSAGE: error,
20
- nsSeparator: '>'
21
- }));
22
- };
11
+ const OrganisationUnitTreeRootError = ({
12
+ dataTest = 'dhis2-uiwidgets-orgunittree-error',
13
+ error
14
+ }) => /*#__PURE__*/_react.default.createElement("div", {
15
+ "data-test": dataTest
16
+ }, _index.default.t('Error: {{ ERRORMESSAGE }}', {
17
+ ERRORMESSAGE: error,
18
+ nsSeparator: '>'
19
+ }));
23
20
  exports.OrganisationUnitTreeRootError = OrganisationUnitTreeRootError;
24
21
  OrganisationUnitTreeRootError.propTypes = {
25
22
  error: _propTypes.default.string.isRequired,
@@ -9,19 +9,16 @@ var _loader = require("@dhis2-ui/loader");
9
9
  var _propTypes = _interopRequireDefault(require("prop-types"));
10
10
  var _react = _interopRequireDefault(require("react"));
11
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- const OrganisationUnitTreeRootLoading = _ref => {
13
- let {
14
- dataTest = 'dhis2-uiwidgets-orgunittree-loading'
15
- } = _ref;
16
- return /*#__PURE__*/_react.default.createElement("div", {
17
- "data-test": dataTest,
18
- className: "jsx-814846266"
19
- }, /*#__PURE__*/_react.default.createElement(_loader.CircularLoader, {
20
- small: true
21
- }), /*#__PURE__*/_react.default.createElement(_style.default, {
22
- id: "814846266"
23
- }, ["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;}"]));
24
- };
12
+ const OrganisationUnitTreeRootLoading = ({
13
+ dataTest = 'dhis2-uiwidgets-orgunittree-loading'
14
+ }) => /*#__PURE__*/_react.default.createElement("div", {
15
+ "data-test": dataTest,
16
+ className: "jsx-814846266"
17
+ }, /*#__PURE__*/_react.default.createElement(_loader.CircularLoader, {
18
+ small: true
19
+ }), /*#__PURE__*/_react.default.createElement(_style.default, {
20
+ id: "814846266"
21
+ }, ["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;}"]));
25
22
  exports.OrganisationUnitTreeRootLoading = OrganisationUnitTreeRootLoading;
26
23
  OrganisationUnitTreeRootLoading.propTypes = {
27
24
  dataTest: _propTypes.default.string
@@ -16,35 +16,33 @@ var _organisationUnitTreeRootLoading = require("./organisation-unit-tree-root-lo
16
16
  var _index3 = require("./use-expanded/index.js");
17
17
  var _useForceReload = require("./use-force-reload.js");
18
18
  var _index4 = require("./use-root-org-data/index.js");
19
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
20
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
19
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
21
20
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
22
21
  // A stable object to reference
23
22
  const staticArray = [];
24
- const OrganisationUnitTree = _ref => {
25
- let {
26
- onChange,
27
- roots,
28
- autoExpandLoadingError,
29
- dataTest = 'dhis2-uiwidgets-orgunittree',
30
- disableSelection,
31
- displayProperty = 'displayName',
32
- forceReload,
33
- highlighted = staticArray,
34
- isUserDataViewFallback,
35
- initiallyExpanded = staticArray,
36
- filter = staticArray,
37
- renderNodeLabel = _index2.defaultRenderNodeLabel,
38
- selected = staticArray,
39
- singleSelection,
40
- suppressAlphabeticalSorting,
41
- expanded: expandedControlled,
42
- handleExpand: handleExpandControlled,
43
- handleCollapse: handleCollapseControlled,
44
- onExpand,
45
- onCollapse,
46
- onChildrenLoaded
47
- } = _ref;
23
+ const OrganisationUnitTree = ({
24
+ onChange,
25
+ roots,
26
+ autoExpandLoadingError,
27
+ dataTest = 'dhis2-uiwidgets-orgunittree',
28
+ disableSelection,
29
+ displayProperty = 'displayName',
30
+ forceReload,
31
+ highlighted = staticArray,
32
+ isUserDataViewFallback,
33
+ initiallyExpanded = staticArray,
34
+ filter = staticArray,
35
+ renderNodeLabel = _index2.defaultRenderNodeLabel,
36
+ selected = staticArray,
37
+ singleSelection,
38
+ suppressAlphabeticalSorting,
39
+ expanded: expandedControlled,
40
+ handleExpand: handleExpandControlled,
41
+ handleCollapse: handleCollapseControlled,
42
+ onExpand,
43
+ onCollapse,
44
+ onChildrenLoaded
45
+ }) => {
48
46
  const rootIds = (0, _filterRootIds.filterRootIds)(filter, Array.isArray(roots) ? roots : [roots]);
49
47
  const reloadId = (0, _useForceReload.useForceReload)(forceReload);
50
48
  const [prevReloadId, setPrevReloadId] = (0, _react.useState)(reloadId);
@@ -12,18 +12,16 @@ exports.createExpandHandlers = void 0;
12
12
  * @param {Function} [args.onCollapse]
13
13
  * @returns {{ handleExpand: Function, handleCollapse: Function }}
14
14
  */
15
- const createExpandHandlers = _ref => {
16
- let {
17
- expanded,
18
- setExpanded,
19
- onExpand,
20
- onCollapse
21
- } = _ref;
22
- const handleExpand = _ref2 => {
23
- let {
24
- path,
25
- ...rest
26
- } = _ref2;
15
+ const createExpandHandlers = ({
16
+ expanded,
17
+ setExpanded,
18
+ onExpand,
19
+ onCollapse
20
+ }) => {
21
+ const handleExpand = ({
22
+ path,
23
+ ...rest
24
+ }) => {
27
25
  if (!expanded.includes(path)) {
28
26
  setExpanded([...expanded, path]);
29
27
  if (onExpand) {
@@ -34,11 +32,10 @@ const createExpandHandlers = _ref => {
34
32
  }
35
33
  }
36
34
  };
37
- const handleCollapse = _ref3 => {
38
- let {
39
- path,
40
- ...rest
41
- } = _ref3;
35
+ const handleCollapse = ({
36
+ path,
37
+ ...rest
38
+ }) => {
42
39
  const pathIndex = expanded.indexOf(path);
43
40
  if (pathIndex !== -1) {
44
41
  const updatedExpanded = pathIndex === 0 ? expanded.slice(1) : [...expanded.slice(0, pathIndex), ...expanded.slice(pathIndex + 1)];
@@ -13,15 +13,14 @@ var _createExpandHandlers = require("./create-expand-handlers.js");
13
13
  * @param {Function} [onCollapse]
14
14
  * @returns {{ expanded: string[], handleExpand: Function, handleCollapse: Function }}
15
15
  */
16
- const useExpanded = _ref => {
17
- let {
18
- initiallyExpanded,
19
- onExpand,
20
- onCollapse,
21
- expandedControlled,
22
- handleExpandControlled,
23
- handleCollapseControlled
24
- } = _ref;
16
+ const useExpanded = ({
17
+ initiallyExpanded,
18
+ onExpand,
19
+ onCollapse,
20
+ expandedControlled,
21
+ handleExpandControlled,
22
+ handleCollapseControlled
23
+ }) => {
25
24
  const isControlled = !!expandedControlled;
26
25
  const allInitiallyExpandedPaths = isControlled ? [] : (0, _index.getAllExpandedPaths)(initiallyExpanded);
27
26
  const [expanded, setExpanded] = (0, _react.useState)(allInitiallyExpandedPaths);
@@ -17,8 +17,7 @@ exports.patchMissingDisplayName = void 0;
17
17
  */
18
18
  const patchMissingDisplayName = nodes => {
19
19
  const nodeEntries = Object.entries(nodes);
20
- const nodesWithDisplayName = nodeEntries.map(_ref => {
21
- let [id, node] = _ref;
20
+ const nodesWithDisplayName = nodeEntries.map(([id, node]) => {
22
21
  const displayName = node.displayName || '';
23
22
  return [id, {
24
23
  ...node,
@@ -12,15 +12,12 @@ const createRootQuery = (ids, displayProperty) => ids.reduce((query, id) => ({
12
12
  [id]: {
13
13
  id,
14
14
  resource: `organisationUnits`,
15
- params: _ref => {
16
- let {
17
- isUserDataViewFallback
18
- } = _ref;
19
- return {
20
- isUserDataViewFallback,
21
- fields: [displayProperty === 'displayName' ? 'displayName' : `${displayProperty}~rename(displayName)`, 'path', 'id']
22
- };
23
- }
15
+ params: ({
16
+ isUserDataViewFallback
17
+ }) => ({
18
+ isUserDataViewFallback,
19
+ fields: [displayProperty === 'displayName' ? 'displayName' : `${displayProperty}~rename(displayName)`, 'path', 'id']
20
+ })
24
21
  }
25
22
  }), {});
26
23
 
@@ -33,11 +30,10 @@ const createRootQuery = (ids, displayProperty) => ids.reduce((query, id) => ({
33
30
  * @returns {Object}
34
31
  */
35
32
  exports.createRootQuery = createRootQuery;
36
- const useRootOrgData = function (ids) {
37
- let {
38
- isUserDataViewFallback,
39
- displayProperty = 'displayName'
40
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
33
+ const useRootOrgData = (ids, {
34
+ isUserDataViewFallback,
35
+ displayProperty = 'displayName'
36
+ } = {}) => {
41
37
  const query = (0, _react.useMemo)(() => createRootQuery(ids, displayProperty), [ids, displayProperty]);
42
38
  const variables = {
43
39
  isUserDataViewFallback
@@ -8,10 +8,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
8
8
  describe('OrganisationUnitTree - useRootOrgData', () => {
9
9
  // @TODO: Figure out why this is necessary at all...
10
10
  const origError = console.error;
11
- jest.spyOn(console, 'error').mockImplementation(function () {
12
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
13
- args[_key] = arguments[_key];
14
- }
11
+ jest.spyOn(console, 'error').mockImplementation((...args) => {
15
12
  const [err] = args;
16
13
  if (!err.toString().match(/^Warning: An update to/)) {
17
14
  origError(...args);
@@ -21,10 +18,7 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
21
18
  // @TODO: This is kind of necessary; no idea if we can get rid of this
22
19
  const origWarn = console.warn;
23
20
  const dynamicQueryWarningMsg = "The query should be static, don't create it within the render loop!";
24
- jest.spyOn(console, 'warn').mockImplementation(function () {
25
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
26
- args[_key2] = arguments[_key2];
27
- }
21
+ jest.spyOn(console, 'warn').mockImplementation((...args) => {
28
22
  const [err] = args;
29
23
  if (!err.toString().match(dynamicQueryWarningMsg)) {
30
24
  origWarn(...args);
@@ -43,14 +37,11 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
43
37
  };
44
38
  })
45
39
  };
46
- const wrapper = _ref => {
47
- let {
48
- children
49
- } = _ref;
50
- return /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
51
- data: dataProviderData
52
- }, children);
53
- };
40
+ const wrapper = ({
41
+ children
42
+ }) => /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
43
+ data: dataProviderData
44
+ }, children);
54
45
  it('should respond with `loading: false`, `error: null` and `data: null` initially', () => {
55
46
  const {
56
47
  result
@@ -70,32 +61,30 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
70
61
  } = (0, _react.renderHook)(() => (0, _useRootOrgData.useRootOrgData)(['A0000000000']), {
71
62
  wrapper
72
63
  });
73
- await (0, _react.waitFor)(() => {});
74
- expect(result.current).toEqual(expect.objectContaining({
75
- loading: false,
76
- error: null,
77
- data: {
78
- A0000000000: {
79
- id: 'A0000000000',
80
- path: '/A0000000000',
81
- displayName: 'Org Unit 1'
64
+ await (0, _react.waitFor)(() => {
65
+ expect(result.current).toEqual(expect.objectContaining({
66
+ loading: false,
67
+ error: null,
68
+ data: {
69
+ A0000000000: {
70
+ id: 'A0000000000',
71
+ path: '/A0000000000',
72
+ displayName: 'Org Unit 1'
73
+ }
82
74
  }
83
- }
84
- }));
75
+ }));
76
+ });
85
77
  });
86
78
  it('should provide the error', async () => {
87
- const errorWrapper = _ref2 => {
88
- let {
89
- children
90
- } = _ref2;
91
- return /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
92
- data: {
93
- organisationUnits: async () => {
94
- throw new Error('Error message');
95
- }
79
+ const errorWrapper = ({
80
+ children
81
+ }) => /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
82
+ data: {
83
+ organisationUnits: async () => {
84
+ throw new Error('Error message');
96
85
  }
97
- }, children);
98
- };
86
+ }
87
+ }, children);
99
88
  const {
100
89
  result
101
90
  } = (0, _react.renderHook)(() => (0, _useRootOrgData.useRootOrgData)(['A0000000000']), {
@@ -145,14 +134,11 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
145
134
  };
146
135
  })
147
136
  };
148
- const wrapperWithoutDisplayName = _ref3 => {
149
- let {
150
- children
151
- } = _ref3;
152
- return /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
153
- data: dataProviderDataWithoutDisplayName
154
- }, children);
155
- };
137
+ const wrapperWithoutDisplayName = ({
138
+ children
139
+ }) => /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
140
+ data: dataProviderDataWithoutDisplayName
141
+ }, children);
156
142
  const {
157
143
  result
158
144
  } = (0, _react.renderHook)(() => (0, _useRootOrgData.useRootOrgData)(['A0000000000']), {