@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.
- package/build/cjs/__e2e__/children_as_child_nodes.stories.e2e.js +11 -8
- package/build/cjs/__e2e__/common.js +53 -43
- package/build/cjs/__e2e__/controlled_expanded.stories.e2e.js +10 -7
- package/build/cjs/__e2e__/displaying_loading_error.stories.e2e.js +5 -1
- package/build/cjs/__e2e__/expanded.stories.e2e.js +35 -26
- package/build/cjs/__e2e__/force_reload.stories.e2e.js +21 -14
- package/build/cjs/__e2e__/highlight.stories.e2e.js +10 -7
- package/build/cjs/__e2e__/loading_state.stories.e2e.js +14 -7
- package/build/cjs/__e2e__/multi_selection.stories.e2e.js +11 -8
- package/build/cjs/__e2e__/no_selection.stories.e2e.js +21 -15
- package/build/cjs/__e2e__/path_based_filtering.stories.e2e.js +23 -17
- package/build/cjs/__e2e__/single_selection.stories.e2e.js +17 -10
- package/build/cjs/__e2e__/sub_unit_as_root.stories.e2e.js +6 -5
- package/build/cjs/__e2e__/tree_api.stories.e2e.js +22 -15
- package/build/cjs/__stories__/custom-expanded-imperative-open.js +9 -6
- package/build/cjs/__stories__/custom-node-label.js +6 -4
- package/build/cjs/__stories__/development-stories.js +7 -6
- package/build/cjs/__stories__/loading-error-grandchild.js +5 -1
- package/build/cjs/__stories__/loading.js +5 -1
- package/build/cjs/__stories__/multiple-roots.js +12 -9
- package/build/cjs/__stories__/root-error.js +5 -1
- package/build/cjs/__stories__/root-loading.js +5 -1
- package/build/cjs/__stories__/shared.js +82 -45
- package/build/cjs/features/controlled_expanded/index.js +8 -5
- package/build/cjs/features/expanded/index.js +1 -7
- package/build/cjs/features/path_based_filtering/index.js +2 -2
- package/build/cjs/features/sub_unit_as_root/index.js +1 -7
- package/build/cjs/get-all-expanded-paths/get-all-expanded-paths.js +1 -1
- package/build/cjs/helpers/is-path-included.js +1 -1
- package/build/cjs/helpers/left-trim-to-root-id.js +1 -1
- package/build/cjs/organisation-unit-node/compute-child-nodes.js +1 -1
- package/build/cjs/organisation-unit-node/error-message.js +13 -10
- package/build/cjs/organisation-unit-node/has-descendant-selected-paths.js +1 -1
- package/build/cjs/organisation-unit-node/label/disabled-selection-label.js +12 -9
- package/build/cjs/organisation-unit-node/label/icon-empty.js +22 -19
- package/build/cjs/organisation-unit-node/label/icon-folder-closed.js +28 -25
- package/build/cjs/organisation-unit-node/label/icon-folder-open.js +37 -34
- package/build/cjs/organisation-unit-node/label/icon-single.js +31 -28
- package/build/cjs/organisation-unit-node/label/icon.js +8 -6
- package/build/cjs/organisation-unit-node/label/iconized-checkbox.js +14 -12
- package/build/cjs/organisation-unit-node/label/label-container.js +16 -13
- package/build/cjs/organisation-unit-node/label/label.js +31 -27
- package/build/cjs/organisation-unit-node/label/single-selection-label.js +21 -18
- package/build/cjs/organisation-unit-node/organisation-unit-node-children.js +32 -29
- package/build/cjs/organisation-unit-node/organisation-unit-node.js +26 -25
- package/build/cjs/organisation-unit-node/use-open-state.js +9 -8
- package/build/cjs/organisation-unit-node/use-org-children.js +13 -9
- package/build/cjs/organisation-unit-node/use-org-children.test.js +69 -46
- package/build/cjs/organisation-unit-node/use-org-data/use-org-data.js +22 -14
- package/build/cjs/organisation-unit-node/use-org-data/use-org-data.test.js +30 -18
- package/build/cjs/organisation-unit-tree/default-render-node-label/default-render-node-label.js +6 -3
- package/build/cjs/organisation-unit-tree/filter-root-ids.js +1 -1
- package/build/cjs/organisation-unit-tree/organisation-unit-tree.js +23 -22
- package/build/cjs/organisation-unit-tree/root-error.js +12 -9
- package/build/cjs/organisation-unit-tree/root-loading.js +13 -10
- package/build/cjs/organisation-unit-tree/use-expanded/create-expand-handlers.js +19 -14
- package/build/cjs/organisation-unit-tree/use-expanded/use-expanded.js +9 -8
- package/build/cjs/organisation-unit-tree/use-root-org-data/patch-missing-display-name.js +2 -1
- package/build/cjs/organisation-unit-tree/use-root-org-data/use-root-org-data.js +14 -10
- package/build/cjs/organisation-unit-tree/use-root-org-data/use-root-org-unit.test.js +37 -20
- package/build/cjs/organisation-unit-tree.stories.js +32 -57
- package/build/cjs/prop-types.js +5 -5
- package/build/es/__e2e__/children_as_child_nodes.stories.e2e.js +11 -8
- package/build/es/__e2e__/common.js +52 -42
- package/build/es/__e2e__/controlled_expanded.stories.e2e.js +9 -6
- package/build/es/__e2e__/displaying_loading_error.stories.e2e.js +5 -1
- package/build/es/__e2e__/expanded.stories.e2e.js +34 -25
- package/build/es/__e2e__/force_reload.stories.e2e.js +21 -14
- package/build/es/__e2e__/highlight.stories.e2e.js +10 -7
- package/build/es/__e2e__/loading_state.stories.e2e.js +14 -7
- package/build/es/__e2e__/multi_selection.stories.e2e.js +11 -8
- package/build/es/__e2e__/no_selection.stories.e2e.js +21 -15
- package/build/es/__e2e__/path_based_filtering.stories.e2e.js +23 -17
- package/build/es/__e2e__/single_selection.stories.e2e.js +17 -10
- package/build/es/__e2e__/sub_unit_as_root.stories.e2e.js +5 -4
- package/build/es/__e2e__/tree_api.stories.e2e.js +22 -15
- package/build/es/__stories__/custom-expanded-imperative-open.js +9 -6
- package/build/es/__stories__/custom-node-label.js +6 -4
- package/build/es/__stories__/development-stories.js +6 -5
- package/build/es/__stories__/loading-error-grandchild.js +5 -1
- package/build/es/__stories__/loading.js +5 -1
- package/build/es/__stories__/multiple-roots.js +12 -9
- package/build/es/__stories__/root-error.js +5 -1
- package/build/es/__stories__/root-loading.js +5 -1
- package/build/es/__stories__/shared.js +82 -45
- package/build/es/features/controlled_expanded/index.js +8 -5
- package/build/es/features/expanded/index.js +1 -7
- package/build/es/features/path_based_filtering/index.js +2 -2
- package/build/es/features/sub_unit_as_root/index.js +1 -7
- package/build/es/get-all-expanded-paths/get-all-expanded-paths.js +1 -1
- package/build/es/helpers/is-path-included.js +1 -1
- package/build/es/helpers/left-trim-to-root-id.js +1 -1
- package/build/es/organisation-unit-node/compute-child-nodes.js +1 -1
- package/build/es/organisation-unit-node/error-message.js +13 -10
- package/build/es/organisation-unit-node/has-descendant-selected-paths.js +1 -1
- package/build/es/organisation-unit-node/label/disabled-selection-label.js +12 -9
- package/build/es/organisation-unit-node/label/icon-empty.js +22 -19
- package/build/es/organisation-unit-node/label/icon-folder-closed.js +28 -25
- package/build/es/organisation-unit-node/label/icon-folder-open.js +37 -34
- package/build/es/organisation-unit-node/label/icon-single.js +31 -28
- package/build/es/organisation-unit-node/label/icon.js +8 -6
- package/build/es/organisation-unit-node/label/iconized-checkbox.js +13 -12
- package/build/es/organisation-unit-node/label/label-container.js +16 -13
- package/build/es/organisation-unit-node/label/label.js +31 -27
- package/build/es/organisation-unit-node/label/single-selection-label.js +21 -18
- package/build/es/organisation-unit-node/organisation-unit-node-children.js +32 -29
- package/build/es/organisation-unit-node/organisation-unit-node.js +26 -25
- package/build/es/organisation-unit-node/use-open-state.js +9 -8
- package/build/es/organisation-unit-node/use-org-children.js +13 -9
- package/build/es/organisation-unit-node/use-org-children.test.js +69 -46
- package/build/es/organisation-unit-node/use-org-data/use-org-data.js +22 -14
- package/build/es/organisation-unit-node/use-org-data/use-org-data.test.js +30 -18
- package/build/es/organisation-unit-tree/default-render-node-label/default-render-node-label.js +6 -3
- package/build/es/organisation-unit-tree/filter-root-ids.js +1 -1
- package/build/es/organisation-unit-tree/organisation-unit-tree.js +23 -22
- package/build/es/organisation-unit-tree/root-error.js +12 -9
- package/build/es/organisation-unit-tree/root-loading.js +13 -10
- package/build/es/organisation-unit-tree/use-expanded/create-expand-handlers.js +19 -14
- package/build/es/organisation-unit-tree/use-expanded/use-expanded.js +9 -8
- package/build/es/organisation-unit-tree/use-root-org-data/patch-missing-display-name.js +2 -1
- package/build/es/organisation-unit-tree/use-root-org-data/use-root-org-data.js +14 -10
- package/build/es/organisation-unit-tree/use-root-org-data/use-root-org-unit.test.js +37 -20
- package/build/es/organisation-unit-tree.stories.js +2 -27
- package/build/es/prop-types.js +4 -4
- 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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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(
|
|
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:
|
|
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:
|
|
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":
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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:
|
|
7
|
-
id:
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
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(
|
|
23
|
+
return Promise.reject("No org unit with id \"".concat(id, "\""));
|
|
22
24
|
})
|
|
23
25
|
};
|
|
24
26
|
|
|
25
|
-
const wrapper =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
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(
|
|
161
|
+
return Promise.reject("No org unit with id \"".concat(id, "\""));
|
|
152
162
|
})
|
|
153
163
|
};
|
|
154
164
|
|
|
155
|
-
const wrapperWithUnsortedChildren =
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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(
|
|
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
|
-
|
|
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(
|
|
225
|
+
return Promise.reject("No org unit with id \"".concat(id, "\""));
|
|
211
226
|
})
|
|
212
227
|
};
|
|
213
228
|
|
|
214
|
-
const wrapperWithUnsortedChildren =
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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(
|
|
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
|
-
|
|
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(
|
|
291
|
+
return Promise.reject("No org unit with id \"".concat(id, "\""));
|
|
272
292
|
})
|
|
273
293
|
};
|
|
274
294
|
|
|
275
|
-
const wrapperWithUnsortedChildren =
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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:
|
|
5
|
-
id:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
26
|
-
|
|
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((
|
|
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
|
-
|
|
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(
|
|
36
|
+
return Promise.reject("No org unit with id \"".concat(id, "\""));
|
|
31
37
|
})
|
|
32
38
|
};
|
|
33
39
|
|
|
34
|
-
const wrapper =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
}
|
|
97
|
+
}, children);
|
|
98
|
+
};
|
|
87
99
|
|
|
88
100
|
const {
|
|
89
101
|
result,
|
|
@@ -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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
},
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
33
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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);
|