@dhis2-ui/organisation-unit-tree 8.2.0 → 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
|
@@ -13,7 +13,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
13
13
|
describe('OrganisationUnitTree - useRootOrgData', () => {
|
|
14
14
|
// @TODO: Figure out why this is necessary at all...
|
|
15
15
|
const origError = console.error;
|
|
16
|
-
jest.spyOn(console, 'error').mockImplementation((
|
|
16
|
+
jest.spyOn(console, 'error').mockImplementation(function () {
|
|
17
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
18
|
+
args[_key] = arguments[_key];
|
|
19
|
+
}
|
|
20
|
+
|
|
17
21
|
const [err] = args;
|
|
18
22
|
|
|
19
23
|
if (!err.toString().match(/^Warning: An update to/)) {
|
|
@@ -23,7 +27,11 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
|
|
|
23
27
|
|
|
24
28
|
const origWarn = console.warn;
|
|
25
29
|
const dynamicQueryWarningMsg = "The query should be static, don't create it within the render loop!";
|
|
26
|
-
jest.spyOn(console, 'warn').mockImplementation((
|
|
30
|
+
jest.spyOn(console, 'warn').mockImplementation(function () {
|
|
31
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
32
|
+
args[_key2] = arguments[_key2];
|
|
33
|
+
}
|
|
34
|
+
|
|
27
35
|
const [err] = args;
|
|
28
36
|
|
|
29
37
|
if (!err.toString().match(dynamicQueryWarningMsg)) {
|
|
@@ -44,11 +52,14 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
|
|
|
44
52
|
})
|
|
45
53
|
};
|
|
46
54
|
|
|
47
|
-
const wrapper =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
const wrapper = _ref => {
|
|
56
|
+
let {
|
|
57
|
+
children
|
|
58
|
+
} = _ref;
|
|
59
|
+
return /*#__PURE__*/_react.default.createElement(_appRuntime.CustomDataProvider, {
|
|
60
|
+
data: dataProviderData
|
|
61
|
+
}, children);
|
|
62
|
+
};
|
|
52
63
|
|
|
53
64
|
it('should respond with `loading: false`, `error: null` and `data: null` initially', () => {
|
|
54
65
|
const {
|
|
@@ -84,15 +95,18 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
|
|
|
84
95
|
}));
|
|
85
96
|
});
|
|
86
97
|
it('should provide the error', async () => {
|
|
87
|
-
const errorWrapper =
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
98
|
+
const errorWrapper = _ref2 => {
|
|
99
|
+
let {
|
|
100
|
+
children
|
|
101
|
+
} = _ref2;
|
|
102
|
+
return /*#__PURE__*/_react.default.createElement(_appRuntime.CustomDataProvider, {
|
|
103
|
+
data: {
|
|
104
|
+
organisationUnits: async () => {
|
|
105
|
+
throw new Error('Error message');
|
|
106
|
+
}
|
|
93
107
|
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
108
|
+
}, children);
|
|
109
|
+
};
|
|
96
110
|
|
|
97
111
|
const {
|
|
98
112
|
result,
|
|
@@ -148,11 +162,14 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
|
|
|
148
162
|
})
|
|
149
163
|
};
|
|
150
164
|
|
|
151
|
-
const wrapperWithoutDisplayName =
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
165
|
+
const wrapperWithoutDisplayName = _ref3 => {
|
|
166
|
+
let {
|
|
167
|
+
children
|
|
168
|
+
} = _ref3;
|
|
169
|
+
return /*#__PURE__*/_react.default.createElement(_appRuntime.CustomDataProvider, {
|
|
170
|
+
data: dataProviderDataWithoutDisplayName
|
|
171
|
+
}, children);
|
|
172
|
+
};
|
|
156
173
|
|
|
157
174
|
const {
|
|
158
175
|
result,
|
|
@@ -30,28 +30,28 @@ Object.defineProperty(exports, "Collapsed", {
|
|
|
30
30
|
return _collapsed.Collapsed;
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
|
-
Object.defineProperty(exports, "
|
|
33
|
+
Object.defineProperty(exports, "CustomExpandedImperativeOpen", {
|
|
34
34
|
enumerable: true,
|
|
35
35
|
get: function () {
|
|
36
|
-
return
|
|
36
|
+
return _customExpandedImperativeOpen.CustomExpandedImperativeOpen;
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
|
-
Object.defineProperty(exports, "
|
|
39
|
+
Object.defineProperty(exports, "CustomNodeLabel", {
|
|
40
40
|
enumerable: true,
|
|
41
41
|
get: function () {
|
|
42
|
-
return
|
|
42
|
+
return _customNodeLabel.CustomNodeLabel;
|
|
43
43
|
}
|
|
44
44
|
});
|
|
45
|
-
Object.defineProperty(exports, "
|
|
45
|
+
Object.defineProperty(exports, "Expanded", {
|
|
46
46
|
enumerable: true,
|
|
47
47
|
get: function () {
|
|
48
|
-
return
|
|
48
|
+
return _expanded.Expanded;
|
|
49
49
|
}
|
|
50
50
|
});
|
|
51
|
-
Object.defineProperty(exports, "
|
|
51
|
+
Object.defineProperty(exports, "Filtered", {
|
|
52
52
|
enumerable: true,
|
|
53
53
|
get: function () {
|
|
54
|
-
return
|
|
54
|
+
return _filtered.Filtered;
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
57
|
Object.defineProperty(exports, "FilteredRoot", {
|
|
@@ -60,52 +60,52 @@ Object.defineProperty(exports, "FilteredRoot", {
|
|
|
60
60
|
return _filteredRoot.FilteredRoot;
|
|
61
61
|
}
|
|
62
62
|
});
|
|
63
|
-
Object.defineProperty(exports, "
|
|
63
|
+
Object.defineProperty(exports, "ForceReloadAll", {
|
|
64
64
|
enumerable: true,
|
|
65
65
|
get: function () {
|
|
66
|
-
return
|
|
66
|
+
return _forceReloadAll.ForceReloadAll;
|
|
67
67
|
}
|
|
68
68
|
});
|
|
69
|
-
Object.defineProperty(exports, "
|
|
69
|
+
Object.defineProperty(exports, "ForceReloadOneUnit", {
|
|
70
70
|
enumerable: true,
|
|
71
71
|
get: function () {
|
|
72
|
-
return
|
|
72
|
+
return _forceReloadOneUnit.ForceReloadOneUnit;
|
|
73
73
|
}
|
|
74
74
|
});
|
|
75
|
-
Object.defineProperty(exports, "
|
|
75
|
+
Object.defineProperty(exports, "Highlighted", {
|
|
76
76
|
enumerable: true,
|
|
77
77
|
get: function () {
|
|
78
|
-
return
|
|
78
|
+
return _highlighted.Highlighted;
|
|
79
79
|
}
|
|
80
80
|
});
|
|
81
|
-
Object.defineProperty(exports, "
|
|
81
|
+
Object.defineProperty(exports, "Indeterminate", {
|
|
82
82
|
enumerable: true,
|
|
83
83
|
get: function () {
|
|
84
|
-
return
|
|
84
|
+
return _indeterminate.Indeterminate;
|
|
85
85
|
}
|
|
86
86
|
});
|
|
87
|
-
Object.defineProperty(exports, "
|
|
87
|
+
Object.defineProperty(exports, "Loading", {
|
|
88
88
|
enumerable: true,
|
|
89
89
|
get: function () {
|
|
90
|
-
return
|
|
90
|
+
return _loading.Loading;
|
|
91
91
|
}
|
|
92
92
|
});
|
|
93
|
-
Object.defineProperty(exports, "
|
|
93
|
+
Object.defineProperty(exports, "LoadingErrorGrandchild", {
|
|
94
94
|
enumerable: true,
|
|
95
95
|
get: function () {
|
|
96
|
-
return
|
|
96
|
+
return _loadingErrorGrandchild.LoadingErrorGrandchild;
|
|
97
97
|
}
|
|
98
98
|
});
|
|
99
|
-
Object.defineProperty(exports, "
|
|
99
|
+
Object.defineProperty(exports, "MultipleRoots", {
|
|
100
100
|
enumerable: true,
|
|
101
101
|
get: function () {
|
|
102
|
-
return
|
|
102
|
+
return _multipleRoots.MultipleRoots;
|
|
103
103
|
}
|
|
104
104
|
});
|
|
105
|
-
Object.defineProperty(exports, "
|
|
105
|
+
Object.defineProperty(exports, "NoSelection", {
|
|
106
106
|
enumerable: true,
|
|
107
107
|
get: function () {
|
|
108
|
-
return
|
|
108
|
+
return _noSelection.NoSelection;
|
|
109
109
|
}
|
|
110
110
|
});
|
|
111
111
|
Object.defineProperty(exports, "ReplaceRoots", {
|
|
@@ -114,10 +114,10 @@ Object.defineProperty(exports, "ReplaceRoots", {
|
|
|
114
114
|
return _replaceRoots.ReplaceRoots;
|
|
115
115
|
}
|
|
116
116
|
});
|
|
117
|
-
Object.defineProperty(exports, "
|
|
117
|
+
Object.defineProperty(exports, "RootError", {
|
|
118
118
|
enumerable: true,
|
|
119
119
|
get: function () {
|
|
120
|
-
return
|
|
120
|
+
return _rootError.RootError;
|
|
121
121
|
}
|
|
122
122
|
});
|
|
123
123
|
Object.defineProperty(exports, "RootLoading", {
|
|
@@ -126,16 +126,16 @@ Object.defineProperty(exports, "RootLoading", {
|
|
|
126
126
|
return _rootLoading.RootLoading;
|
|
127
127
|
}
|
|
128
128
|
});
|
|
129
|
-
Object.defineProperty(exports, "
|
|
129
|
+
Object.defineProperty(exports, "SelectedMultiple", {
|
|
130
130
|
enumerable: true,
|
|
131
131
|
get: function () {
|
|
132
|
-
return
|
|
132
|
+
return _selectedMultiple.SelectedMultiple;
|
|
133
133
|
}
|
|
134
134
|
});
|
|
135
|
-
Object.defineProperty(exports, "
|
|
135
|
+
Object.defineProperty(exports, "SingleSelection", {
|
|
136
136
|
enumerable: true,
|
|
137
137
|
get: function () {
|
|
138
|
-
return
|
|
138
|
+
return _singleSelection.SingleSelection;
|
|
139
139
|
}
|
|
140
140
|
});
|
|
141
141
|
exports.default = void 0;
|
|
@@ -203,34 +203,9 @@ Object.keys(_developmentStories).forEach(function (key) {
|
|
|
203
203
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
204
204
|
|
|
205
205
|
const subtitle = 'Display, manipulate and select organization units displayed in a hierarchical tree';
|
|
206
|
-
const description = `
|
|
207
|
-
This is a complex, controlled component. It needs access to an App Runtime data provider to fetch org unit data.
|
|
208
|
-
|
|
209
|
-
Several props require arrays of org. unit paths (referred to as \`orgUnitPathPropType[]\` in the table below). Take a look at the \`initiallyExpanded\` and \`filter\` props in the example to see an example of the paths format.
|
|
210
|
-
|
|
211
|
-
Example:
|
|
212
|
-
|
|
213
|
-
\`\`\`js
|
|
214
|
-
import { OrganisationUnitTree } from '@dhis2/ui'
|
|
215
|
-
|
|
216
|
-
const orgUnitTree = (
|
|
217
|
-
<OrganisationUnitTree
|
|
218
|
-
name="Root org unit"
|
|
219
|
-
roots="A0000000000"
|
|
220
|
-
onChange={onChange}
|
|
221
|
-
onExpand={onExpand}
|
|
222
|
-
onCollapse={onCollapse}
|
|
223
|
-
onChildrenLoaded={onChildrenLoaded}
|
|
224
|
-
// Notice the format of the org unit paths
|
|
225
|
-
initiallyExpanded={['/A0000000000/A0000000001']}
|
|
226
|
-
filter={['/A0000000000/A0000000001/A0000000003']}
|
|
227
|
-
/>
|
|
228
|
-
)
|
|
229
|
-
\`\`\`
|
|
230
|
-
|
|
231
|
-
`;
|
|
206
|
+
const description = "\nThis is a complex, controlled component. It needs access to an App Runtime data provider to fetch org unit data.\n\nSeveral props require arrays of org. unit paths (referred to as `orgUnitPathPropType[]` in the table below). Take a look at the `initiallyExpanded` and `filter` props in the example to see an example of the paths format.\n\nExample:\n\n```js\nimport { OrganisationUnitTree } from '@dhis2/ui'\n\nconst orgUnitTree = (\n <OrganisationUnitTree\n name=\"Root org unit\"\n roots=\"A0000000000\"\n onChange={onChange}\n onExpand={onExpand}\n onCollapse={onCollapse}\n onChildrenLoaded={onChildrenLoaded}\n // Notice the format of the org unit paths\n initiallyExpanded={['/A0000000000/A0000000001']}\n filter={['/A0000000000/A0000000001/A0000000003']}\n />\n)\n```\n\n";
|
|
232
207
|
var _default = {
|
|
233
|
-
title: '
|
|
208
|
+
title: 'Organisation Unit Tree',
|
|
234
209
|
component: _index.OrganisationUnitTree,
|
|
235
210
|
decorators: [fn => /*#__PURE__*/_react.default.createElement(_appRuntime.CustomDataProvider, {
|
|
236
211
|
data: _shared.customData
|
package/build/cjs/prop-types.js
CHANGED
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.orgUnitPathPropType = exports.orgUnitIdPropType = void 0;
|
|
7
7
|
|
|
8
8
|
/* eslint-disable max-params */
|
|
9
9
|
const UNIT_ID_PATTERN = '[a-zA-Z][a-zA-Z0-9]{10}';
|
|
10
|
-
const orgUnitIdRegExp = new RegExp(
|
|
11
|
-
const orgUnitPathRegExp = new RegExp(
|
|
10
|
+
const orgUnitIdRegExp = new RegExp("^".concat(UNIT_ID_PATTERN, "$"));
|
|
11
|
+
const orgUnitPathRegExp = new RegExp("(/".concat(UNIT_ID_PATTERN, ")+"));
|
|
12
12
|
|
|
13
13
|
const orgUnitPathPropType = (propValue, key, compName, location, propFullName) => {
|
|
14
14
|
if (!orgUnitPathRegExp.test(propValue[key])) {
|
|
15
|
-
return new Error(
|
|
15
|
+
return new Error("Invalid org unit path `".concat(propValue[key], "` supplied to `").concat(compName, ".").concat(propFullName, "`"));
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
|
|
@@ -20,7 +20,7 @@ exports.orgUnitPathPropType = orgUnitPathPropType;
|
|
|
20
20
|
|
|
21
21
|
const orgUnitIdPropType = (propValue, key, compName, location, propFullName) => {
|
|
22
22
|
if (!orgUnitIdRegExp.test(propValue[key])) {
|
|
23
|
-
return new Error(
|
|
23
|
+
return new Error("Invalid org unit id `".concat(propValue[key], "` supplied to `").concat(compName, ".").concat(propFullName, "`"));
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
26
|
|
|
@@ -5,11 +5,14 @@ import { OrganisationUnitTree } from '../index.js';
|
|
|
5
5
|
import { StatefulMultiSelectionWrapper, dataProviderData, namespace } from './common.js';
|
|
6
6
|
storiesOf(namespace, module).add('Closed with children', () => /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
7
7
|
data: dataProviderData
|
|
8
|
-
}, /*#__PURE__*/React.createElement(StatefulMultiSelectionWrapper, null,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
}, /*#__PURE__*/React.createElement(StatefulMultiSelectionWrapper, null, _ref => {
|
|
9
|
+
let {
|
|
10
|
+
selected,
|
|
11
|
+
onChange
|
|
12
|
+
} = _ref;
|
|
13
|
+
return /*#__PURE__*/React.createElement(OrganisationUnitTree, {
|
|
14
|
+
roots: "A0000000000",
|
|
15
|
+
onChange: onChange,
|
|
16
|
+
selected: selected
|
|
17
|
+
});
|
|
18
|
+
})));
|
|
@@ -5,32 +5,36 @@ 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
7
|
|
|
8
|
-
const createResponse =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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]') ? {
|
|
8
|
+
const createResponse = _ref => {
|
|
9
|
+
let {
|
|
10
|
+
fields,
|
|
11
|
+
id,
|
|
12
|
+
path,
|
|
13
|
+
displayName,
|
|
27
14
|
children
|
|
28
|
-
}
|
|
29
|
-
|
|
15
|
+
} = _ref;
|
|
16
|
+
return { ...(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
|
+
};
|
|
30
33
|
|
|
31
|
-
export const getOrganisationUnitData = (id, {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
export const getOrganisationUnitData = (id, _ref2) => {
|
|
35
|
+
let {
|
|
36
|
+
fields
|
|
37
|
+
} = _ref2;
|
|
34
38
|
let data;
|
|
35
39
|
|
|
36
40
|
if (id === 'A0000000000') {
|
|
@@ -133,10 +137,11 @@ export const getOrganisationUnitData = (id, {
|
|
|
133
137
|
return data;
|
|
134
138
|
};
|
|
135
139
|
export const dataProviderData = {
|
|
136
|
-
organisationUnits: (_, {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
+
organisationUnits: (_, _ref3) => {
|
|
141
|
+
let {
|
|
142
|
+
id,
|
|
143
|
+
params = {}
|
|
144
|
+
} = _ref3;
|
|
140
145
|
console.log('id, params', id, params);
|
|
141
146
|
const data = getOrganisationUnitData(id, params);
|
|
142
147
|
|
|
@@ -147,16 +152,18 @@ export const dataProviderData = {
|
|
|
147
152
|
return Promise.resolve(data);
|
|
148
153
|
}
|
|
149
154
|
};
|
|
150
|
-
export const StatefulMultiSelectionWrapper =
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
155
|
+
export const StatefulMultiSelectionWrapper = _ref4 => {
|
|
156
|
+
let {
|
|
157
|
+
children,
|
|
158
|
+
onSelectionChange = () => null
|
|
159
|
+
} = _ref4;
|
|
154
160
|
const [selected, setSelected] = useState([]);
|
|
155
161
|
return children({
|
|
156
162
|
selected,
|
|
157
|
-
onChange:
|
|
158
|
-
|
|
159
|
-
|
|
163
|
+
onChange: _ref5 => {
|
|
164
|
+
let {
|
|
165
|
+
selected: newSelected
|
|
166
|
+
} = _ref5;
|
|
160
167
|
setSelected(newSelected);
|
|
161
168
|
onSelectionChange(newSelected);
|
|
162
169
|
}
|
|
@@ -169,13 +176,16 @@ StatefulMultiSelectionWrapper.propTypes = {
|
|
|
169
176
|
export const createDecoratorStatefulMultiSelection = args => {
|
|
170
177
|
return Story => /*#__PURE__*/React.createElement(StatefulMultiSelectionWrapper, {
|
|
171
178
|
onSelectionChange: args === null || args === void 0 ? void 0 : args.onSelectionChange
|
|
172
|
-
},
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
+
}, _ref6 => {
|
|
180
|
+
let {
|
|
181
|
+
selected,
|
|
182
|
+
onChange
|
|
183
|
+
} = _ref6;
|
|
184
|
+
return /*#__PURE__*/React.createElement(Story, {
|
|
185
|
+
selected: selected,
|
|
186
|
+
onChange: onChange
|
|
187
|
+
});
|
|
188
|
+
});
|
|
179
189
|
};
|
|
180
190
|
export const createDecoratorCustomDataProvider = args => {
|
|
181
191
|
const data = (args === null || args === void 0 ? void 0 : args.data) || dataProviderData;
|
|
@@ -12,17 +12,20 @@ export const Controlled = () => {
|
|
|
12
12
|
const initiallyExpanded = getAllExpandedOrgUnitPaths(window.initiallyExpandedPaths);
|
|
13
13
|
const [expanded, setExpanded] = useState(initiallyExpanded);
|
|
14
14
|
|
|
15
|
-
const handleExpand =
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const handleExpand = _ref => {
|
|
16
|
+
let {
|
|
17
|
+
path
|
|
18
|
+
} = _ref;
|
|
19
|
+
|
|
18
20
|
if (!expanded.includes(path)) {
|
|
19
21
|
setExpanded([...expanded, path]);
|
|
20
22
|
}
|
|
21
23
|
};
|
|
22
24
|
|
|
23
|
-
const handleCollapse =
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
const handleCollapse = _ref2 => {
|
|
26
|
+
let {
|
|
27
|
+
path
|
|
28
|
+
} = _ref2;
|
|
26
29
|
const pathIndex = expanded.indexOf(path);
|
|
27
30
|
|
|
28
31
|
if (pathIndex !== -1) {
|
|
@@ -4,7 +4,11 @@ import React from 'react';
|
|
|
4
4
|
import { OrganisationUnitTree } from '../index.js';
|
|
5
5
|
import { StatefulMultiSelectionWrapper, dataProviderData, namespace } from './common.js';
|
|
6
6
|
const dataProviderDataWithError = {
|
|
7
|
-
organisationUnits: (
|
|
7
|
+
organisationUnits: function () {
|
|
8
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
9
|
+
args[_key] = arguments[_key];
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
const [, {
|
|
9
13
|
id
|
|
10
14
|
}] = args;
|
|
@@ -5,28 +5,37 @@ export default {
|
|
|
5
5
|
title: 'OrganisationUnitTree/expanded',
|
|
6
6
|
decorators: [createDecoratorStatefulMultiSelection(), createDecoratorCustomDataProvider()]
|
|
7
7
|
};
|
|
8
|
-
export const NoInitiallyExpandedPaths = (_, {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
8
|
+
export const NoInitiallyExpandedPaths = (_, _ref) => {
|
|
9
|
+
let {
|
|
10
|
+
onChange,
|
|
11
|
+
selected
|
|
12
|
+
} = _ref;
|
|
13
|
+
return /*#__PURE__*/React.createElement(OrganisationUnitTree, {
|
|
14
|
+
roots: "A0000000000",
|
|
15
|
+
selected: selected,
|
|
16
|
+
onChange: onChange
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
export const InitiallyExpandedPaths = (_, _ref2) => {
|
|
20
|
+
let {
|
|
21
|
+
onChange,
|
|
22
|
+
selected
|
|
23
|
+
} = _ref2;
|
|
24
|
+
return /*#__PURE__*/React.createElement(OrganisationUnitTree, {
|
|
25
|
+
roots: "A0000000000",
|
|
26
|
+
selected: selected,
|
|
27
|
+
onChange: onChange,
|
|
28
|
+
initiallyExpanded: ['/A0000000000']
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
export const WithRootMainAndRootSubOrgUnit = (_, _ref3) => {
|
|
32
|
+
let {
|
|
33
|
+
onChange,
|
|
34
|
+
selected
|
|
35
|
+
} = _ref3;
|
|
36
|
+
return /*#__PURE__*/React.createElement(OrganisationUnitTree, {
|
|
37
|
+
roots: ['A0000000000', 'A0000000001'],
|
|
38
|
+
selected: selected,
|
|
39
|
+
onChange: onChange
|
|
40
|
+
});
|
|
41
|
+
};
|
|
@@ -4,7 +4,11 @@ import React, { useState } from 'react';
|
|
|
4
4
|
import { OrganisationUnitTree } from '../index.js';
|
|
5
5
|
import { StatefulMultiSelectionWrapper, dataProviderData, delayResponse, namespace } from './common.js';
|
|
6
6
|
const afterReloadData = {
|
|
7
|
-
organisationUnits: (
|
|
7
|
+
organisationUnits: function () {
|
|
8
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
9
|
+
args[_key] = arguments[_key];
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
const [, {
|
|
9
13
|
id
|
|
10
14
|
}] = args;
|
|
@@ -29,20 +33,23 @@ const ForceReloading = () => {
|
|
|
29
33
|
disabled: forceReload,
|
|
30
34
|
"data-test": "reload-all",
|
|
31
35
|
onClick: () => setForceReload(true)
|
|
32
|
-
}, "Force reload tree"), /*#__PURE__*/React.createElement(StatefulMultiSelectionWrapper, null,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
}, "Force reload tree"), /*#__PURE__*/React.createElement(StatefulMultiSelectionWrapper, null, _ref => {
|
|
37
|
+
let {
|
|
38
|
+
selected,
|
|
39
|
+
onChange
|
|
40
|
+
} = _ref;
|
|
41
|
+
return /*#__PURE__*/React.createElement(OrganisationUnitTree, {
|
|
42
|
+
roots: "A0000000000",
|
|
43
|
+
onChange: onChange,
|
|
44
|
+
selected: selected,
|
|
45
|
+
forceReload: forceReload,
|
|
46
|
+
onChildrenLoaded: data => {
|
|
47
|
+
if (data.A0000000000) {
|
|
48
|
+
setForceReload(false);
|
|
49
|
+
}
|
|
43
50
|
}
|
|
44
|
-
}
|
|
45
|
-
}))
|
|
51
|
+
});
|
|
52
|
+
}));
|
|
46
53
|
};
|
|
47
54
|
|
|
48
55
|
storiesOf(namespace, module).add('Force reloading', () => /*#__PURE__*/React.createElement(ForceReloading, null));
|
|
@@ -5,10 +5,13 @@ import { OrganisationUnitTree } from '../index.js';
|
|
|
5
5
|
import { StatefulMultiSelectionWrapper, dataProviderData, namespace } from './common.js';
|
|
6
6
|
storiesOf(namespace, module).add('Root highlighted', () => /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
7
7
|
data: dataProviderData
|
|
8
|
-
}, /*#__PURE__*/React.createElement(StatefulMultiSelectionWrapper, null,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
}, /*#__PURE__*/React.createElement(StatefulMultiSelectionWrapper, null, _ref => {
|
|
9
|
+
let {
|
|
10
|
+
onChange
|
|
11
|
+
} = _ref;
|
|
12
|
+
return /*#__PURE__*/React.createElement(OrganisationUnitTree, {
|
|
13
|
+
roots: "A0000000000",
|
|
14
|
+
onChange: onChange,
|
|
15
|
+
highlighted: ['/A0000000000']
|
|
16
|
+
});
|
|
17
|
+
})));
|
|
@@ -4,7 +4,11 @@ import React from 'react';
|
|
|
4
4
|
import { OrganisationUnitTree } from '../index.js';
|
|
5
5
|
import { StatefulMultiSelectionWrapper, dataProviderData, delayResponse, namespace } from './common.js';
|
|
6
6
|
const data = {
|
|
7
|
-
organisationUnits: (
|
|
7
|
+
organisationUnits: function () {
|
|
8
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
9
|
+
args[_key] = arguments[_key];
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
const [, {
|
|
9
13
|
id
|
|
10
14
|
}] = args;
|
|
@@ -22,9 +26,12 @@ const data = {
|
|
|
22
26
|
};
|
|
23
27
|
storiesOf(namespace, module).add('A0000000001 loading', () => /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
24
28
|
data: data
|
|
25
|
-
}, /*#__PURE__*/React.createElement(StatefulMultiSelectionWrapper, null,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
}, /*#__PURE__*/React.createElement(StatefulMultiSelectionWrapper, null, _ref => {
|
|
30
|
+
let {
|
|
31
|
+
onChange
|
|
32
|
+
} = _ref;
|
|
33
|
+
return /*#__PURE__*/React.createElement(OrganisationUnitTree, {
|
|
34
|
+
roots: "A0000000000",
|
|
35
|
+
onChange: onChange
|
|
36
|
+
});
|
|
37
|
+
})));
|