@dhis2-ui/organisation-unit-tree 10.16.3 → 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.
- package/build/cjs/__e2e__/children_as_child_nodes.js +8 -11
- package/build/cjs/__e2e__/common.js +19 -26
- package/build/cjs/__e2e__/controlled_expanded.js +7 -10
- package/build/cjs/__e2e__/displaying_loading_error.js +1 -4
- package/build/cjs/__e2e__/expanded.js +25 -34
- package/build/cjs/__e2e__/force_reload.js +15 -22
- package/build/cjs/__e2e__/get-organisation-unit-data.js +25 -29
- package/build/cjs/__e2e__/highlight.js +7 -10
- package/build/cjs/__e2e__/loading_state.js +7 -13
- package/build/cjs/__e2e__/multi_selection.js +8 -11
- package/build/cjs/__e2e__/no_selection.js +15 -21
- package/build/cjs/__e2e__/path_based_filtering.js +16 -22
- package/build/cjs/__e2e__/single_selection.js +10 -16
- package/build/cjs/__e2e__/sub_unit_as_root.js +5 -7
- package/build/cjs/__e2e__/tree_api.js +15 -21
- package/build/cjs/__stories__/custom-expanded-imperative-open.js +7 -10
- package/build/cjs/__stories__/custom-node-label.js +4 -5
- package/build/cjs/__stories__/development-stories.js +6 -8
- package/build/cjs/__stories__/force-reload-all.js +1 -2
- package/build/cjs/__stories__/loading-error-grandchild.js +1 -4
- package/build/cjs/__stories__/loading.js +1 -4
- package/build/cjs/__stories__/multiple-roots.js +9 -12
- package/build/cjs/__stories__/root-error.js +1 -4
- package/build/cjs/__stories__/root-loading.js +1 -4
- package/build/cjs/__stories__/shared.js +46 -79
- package/build/cjs/features/controlled_expanded/index.js +3 -6
- package/build/cjs/locales/index.js +49 -27
- package/build/cjs/organisation-unit-node/error-message.js +10 -13
- package/build/cjs/organisation-unit-node/label/disabled-selection-label.js +9 -12
- package/build/cjs/organisation-unit-node/label/icon-empty.js +19 -22
- package/build/cjs/organisation-unit-node/label/icon-folder-closed.js +25 -28
- package/build/cjs/organisation-unit-node/label/icon-folder-open.js +34 -37
- package/build/cjs/organisation-unit-node/label/icon-single.js +28 -31
- package/build/cjs/organisation-unit-node/label/icon.js +6 -7
- package/build/cjs/organisation-unit-node/label/iconized-checkbox.js +12 -13
- package/build/cjs/organisation-unit-node/label/label-container.js +13 -16
- package/build/cjs/organisation-unit-node/label/label.js +27 -30
- package/build/cjs/organisation-unit-node/label/single-selection-label.js +18 -21
- package/build/cjs/organisation-unit-node/organisation-unit-node-children.js +27 -29
- package/build/cjs/organisation-unit-node/organisation-unit-node.js +22 -23
- package/build/cjs/organisation-unit-node/use-open-state.js +8 -9
- package/build/cjs/organisation-unit-node/use-org-children.js +14 -21
- package/build/cjs/organisation-unit-node/use-org-children.test.js +40 -59
- package/build/cjs/organisation-unit-node/use-org-data/use-org-data.js +13 -20
- package/build/cjs/organisation-unit-node/use-org-data/use-org-data.test.js +17 -27
- package/build/cjs/organisation-unit-tree/default-render-node-label/default-render-node-label.js +3 -6
- package/build/cjs/organisation-unit-tree/organisation-unit-tree-root-error.js +9 -12
- package/build/cjs/organisation-unit-tree/organisation-unit-tree-root-loading.js +10 -13
- package/build/cjs/organisation-unit-tree/organisation-unit-tree.js +24 -26
- package/build/cjs/organisation-unit-tree/use-expanded/create-expand-handlers.js +14 -17
- package/build/cjs/organisation-unit-tree/use-expanded/use-expanded.js +8 -9
- package/build/cjs/organisation-unit-tree/use-root-org-data/patch-missing-display-name.js +1 -2
- package/build/cjs/organisation-unit-tree/use-root-org-data/use-root-org-data.js +10 -14
- package/build/cjs/organisation-unit-tree/use-root-org-data/use-root-org-unit.test.js +32 -46
- package/build/es/__e2e__/children_as_child_nodes.js +8 -11
- package/build/es/__e2e__/common.js +18 -24
- package/build/es/__e2e__/controlled_expanded.js +6 -8
- package/build/es/__e2e__/displaying_loading_error.js +1 -4
- package/build/es/__e2e__/expanded.js +25 -34
- package/build/es/__e2e__/force_reload.js +14 -20
- package/build/es/__e2e__/get-organisation-unit-data.js +25 -29
- package/build/es/__e2e__/highlight.js +7 -10
- package/build/es/__e2e__/loading_state.js +7 -13
- package/build/es/__e2e__/multi_selection.js +8 -11
- package/build/es/__e2e__/no_selection.js +15 -21
- package/build/es/__e2e__/path_based_filtering.js +16 -22
- package/build/es/__e2e__/single_selection.js +10 -16
- package/build/es/__e2e__/sub_unit_as_root.js +4 -5
- package/build/es/__e2e__/tree_api.js +15 -21
- package/build/es/__stories__/custom-expanded-imperative-open.js +6 -8
- package/build/es/__stories__/custom-node-label.js +4 -5
- package/build/es/__stories__/development-stories.js +5 -6
- package/build/es/__stories__/loading-error-grandchild.js +1 -4
- package/build/es/__stories__/loading.js +1 -4
- package/build/es/__stories__/multiple-roots.js +9 -12
- package/build/es/__stories__/root-error.js +1 -4
- package/build/es/__stories__/root-loading.js +1 -4
- package/build/es/__stories__/shared.js +45 -77
- package/build/es/features/controlled_expanded/index.js +3 -6
- package/build/es/locales/index.js +40 -18
- package/build/es/organisation-unit-node/error-message.js +10 -13
- package/build/es/organisation-unit-node/label/disabled-selection-label.js +9 -12
- package/build/es/organisation-unit-node/label/icon-empty.js +19 -22
- package/build/es/organisation-unit-node/label/icon-folder-closed.js +25 -28
- package/build/es/organisation-unit-node/label/icon-folder-open.js +34 -37
- package/build/es/organisation-unit-node/label/icon-single.js +28 -31
- package/build/es/organisation-unit-node/label/icon.js +6 -7
- package/build/es/organisation-unit-node/label/iconized-checkbox.js +12 -13
- package/build/es/organisation-unit-node/label/label-container.js +13 -16
- package/build/es/organisation-unit-node/label/label.js +27 -30
- package/build/es/organisation-unit-node/label/single-selection-label.js +18 -21
- package/build/es/organisation-unit-node/organisation-unit-node-children.js +27 -29
- package/build/es/organisation-unit-node/organisation-unit-node.js +22 -23
- package/build/es/organisation-unit-node/use-open-state.js +8 -9
- package/build/es/organisation-unit-node/use-org-children.js +14 -21
- package/build/es/organisation-unit-node/use-org-children.test.js +40 -59
- package/build/es/organisation-unit-node/use-org-data/use-org-data.js +13 -20
- package/build/es/organisation-unit-node/use-org-data/use-org-data.test.js +17 -27
- package/build/es/organisation-unit-tree/default-render-node-label/default-render-node-label.js +3 -6
- package/build/es/organisation-unit-tree/organisation-unit-tree-root-error.js +9 -12
- package/build/es/organisation-unit-tree/organisation-unit-tree-root-loading.js +10 -13
- package/build/es/organisation-unit-tree/organisation-unit-tree.js +23 -24
- package/build/es/organisation-unit-tree/use-expanded/create-expand-handlers.js +14 -17
- package/build/es/organisation-unit-tree/use-expanded/use-expanded.js +8 -9
- package/build/es/organisation-unit-tree/use-root-org-data/patch-missing-display-name.js +1 -2
- package/build/es/organisation-unit-tree/use-root-org-data/use-root-org-data.js +10 -14
- package/build/es/organisation-unit-tree/use-root-org-data/use-root-org-unit.test.js +32 -46
- package/package.json +6 -6
- package/src/locales/index.js +57 -18
- 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,
|
|
11
|
-
|
|
12
|
-
|
|
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 =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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 =
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
}
|
|
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,
|
|
138
|
-
|
|
139
|
-
|
|
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 =
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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,
|
|
199
|
-
|
|
200
|
-
|
|
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 =
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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,
|
|
262
|
-
|
|
263
|
-
|
|
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 =
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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(
|
|
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,
|
|
25
|
-
|
|
26
|
-
|
|
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 =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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 =
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
}
|
|
95
|
-
};
|
|
84
|
+
}
|
|
85
|
+
}, children);
|
|
96
86
|
const {
|
|
97
87
|
result
|
|
98
88
|
} = (0, _react.renderHook)(() => (0, _useOrgData.useOrgData)('A0000000000', {
|
package/build/cjs/organisation-unit-tree/default-render-node-label/default-render-node-label.js
CHANGED
|
@@ -4,10 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.defaultRenderNodeLabel = void 0;
|
|
7
|
-
const defaultRenderNodeLabel =
|
|
8
|
-
|
|
9
|
-
|
|
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 =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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 =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
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 =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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 =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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 =
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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 =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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(
|
|
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:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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 =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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(
|
|
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(
|
|
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 =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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 =
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
}
|
|
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 =
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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']), {
|