@dhis2-ui/organisation-unit-tree 7.16.1 → 8.0.0

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 (37) hide show
  1. package/build/cjs/__e2e__/common.js +51 -24
  2. package/build/cjs/__e2e__/tree_api.stories.e2e.js +13 -5
  3. package/build/cjs/__stories__/development-stories.js +1 -3
  4. package/build/cjs/__stories__/shared.js +50 -17
  5. package/build/cjs/features/controlled_expanded/index.js +9 -3
  6. package/build/cjs/features/tree_api/index.js +4 -3
  7. package/build/cjs/helpers/sort-node-children-alphabetically.js +2 -17
  8. package/build/cjs/locales/en/translations.json +3 -2
  9. package/build/cjs/organisation-unit-node/label/label.js +2 -5
  10. package/build/cjs/organisation-unit-node/loading-spinner.js +32 -0
  11. package/build/cjs/organisation-unit-node/organisation-unit-node-children.js +120 -0
  12. package/build/cjs/organisation-unit-node/organisation-unit-node.js +43 -68
  13. package/build/cjs/organisation-unit-node/use-org-children.js +81 -0
  14. package/build/cjs/organisation-unit-node/use-org-children.test.js +319 -0
  15. package/build/cjs/organisation-unit-node/use-org-data/use-org-data.js +10 -33
  16. package/build/cjs/organisation-unit-node/use-org-data/use-org-data.test.js +3 -169
  17. package/build/cjs/organisation-unit-tree/organisation-unit-tree.js +4 -2
  18. package/build/cjs/organisation-unit-tree/use-root-org-data/use-root-org-data.js +7 -5
  19. package/build/es/__e2e__/common.js +52 -24
  20. package/build/es/__e2e__/tree_api.stories.e2e.js +13 -5
  21. package/build/es/__stories__/development-stories.js +1 -3
  22. package/build/es/__stories__/shared.js +51 -17
  23. package/build/es/features/controlled_expanded/index.js +9 -3
  24. package/build/es/features/tree_api/index.js +4 -3
  25. package/build/es/helpers/sort-node-children-alphabetically.js +2 -17
  26. package/build/es/locales/en/translations.json +3 -2
  27. package/build/es/organisation-unit-node/label/label.js +2 -5
  28. package/build/es/organisation-unit-node/loading-spinner.js +17 -0
  29. package/build/es/organisation-unit-node/organisation-unit-node-children.js +103 -0
  30. package/build/es/organisation-unit-node/organisation-unit-node.js +41 -65
  31. package/build/es/organisation-unit-node/use-org-children.js +69 -0
  32. package/build/es/organisation-unit-node/use-org-children.test.js +311 -0
  33. package/build/es/organisation-unit-node/use-org-data/use-org-data.js +10 -31
  34. package/build/es/organisation-unit-node/use-org-data/use-org-data.test.js +3 -169
  35. package/build/es/organisation-unit-tree/organisation-unit-tree.js +4 -2
  36. package/build/es/organisation-unit-tree/use-root-org-data/use-root-org-data.js +7 -5
  37. package/package.json +5 -5
@@ -31,13 +31,7 @@ describe('OrganisationUnitTree - useOrgData', () => {
31
31
  return {
32
32
  id: 'A0000000000',
33
33
  path: '/A0000000000',
34
- displayName: 'Org Unit 1',
35
- children: [{
36
- id: 'A0000000001',
37
- path: '/A0000000000/A0000000001',
38
- children: [],
39
- displayName: 'Org Unit 2'
40
- }]
34
+ displayName: 'Org Unit 1'
41
35
  };
42
36
  }
43
37
 
@@ -51,7 +45,7 @@ describe('OrganisationUnitTree - useOrgData', () => {
51
45
  data: dataProviderData
52
46
  }, children);
53
47
 
54
- it('should respond with `loading: false`, `error: null` and `data: { displayName, id }` initially', () => {
48
+ it('should respond with `loading: true`, `error: null` and `data: { displayName, id }` initially', () => {
55
49
  const {
56
50
  result
57
51
  } = (0, _reactHooks.renderHook)(() => (0, _useOrgData.useOrgData)('A0000000000', {
@@ -84,13 +78,7 @@ describe('OrganisationUnitTree - useOrgData', () => {
84
78
  data: {
85
79
  id: 'A0000000000',
86
80
  path: '/A0000000000',
87
- displayName: 'Org Unit 1',
88
- children: [{
89
- id: 'A0000000001',
90
- path: '/A0000000000/A0000000001',
91
- children: [],
92
- displayName: 'Org Unit 2'
93
- }]
81
+ displayName: 'Org Unit 1'
94
82
  }
95
83
  });
96
84
  });
@@ -123,30 +111,6 @@ describe('OrganisationUnitTree - useOrgData', () => {
123
111
  }
124
112
  });
125
113
  });
126
- it('should call the onComplete callback', async () => {
127
- const onComplete = jest.fn();
128
- const options = {
129
- onComplete,
130
- displayName: 'Display name'
131
- };
132
- const {
133
- waitForNextUpdate
134
- } = (0, _reactHooks.renderHook)(() => (0, _useOrgData.useOrgData)('A0000000000', options), {
135
- wrapper
136
- });
137
- await waitForNextUpdate();
138
- expect(onComplete).toHaveBeenCalledWith({
139
- id: 'A0000000000',
140
- path: '/A0000000000',
141
- displayName: 'Org Unit 1',
142
- children: [{
143
- id: 'A0000000001',
144
- path: '/A0000000000/A0000000001',
145
- children: [],
146
- displayName: 'Org Unit 2'
147
- }]
148
- });
149
- });
150
114
  it('should send the "isUserDataViewFallback" parameter with value "undefined"', async () => {
151
115
  const options = {
152
116
  displayName: 'Display name'
@@ -182,134 +146,4 @@ describe('OrganisationUnitTree - useOrgData', () => {
182
146
  }), expect.objectContaining({}) // contains the `signal`
183
147
  );
184
148
  });
185
- it("should sort the node's children alphabetically by default", async () => {
186
- const dataProviderDataWithUnsortedChildren = {
187
- organisationUnits: jest.fn((type, {
188
- id
189
- }) => {
190
- if (id === 'A0000000000') {
191
- return {
192
- id: 'A0000000000',
193
- path: '/A0000000000',
194
- displayName: 'Org Unit 1',
195
- children: [{
196
- id: 'A0000000002',
197
- path: '/A0000000000/A0000000002',
198
- children: [],
199
- displayName: 'Org Unit 3'
200
- }, {
201
- id: 'A0000000001',
202
- path: '/A0000000000/A0000000001',
203
- children: [],
204
- displayName: 'Org Unit 2'
205
- }]
206
- };
207
- }
208
-
209
- return Promise.reject(`No org unit with id "${id}"`);
210
- })
211
- };
212
-
213
- const wrapperWithUnsortedChildren = ({
214
- children
215
- }) => /*#__PURE__*/_react.default.createElement(_appRuntime.CustomDataProvider, {
216
- data: dataProviderDataWithUnsortedChildren
217
- }, children);
218
-
219
- const {
220
- result,
221
- waitForNextUpdate
222
- } = (0, _reactHooks.renderHook)(() => (0, _useOrgData.useOrgData)('A0000000000', {
223
- displayName: 'Display name'
224
- }), {
225
- wrapper: wrapperWithUnsortedChildren
226
- });
227
- await waitForNextUpdate();
228
- expect(result.current).toEqual({
229
- loading: false,
230
- error: null,
231
- data: {
232
- id: 'A0000000000',
233
- path: '/A0000000000',
234
- displayName: 'Org Unit 1',
235
- children: [{
236
- id: 'A0000000001',
237
- path: '/A0000000000/A0000000001',
238
- children: [],
239
- displayName: 'Org Unit 2'
240
- }, {
241
- id: 'A0000000002',
242
- path: '/A0000000000/A0000000002',
243
- children: [],
244
- displayName: 'Org Unit 3'
245
- }]
246
- }
247
- });
248
- });
249
- it(`should not sort the node's children alphabetically when "suppressAlphabeticalSorting" is true`, async () => {
250
- const dataProviderDataWithUnsortedChildren = {
251
- organisationUnits: jest.fn((type, {
252
- id
253
- }) => {
254
- if (id === 'A0000000000') {
255
- return {
256
- id: 'A0000000000',
257
- path: '/A0000000000',
258
- displayName: 'Org Unit 1',
259
- children: [{
260
- id: 'A0000000002',
261
- path: '/A0000000000/A0000000002',
262
- children: [],
263
- displayName: 'Org Unit 3'
264
- }, {
265
- id: 'A0000000001',
266
- path: '/A0000000000/A0000000001',
267
- children: [],
268
- displayName: 'Org Unit 2'
269
- }]
270
- };
271
- }
272
-
273
- return Promise.reject(`No org unit with id "${id}"`);
274
- })
275
- };
276
-
277
- const wrapperWithUnsortedChildren = ({
278
- children
279
- }) => /*#__PURE__*/_react.default.createElement(_appRuntime.CustomDataProvider, {
280
- data: dataProviderDataWithUnsortedChildren
281
- }, children);
282
-
283
- const options = {
284
- displayName: 'Display name',
285
- suppressAlphabeticalSorting: true
286
- };
287
- const {
288
- result,
289
- waitForNextUpdate
290
- } = (0, _reactHooks.renderHook)(() => (0, _useOrgData.useOrgData)('A0000000000', options), {
291
- wrapper: wrapperWithUnsortedChildren
292
- });
293
- await waitForNextUpdate();
294
- expect(result.current).toEqual({
295
- loading: false,
296
- error: null,
297
- data: {
298
- id: 'A0000000000',
299
- path: '/A0000000000',
300
- displayName: 'Org Unit 1',
301
- children: [{
302
- id: 'A0000000002',
303
- path: '/A0000000000/A0000000002',
304
- children: [],
305
- displayName: 'Org Unit 3'
306
- }, {
307
- id: 'A0000000001',
308
- path: '/A0000000000/A0000000001',
309
- children: [],
310
- displayName: 'Org Unit 2'
311
- }]
312
- }
313
- });
314
- });
315
149
  });
@@ -61,6 +61,7 @@ const OrganisationUnitTree = ({
61
61
  const reloadId = (0, _useForceReload.useForceReload)(forceReload);
62
62
  const [prevReloadId, setPrevReloadId] = (0, _react.useState)(reloadId);
63
63
  const {
64
+ called,
64
65
  loading,
65
66
  error,
66
67
  data,
@@ -90,11 +91,12 @@ const OrganisationUnitTree = ({
90
91
 
91
92
  return () => console.warn('@TODO: Why does this component unmount after a force reload?');
92
93
  }, [reloadId, prevReloadId, refetch]);
94
+ const isLoading = !called || loading;
93
95
  return /*#__PURE__*/_react.default.createElement("div", {
94
96
  "data-test": dataTest
95
- }, loading && /*#__PURE__*/_react.default.createElement(_rootLoading.RootLoading, null), error && /*#__PURE__*/_react.default.createElement(_rootError.RootError, {
97
+ }, isLoading && /*#__PURE__*/_react.default.createElement(_rootLoading.RootLoading, null), error && /*#__PURE__*/_react.default.createElement(_rootError.RootError, {
96
98
  error: error
97
- }), !error && !loading && rootIds.map(rootId => {
99
+ }), !error && !isLoading && rootIds.map(rootId => {
98
100
  const rootNode = data[rootId];
99
101
  return /*#__PURE__*/_react.default.createElement(_index.OrganisationUnitNode, {
100
102
  key: rootNode.path,
@@ -19,8 +19,7 @@ const createRootQuery = ids => ids.reduce((query, id) => ({ ...query,
19
19
  isUserDataViewFallback
20
20
  }) => ({
21
21
  isUserDataViewFallback,
22
- fields: ['displayName', 'path', 'id'],
23
- paging: false
22
+ fields: ['displayName', 'path', 'id']
24
23
  })
25
24
  }
26
25
  }), {});
@@ -42,18 +41,21 @@ const useRootOrgData = (ids, {
42
41
  const variables = {
43
42
  isUserDataViewFallback
44
43
  };
44
+ const rootOrgUnits = (0, _appRuntime.useDataQuery)(query, {
45
+ variables
46
+ });
45
47
  const {
48
+ called,
46
49
  loading,
47
50
  error,
48
51
  data,
49
52
  refetch
50
- } = (0, _appRuntime.useDataQuery)(query, {
51
- variables
52
- });
53
+ } = rootOrgUnits;
53
54
  const patchedData = (0, _react.useMemo)(() => {
54
55
  return data ? (0, _patchMissingDisplayName.patchMissingDisplayName)(data) : data;
55
56
  }, [data]);
56
57
  return {
58
+ called,
57
59
  loading,
58
60
  error: error || null,
59
61
  data: patchedData || null,
@@ -4,39 +4,60 @@ import PropTypes from 'prop-types';
4
4
  import React, { useState } from 'react';
5
5
  export const namespace = 'OrganisationUnitTree';
6
6
  export const delayResponse = (delay, response) => () => new Promise(resolve => setTimeout(() => resolve(response), delay));
7
- export const getOrganisationUnitData = id => {
7
+
8
+ const createResponse = ({
9
+ fields,
10
+ id,
11
+ path,
12
+ displayName,
13
+ children
14
+ }) => ({ ...(fields.includes('id') ? {
15
+ id
16
+ } : {}),
17
+ ...(fields.includes('path') ? {
18
+ path
19
+ } : {}),
20
+ ...(fields.includes('displayName') ? {
21
+ displayName
22
+ } : {}),
23
+ ...(fields.includes('children::size') ? {
24
+ children: children.length
25
+ } : {}),
26
+ ...(fields.includes('children[id,path,displayName]') ? {
27
+ children
28
+ } : {})
29
+ });
30
+
31
+ export const getOrganisationUnitData = (id, {
32
+ fields
33
+ }) => {
8
34
  let data;
9
35
 
10
36
  if (id === 'A0000000000') {
11
- data = {
37
+ data = createResponse({
38
+ fields,
12
39
  id: 'A0000000000',
13
40
  path: '/A0000000000',
14
41
  displayName: 'Org Unit 1',
15
42
  children: [{
16
43
  id: 'A0000000001',
17
44
  path: '/A0000000000/A0000000001',
18
- children: [{
19
- id: 'A0000000003'
20
- }, {
21
- id: 'A0000000004'
22
- }],
23
45
  displayName: 'Org Unit 2'
24
46
  }, {
25
47
  id: 'A0000000002',
26
48
  path: '/A0000000000/A0000000002',
27
- children: [],
28
49
  displayName: 'Org Unit 3'
29
50
  }, {
30
51
  id: 'A0000000006',
31
52
  path: '/A0000000000/A0000000006',
32
- children: [],
33
53
  displayName: 'Org Unit 7'
34
54
  }]
35
- };
55
+ });
36
56
  }
37
57
 
38
58
  if (id === 'A0000000001') {
39
- data = {
59
+ data = createResponse({
60
+ fields,
40
61
  id: 'A0000000001',
41
62
  path: '/A0000000000/A0000000001',
42
63
  displayName: 'Org Unit 2',
@@ -51,20 +72,22 @@ export const getOrganisationUnitData = id => {
51
72
  children: [],
52
73
  displayName: 'Org Unit 5'
53
74
  }]
54
- };
75
+ });
55
76
  }
56
77
 
57
78
  if (id === 'A0000000002') {
58
- data = {
79
+ data = createResponse({
80
+ fields,
59
81
  displayName: 'Org Unit 3',
60
82
  id: 'A0000000002',
61
83
  path: '/A0000000000/A0000000002',
62
84
  children: []
63
- };
85
+ });
64
86
  }
65
87
 
66
88
  if (id === 'A0000000003') {
67
- data = {
89
+ data = createResponse({
90
+ fields,
68
91
  displayName: 'Org Unit 4',
69
92
  id: 'A0000000003',
70
93
  path: '/A0000000000/A0000000001/A0000000003',
@@ -74,43 +97,48 @@ export const getOrganisationUnitData = id => {
74
97
  children: [],
75
98
  displayName: 'Org Unit 8'
76
99
  }]
77
- };
100
+ });
78
101
  }
79
102
 
80
103
  if (id === 'A0000000004') {
81
- data = {
104
+ data = createResponse({
105
+ fields,
82
106
  displayName: 'Org Unit 5',
83
107
  id: 'A0000000004',
84
108
  path: '/A0000000000/A0000000001/A0000000004',
85
109
  children: []
86
- };
110
+ });
87
111
  }
88
112
 
89
113
  if (id === 'A0000000006') {
90
- data = {
114
+ data = createResponse({
115
+ fields,
91
116
  displayName: 'Org Unit 7',
92
117
  id: 'A0000000006',
93
118
  path: '/A0000000000/A0000000006',
94
119
  children: []
95
- };
120
+ });
96
121
  }
97
122
 
98
123
  if (id === 'A0000000007') {
99
- data = {
124
+ data = createResponse({
125
+ fields,
100
126
  displayName: 'Org Unit 8',
101
127
  id: 'A0000000007',
102
128
  path: '/A0000000000/A0000000001/A0000000003/A0000000007',
103
129
  children: []
104
- };
130
+ });
105
131
  }
106
132
 
107
133
  return data;
108
134
  };
109
135
  export const dataProviderData = {
110
136
  organisationUnits: (_, {
111
- id
137
+ id,
138
+ params = {}
112
139
  }) => {
113
- const data = getOrganisationUnitData(id);
140
+ console.log('id, params', id, params);
141
+ const data = getOrganisationUnitData(id, params);
114
142
 
115
143
  if (!data) {
116
144
  return Promise.reject(new Error('404 - Org unit not found'));
@@ -6,19 +6,27 @@ import { StatefulMultiSelectionWrapper, dataProviderData, namespace } from './co
6
6
  const customizedDataProviderData = {
7
7
  organisationUnits: (...args) => {
8
8
  const [, {
9
- id
9
+ id,
10
+ params
10
11
  }] = args;
12
+ const {
13
+ fields
14
+ } = params;
11
15
 
12
16
  if (id === 'A0000000000') {
13
- return dataProviderData.organisationUnits(...args).then(data => ({ ...data,
14
- children: data.children.slice(0, 1)
15
- }));
17
+ return dataProviderData.organisationUnits(...args).then(data => {
18
+ var _data$children;
19
+
20
+ return { ...data,
21
+ children: fields.includes('children::size') ? 1 : (_data$children = data.children) === null || _data$children === void 0 ? void 0 : _data$children.slice(0, 1)
22
+ };
23
+ });
16
24
  }
17
25
 
18
26
  if (id === 'A0000000001') {
19
27
  return dataProviderData.organisationUnits(...args).then(data => ({ ...data,
20
28
  path: '/A0000000001',
21
- children: []
29
+ children: fields.includes('children::size') ? 0 : []
22
30
  }));
23
31
  }
24
32
 
@@ -68,9 +68,7 @@ export const DxWithRealBackend = () => /*#__PURE__*/React.createElement("div", n
68
68
  }, "Settings app / Access")), /*#__PURE__*/React.createElement(DataProvider, {
69
69
  baseUrl: "https://debug.dhis2.org/dev",
70
70
  apiVersion: ""
71
- }, /*#__PURE__*/React.createElement(Wrapper //initiallyExpanded={['/ImspTQPwCqd/eIQbndfxQMb']}
72
- , {
73
- suppressAlphabeticalSorting: true,
71
+ }, /*#__PURE__*/React.createElement(Wrapper, {
74
72
  roots: ['ImspTQPwCqd', 'O6uvpzGd5pu', 'fdc6uOvgoji']
75
73
  })));
76
74
  DxWithRealBackend.storyName = 'DX: With real backend';
@@ -6,11 +6,38 @@ export const onChange = (...args) => log && console.log('onChange', ...args);
6
6
  export const onExpand = (...args) => log && console.log('onExpand', ...args);
7
7
  export const onCollapse = (...args) => log && console.log('onCollapse', ...args);
8
8
  export const onChildrenLoaded = (...args) => log && console.log('onChildrenLoaded', ...args);
9
- export const getOrganisationUnitData = id => {
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]') ? {
29
+ children
30
+ } : {})
31
+ });
32
+
33
+ export const getOrganisationUnitData = (id, {
34
+ fields
35
+ }) => {
10
36
  let data;
11
37
 
12
38
  if (id === 'A0000000000') {
13
- data = {
39
+ data = createResponse({
40
+ fields,
14
41
  id: 'A0000000000',
15
42
  path: '/A0000000000',
16
43
  displayName: 'Org Unit 1',
@@ -34,11 +61,12 @@ export const getOrganisationUnitData = id => {
34
61
  children: [],
35
62
  displayName: 'Org Unit 7'
36
63
  }]
37
- };
64
+ });
38
65
  }
39
66
 
40
67
  if (id === 'A0000000001') {
41
- data = {
68
+ data = createResponse({
69
+ fields,
42
70
  id: 'A0000000001',
43
71
  path: '/A0000000000/A0000000001',
44
72
  displayName: 'Org Unit 2',
@@ -53,20 +81,22 @@ export const getOrganisationUnitData = id => {
53
81
  children: [],
54
82
  displayName: 'Org Unit 5'
55
83
  }]
56
- };
84
+ });
57
85
  }
58
86
 
59
87
  if (id === 'A0000000002') {
60
- data = {
88
+ data = createResponse({
89
+ fields,
61
90
  displayName: 'Org Unit 3',
62
91
  id: 'A0000000002',
63
92
  path: '/A0000000000/A0000000002',
64
93
  children: []
65
- };
94
+ });
66
95
  }
67
96
 
68
97
  if (id === 'A0000000003') {
69
- data = {
98
+ data = createResponse({
99
+ fields,
70
100
  displayName: 'Org Unit 4',
71
101
  id: 'A0000000003',
72
102
  path: '/A0000000000/A0000000001/A0000000003',
@@ -76,43 +106,47 @@ export const getOrganisationUnitData = id => {
76
106
  children: [],
77
107
  displayName: 'Org Unit 8'
78
108
  }]
79
- };
109
+ });
80
110
  }
81
111
 
82
112
  if (id === 'A0000000004') {
83
- data = {
113
+ data = createResponse({
114
+ fields,
84
115
  displayName: 'Org Unit 5',
85
116
  id: 'A0000000004',
86
117
  path: '/A0000000000/A0000000001/A0000000004',
87
118
  children: []
88
- };
119
+ });
89
120
  }
90
121
 
91
122
  if (id === 'A0000000006') {
92
- data = {
123
+ data = createResponse({
124
+ fields,
93
125
  displayName: 'Org Unit 7',
94
126
  id: 'A0000000006',
95
127
  path: '/A0000000000/A0000000006',
96
128
  children: []
97
- };
129
+ });
98
130
  }
99
131
 
100
132
  if (id === 'A0000000007') {
101
- data = {
133
+ data = createResponse({
134
+ fields,
102
135
  displayName: 'Org Unit 8',
103
136
  id: 'A0000000007',
104
137
  path: '/A0000000000/A0000000001/A0000000003/A0000000007',
105
138
  children: []
106
- };
139
+ });
107
140
  }
108
141
 
109
142
  return data;
110
143
  };
111
144
  export const customData = {
112
145
  organisationUnits: (_, {
113
- id
146
+ id,
147
+ params = {}
114
148
  }) => {
115
- const data = getOrganisationUnitData(id);
149
+ const data = getOrganisationUnitData(id, params);
116
150
 
117
151
  if (!data) {
118
152
  return Promise.reject(new Error('404 - Org unit not found'));
@@ -2,7 +2,9 @@ import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps';
2
2
  import { getOrganisationUnitData, namespace } from '../../__e2e__/common.js';
3
3
 
4
4
  const expectOrgUnitsToBeDisplayed = ids => {
5
- const expandedLabels = ids.map(id => getOrganisationUnitData(id).displayName);
5
+ const expandedLabels = ids.map(id => getOrganisationUnitData(id, {
6
+ fields: ['displayName']
7
+ }).displayName);
6
8
  expandedLabels.forEach(label => {
7
9
  cy.get(`:contains("${label}")`).should('exist');
8
10
  });
@@ -10,7 +12,9 @@ const expectOrgUnitsToBeDisplayed = ids => {
10
12
 
11
13
  const expectOrgUnitsToNotBeDisplayed = ids => {
12
14
  const expandedLabels = ids.map(id => {
13
- const data = getOrganisationUnitData(id);
15
+ const data = getOrganisationUnitData(id, {
16
+ fields: ['displayName']
17
+ });
14
18
  return data.displayName;
15
19
  });
16
20
  expandedLabels.forEach(label => {
@@ -46,7 +50,9 @@ Then('the path should close', () => {
46
50
  cy.get('@providedPaths').then(providedPaths => {
47
51
  const providedIds = providedPaths.map(path => path.match(/[^/]+$/)[0]);
48
52
  const hiddenChildrenIds = providedIds.reduce((acc, cur) => {
49
- const curData = getOrganisationUnitData(cur);
53
+ const curData = getOrganisationUnitData(cur, {
54
+ fields: ['children[id,path,displayName]']
55
+ });
50
56
  const childrenIds = curData.children.map(({
51
57
  id
52
58
  }) => id);
@@ -95,9 +95,10 @@ Then('the onChildrenLoaded callback gets called', () => {
95
95
  Then("the payload contains the loaded children's data", () => {
96
96
  cy.window().should(win => {
97
97
  const calls = win.onChildrenLoaded.getCalls();
98
- const {
98
+ expect(calls).to.have.length(1);
99
+ const [{
99
100
  args
100
- } = calls[calls.length - 1];
101
- expect(args[0].id).to.equal('A0000000001');
101
+ }] = calls;
102
+ expect(args[0].id).to.equal('A0000000000');
102
103
  });
103
104
  });
@@ -1,17 +1,2 @@
1
- export const sortNodeChildrenAlphabetically = node => {
2
- if (!node.children) {
3
- return node;
4
- }
5
-
6
- const sortedChildren = [...node.children];
7
- sortedChildren.sort((left, right) => {
8
- if (left.displayName === right.displayName) {
9
- return 0;
10
- }
11
-
12
- return left.displayName.localeCompare(right.displayName);
13
- });
14
- return { ...node,
15
- children: sortedChildren
16
- };
17
- };
1
+ // sort mutates the original
2
+ export const sortNodeChildrenAlphabetically = children => [...children].sort((left, right) => left.displayName.localeCompare(right.displayName));
@@ -1,4 +1,5 @@
1
1
  {
2
- "Could not load children": "",
3
- "Error: {{ ERRORMESSAGE }}": ""
2
+ "No children match filter": "No children match filter",
3
+ "Could not load children": "Could not load children",
4
+ "Error: {{ ERRORMESSAGE }}": "Error: {{ ERRORMESSAGE }}"
4
5
  }