@dhis2-ui/organisation-unit-tree 7.7.2 → 7.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/build/cjs/__e2e__/common.js +10 -4
  2. package/build/cjs/__e2e__/expanded.stories.e2e.js +54 -0
  3. package/build/cjs/__e2e__/sub_unit_as_root.stories.e2e.js +40 -0
  4. package/build/cjs/__stories__/development-stories.js +7 -3
  5. package/build/cjs/__stories__/multiple-roots.js +7 -4
  6. package/build/cjs/__stories__/shared.js +160 -94
  7. package/build/cjs/features/expanded/index.js +45 -0
  8. package/build/cjs/features/expanded.feature +27 -0
  9. package/build/cjs/features/sub_unit_as_root/index.js +58 -0
  10. package/build/cjs/features/sub_unit_as_root.feature +34 -0
  11. package/build/cjs/helpers/index.js +8 -0
  12. package/build/cjs/helpers/left-trim-to-root-id.js +12 -0
  13. package/build/cjs/organisation-unit-node/has-descendant-selected-paths.js +7 -1
  14. package/build/cjs/organisation-unit-node/label/label.js +23 -16
  15. package/build/cjs/organisation-unit-node/organisation-unit-node.js +30 -19
  16. package/build/cjs/organisation-unit-tree/organisation-unit-tree.js +3 -3
  17. package/build/es/__e2e__/common.js +10 -4
  18. package/build/es/__e2e__/expanded.stories.e2e.js +32 -0
  19. package/build/es/__e2e__/sub_unit_as_root.stories.e2e.js +22 -0
  20. package/build/es/__stories__/development-stories.js +7 -3
  21. package/build/es/__stories__/multiple-roots.js +7 -4
  22. package/build/es/__stories__/shared.js +136 -92
  23. package/build/es/features/expanded/index.js +43 -0
  24. package/build/es/features/expanded.feature +27 -0
  25. package/build/es/features/sub_unit_as_root/index.js +55 -0
  26. package/build/es/features/sub_unit_as_root.feature +34 -0
  27. package/build/es/helpers/index.js +1 -0
  28. package/build/es/helpers/left-trim-to-root-id.js +3 -0
  29. package/build/es/organisation-unit-node/has-descendant-selected-paths.js +7 -1
  30. package/build/es/organisation-unit-node/label/label.js +23 -16
  31. package/build/es/organisation-unit-node/organisation-unit-node.js +23 -13
  32. package/build/es/organisation-unit-tree/organisation-unit-tree.js +3 -3
  33. package/package.json +5 -5
  34. package/build/cjs/__e2e__/initially_expanded.stories.e2e.js +0 -30
  35. package/build/cjs/features/initially_expanded/index.js +0 -16
  36. package/build/cjs/features/initially_expanded.feature +0 -11
  37. package/build/es/__e2e__/initially_expanded.stories.e2e.js +0 -21
  38. package/build/es/features/initially_expanded/index.js +0 -13
  39. package/build/es/features/initially_expanded.feature +0 -11
@@ -167,20 +167,26 @@ StatefulMultiSelectionWrapper.propTypes = {
167
167
  };
168
168
 
169
169
  const createDecoratorStatefulMultiSelection = args => {
170
- return fn => /*#__PURE__*/_react.default.createElement(StatefulMultiSelectionWrapper, {
170
+ return Story => /*#__PURE__*/_react.default.createElement(StatefulMultiSelectionWrapper, {
171
171
  onSelectionChange: args === null || args === void 0 ? void 0 : args.onSelectionChange
172
- }, fn);
172
+ }, ({
173
+ selected,
174
+ onChange
175
+ }) => /*#__PURE__*/_react.default.createElement(Story, {
176
+ selected: selected,
177
+ onChange: onChange
178
+ }));
173
179
  };
174
180
 
175
181
  exports.createDecoratorStatefulMultiSelection = createDecoratorStatefulMultiSelection;
176
182
 
177
183
  const createDecoratorCustomDataProvider = args => {
178
184
  const data = (args === null || args === void 0 ? void 0 : args.data) || dataProviderData;
179
- return fn => {
185
+ return Story => {
180
186
  window.dataProviderData = data;
181
187
  return /*#__PURE__*/_react.default.createElement(_appRuntime.CustomDataProvider, {
182
188
  data: data
183
- }, fn());
189
+ }, /*#__PURE__*/_react.default.createElement(Story, null));
184
190
  };
185
191
  };
186
192
 
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.WithRootMainAndRootSubOrgUnit = exports.InitiallyExpandedPaths = exports.NoInitiallyExpandedPaths = exports.default = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ var _index = require("../index.js");
11
+
12
+ var _common = require("./common.js");
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ var _default = {
17
+ title: 'OrganisationUnitTree/expanded',
18
+ decorators: [(0, _common.createDecoratorStatefulMultiSelection)(), (0, _common.createDecoratorCustomDataProvider)()]
19
+ };
20
+ exports.default = _default;
21
+
22
+ const NoInitiallyExpandedPaths = (_, {
23
+ onChange,
24
+ selected
25
+ }) => /*#__PURE__*/_react.default.createElement(_index.OrganisationUnitTree, {
26
+ roots: "A0000000000",
27
+ selected: selected,
28
+ onChange: onChange
29
+ });
30
+
31
+ exports.NoInitiallyExpandedPaths = NoInitiallyExpandedPaths;
32
+
33
+ const InitiallyExpandedPaths = (_, {
34
+ onChange,
35
+ selected
36
+ }) => /*#__PURE__*/_react.default.createElement(_index.OrganisationUnitTree, {
37
+ roots: "A0000000000",
38
+ selected: selected,
39
+ onChange: onChange,
40
+ initiallyExpanded: ['/A0000000000']
41
+ });
42
+
43
+ exports.InitiallyExpandedPaths = InitiallyExpandedPaths;
44
+
45
+ const WithRootMainAndRootSubOrgUnit = (_, {
46
+ onChange,
47
+ selected
48
+ }) => /*#__PURE__*/_react.default.createElement(_index.OrganisationUnitTree, {
49
+ roots: ['A0000000000', 'A0000000001'],
50
+ selected: selected,
51
+ onChange: onChange
52
+ });
53
+
54
+ exports.WithRootMainAndRootSubOrgUnit = WithRootMainAndRootSubOrgUnit;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.MultipleRootSubAndOneMainOrgUnit = exports.default = void 0;
7
+
8
+ var _react = _interopRequireWildcard(require("react"));
9
+
10
+ var _index = require("../index.js");
11
+
12
+ var _common = require("./common.js");
13
+
14
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
+
16
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
+
18
+ var _default = {
19
+ title: 'OrganisationUnitTree',
20
+ decorators: [(0, _common.createDecoratorStatefulMultiSelection)(), (0, _common.createDecoratorCustomDataProvider)()]
21
+ };
22
+ exports.default = _default;
23
+
24
+ const MultipleRootSubAndOneMainOrgUnit = (_, {
25
+ selected,
26
+ onChange
27
+ }) => {
28
+ const [filter, setFilter] = (0, _react.useState)('');
29
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("input", {
30
+ type: "input",
31
+ onChange: e => setFilter(e.target.value)
32
+ }), /*#__PURE__*/_react.default.createElement(_index.OrganisationUnitTree, {
33
+ filter: filter ? filter.split(',') : [],
34
+ onChange: onChange,
35
+ selected: selected,
36
+ roots: ['A0000000000', 'A0000000001', 'A0000000002']
37
+ }));
38
+ };
39
+
40
+ exports.MultipleRootSubAndOneMainOrgUnit = MultipleRootSubAndOneMainOrgUnit;
@@ -28,12 +28,16 @@ const DX_onChange = (selected, setSelected, singleSelection) => ({
28
28
  checked
29
29
  });
30
30
  const pathIndex = selected.indexOf(path);
31
+ let nextSelected;
31
32
 
32
33
  if (checked) {
33
- setSelected(singleSelection ? [path] : [...selected, path]);
34
+ nextSelected = singleSelection ? [path] : [...selected, path];
34
35
  } else {
35
- setSelected(singleSelection ? [] : [...selected.slice(0, pathIndex), ...selected.slice(pathIndex + 1)]);
36
+ nextSelected = singleSelection ? [] : [...selected.slice(0, pathIndex), ...selected.slice(pathIndex + 1)];
36
37
  }
38
+
39
+ console.log('> nextSelected', nextSelected);
40
+ setSelected(nextSelected);
37
41
  };
38
42
 
39
43
  const Wrapper = props => {
@@ -89,7 +93,7 @@ const DxWithRealBackend = () => /*#__PURE__*/_react.default.createElement("div",
89
93
  }, /*#__PURE__*/_react.default.createElement(Wrapper //initiallyExpanded={['/ImspTQPwCqd/eIQbndfxQMb']}
90
94
  , {
91
95
  suppressAlphabeticalSorting: true,
92
- roots: "ImspTQPwCqd"
96
+ roots: ['ImspTQPwCqd', 'O6uvpzGd5pu', 'fdc6uOvgoji']
93
97
  })));
94
98
 
95
99
  exports.DxWithRealBackend = DxWithRealBackend;
@@ -13,12 +13,15 @@ var _shared = require("./shared.js");
13
13
 
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
16
- const MultipleRoots = () => /*#__PURE__*/_react.default.createElement(_index.OrganisationUnitTree, {
17
- onChange: _shared.onChange,
18
- name: "Root org unit",
16
+ const MultipleRoots = (_, {
17
+ onChange,
18
+ selected
19
+ }) => /*#__PURE__*/_react.default.createElement(_index.OrganisationUnitTree, {
20
+ selected: selected,
21
+ onChange: onChange,
19
22
  roots: ['A0000000000', 'A0000000001'],
20
23
  initiallyExpanded: ['/A0000000000/A0000000001']
21
24
  });
22
25
 
23
26
  exports.MultipleRoots = MultipleRoots;
24
- MultipleRoots.storyName = 'Multiple roots';
27
+ MultipleRoots.decorators = [(0, _shared.createDecoratorStatefulMultiSelection)(), (0, _shared.createDecoratorCustomDataProvider)()];
@@ -3,7 +3,21 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.customData = exports.onChildrenLoaded = exports.onCollapse = exports.onExpand = exports.onChange = exports.log = void 0;
6
+ exports.createDecoratorCustomDataProvider = exports.createDecoratorStatefulMultiSelection = exports.StatefulMultiSelectionWrapper = exports.customData = exports.getOrganisationUnitData = exports.onChildrenLoaded = exports.onCollapse = exports.onExpand = exports.onChange = exports.log = void 0;
7
+
8
+ var _appRuntime = require("@dhis2/app-runtime");
9
+
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
+
12
+ var _react = _interopRequireWildcard(require("react"));
13
+
14
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
+
16
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ /* eslint-disable react/display-name */
7
21
  const log = true;
8
22
  exports.log = log;
9
23
 
@@ -22,119 +36,171 @@ exports.onCollapse = onCollapse;
22
36
  const onChildrenLoaded = (...args) => log && console.log('onChildrenLoaded', ...args);
23
37
 
24
38
  exports.onChildrenLoaded = onChildrenLoaded;
25
- const customData = {
26
- organisationUnits: (type, {
27
- id
28
- }) => {
29
- let data;
30
- let delay = 0;
31
-
32
- if (id === 'A0000000000') {
33
- delay = 1000;
34
- data = {
35
- id: 'A0000000000',
36
- path: '/A0000000000',
37
- displayName: 'Org Unit 1',
38
- children: [{
39
- id: 'A0000000001',
40
- path: '/A0000000000/A0000000001',
41
- children: [{
42
- id: 'A0000000003'
43
- }, {
44
- id: 'A0000000004'
45
- }],
46
- displayName: 'Org Unit 2'
47
- }, {
48
- id: 'A0000000002',
49
- path: '/A0000000000/A0000000002',
50
- children: [],
51
- displayName: 'Org Unit 3'
52
- }, {
53
- id: 'A0000000006',
54
- path: '/A0000000000/A0000000006',
55
- children: [],
56
- displayName: 'Org Unit 7'
57
- }]
58
- };
59
- }
60
39
 
61
- if (id === 'A0000000001') {
62
- data = {
40
+ const getOrganisationUnitData = id => {
41
+ let data;
42
+
43
+ if (id === 'A0000000000') {
44
+ data = {
45
+ id: 'A0000000000',
46
+ path: '/A0000000000',
47
+ displayName: 'Org Unit 1',
48
+ children: [{
63
49
  id: 'A0000000001',
64
50
  path: '/A0000000000/A0000000001',
65
- displayName: 'Org Unit 2',
66
51
  children: [{
67
- id: 'A0000000003',
68
- path: '/A0000000000/A0000000001/A0000000003',
69
- children: [],
70
- displayName: 'Org Unit 4'
52
+ id: 'A0000000003'
71
53
  }, {
72
- id: 'A0000000004',
73
- path: '/A0000000000/A0000000001/A0000000004',
74
- children: [],
75
- displayName: 'Org Unit 5'
76
- }]
77
- };
78
- }
79
-
80
- if (id === 'A0000000002') {
81
- delay = 1000;
82
- data = {
83
- displayName: 'Org Unit 3',
54
+ id: 'A0000000004'
55
+ }],
56
+ displayName: 'Org Unit 2'
57
+ }, {
84
58
  id: 'A0000000002',
85
59
  path: '/A0000000000/A0000000002',
86
- children: []
87
- };
88
- }
60
+ children: [],
61
+ displayName: 'Org Unit 3'
62
+ }, {
63
+ id: 'A0000000006',
64
+ path: '/A0000000000/A0000000006',
65
+ children: [],
66
+ displayName: 'Org Unit 7'
67
+ }]
68
+ };
69
+ }
89
70
 
90
- if (id === 'A0000000003') {
91
- data = {
92
- displayName: 'Org Unit 4',
71
+ if (id === 'A0000000001') {
72
+ data = {
73
+ id: 'A0000000001',
74
+ path: '/A0000000000/A0000000001',
75
+ displayName: 'Org Unit 2',
76
+ children: [{
93
77
  id: 'A0000000003',
94
78
  path: '/A0000000000/A0000000001/A0000000003',
95
- children: [{
96
- id: 'A0000000007',
97
- path: '/A0000000000/A0000000001/A0000000003/A0000000007',
98
- children: [],
99
- displayName: 'Org Unit 8'
100
- }]
101
- };
102
- }
103
-
104
- if (id === 'A0000000004') {
105
- data = {
106
- displayName: 'Org Unit 5',
79
+ children: [],
80
+ displayName: 'Org Unit 4'
81
+ }, {
107
82
  id: 'A0000000004',
108
83
  path: '/A0000000000/A0000000001/A0000000004',
109
- children: []
110
- };
111
- }
84
+ children: [],
85
+ displayName: 'Org Unit 5'
86
+ }]
87
+ };
88
+ }
112
89
 
113
- if (id === 'A0000000006') {
114
- data = {
115
- displayName: 'Org Unit 7',
116
- id: 'A0000000006',
117
- path: '/A0000000000/A0000000006',
118
- children: []
119
- };
120
- }
90
+ if (id === 'A0000000002') {
91
+ data = {
92
+ displayName: 'Org Unit 3',
93
+ id: 'A0000000002',
94
+ path: '/A0000000000/A0000000002',
95
+ children: []
96
+ };
97
+ }
121
98
 
122
- if (id === 'A0000000007') {
123
- data = {
124
- displayName: 'Org Unit 8',
99
+ if (id === 'A0000000003') {
100
+ data = {
101
+ displayName: 'Org Unit 4',
102
+ id: 'A0000000003',
103
+ path: '/A0000000000/A0000000001/A0000000003',
104
+ children: [{
125
105
  id: 'A0000000007',
126
106
  path: '/A0000000000/A0000000001/A0000000003/A0000000007',
127
- children: []
128
- };
129
- }
107
+ children: [],
108
+ displayName: 'Org Unit 8'
109
+ }]
110
+ };
111
+ }
112
+
113
+ if (id === 'A0000000004') {
114
+ data = {
115
+ displayName: 'Org Unit 5',
116
+ id: 'A0000000004',
117
+ path: '/A0000000000/A0000000001/A0000000004',
118
+ children: []
119
+ };
120
+ }
121
+
122
+ if (id === 'A0000000006') {
123
+ data = {
124
+ displayName: 'Org Unit 7',
125
+ id: 'A0000000006',
126
+ path: '/A0000000000/A0000000006',
127
+ children: []
128
+ };
129
+ }
130
+
131
+ if (id === 'A0000000007') {
132
+ data = {
133
+ displayName: 'Org Unit 8',
134
+ id: 'A0000000007',
135
+ path: '/A0000000000/A0000000001/A0000000003/A0000000007',
136
+ children: []
137
+ };
138
+ }
139
+
140
+ return data;
141
+ };
142
+
143
+ exports.getOrganisationUnitData = getOrganisationUnitData;
144
+ const customData = {
145
+ organisationUnits: (_, {
146
+ id
147
+ }) => {
148
+ const data = getOrganisationUnitData(id);
130
149
 
131
150
  if (!data) {
132
151
  return Promise.reject(new Error('404 - Org unit not found'));
133
152
  }
134
153
 
135
- return new Promise(resolve => {
136
- setTimeout(() => resolve(data), delay);
137
- });
154
+ return Promise.resolve(data);
138
155
  }
139
156
  };
140
- exports.customData = customData;
157
+ exports.customData = customData;
158
+
159
+ const StatefulMultiSelectionWrapper = ({
160
+ children,
161
+ onSelectionChange = () => null
162
+ }) => {
163
+ const [selected, setSelected] = (0, _react.useState)([]);
164
+ return children({
165
+ selected,
166
+ onChange: (...args) => {
167
+ onChange(...args);
168
+ const [{
169
+ selected: newSelected
170
+ }] = args;
171
+ setSelected(newSelected);
172
+ onSelectionChange(newSelected);
173
+ }
174
+ });
175
+ };
176
+
177
+ exports.StatefulMultiSelectionWrapper = StatefulMultiSelectionWrapper;
178
+ StatefulMultiSelectionWrapper.propTypes = {
179
+ children: _propTypes.default.func.isRequired,
180
+ onSelectionChange: _propTypes.default.func
181
+ };
182
+
183
+ const createDecoratorStatefulMultiSelection = args => {
184
+ return Story => /*#__PURE__*/_react.default.createElement(StatefulMultiSelectionWrapper, {
185
+ onSelectionChange: args === null || args === void 0 ? void 0 : args.onSelectionChange
186
+ }, ({
187
+ selected,
188
+ onChange
189
+ }) => /*#__PURE__*/_react.default.createElement(Story, {
190
+ selected: selected,
191
+ onChange: onChange
192
+ }));
193
+ };
194
+
195
+ exports.createDecoratorStatefulMultiSelection = createDecoratorStatefulMultiSelection;
196
+
197
+ const createDecoratorCustomDataProvider = args => {
198
+ const data = (args === null || args === void 0 ? void 0 : args.data) || customData;
199
+ return Story => {
200
+ return /*#__PURE__*/_react.default.createElement(_appRuntime.CustomDataProvider, {
201
+ data: data
202
+ }, /*#__PURE__*/_react.default.createElement(Story, null));
203
+ };
204
+ };
205
+
206
+ exports.createDecoratorCustomDataProvider = createDecoratorCustomDataProvider;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ var _steps = require("cypress-cucumber-preprocessor/steps");
4
+
5
+ const getRootOrgUnitByLabel = label => {
6
+ const rootOrgUnitLabelSelector = `
7
+ [data-test="dhis2-uiwidgets-orgunittree"]
8
+ > [data-test="dhis2-uiwidgets-orgunittree-node"]
9
+ > [data-test="dhis2-uiwidgets-orgunittree-node-content"]
10
+ > [data-test="dhis2-uiwidgets-orgunittree-node-label"]
11
+ label
12
+ `;
13
+ return cy.contains(rootOrgUnitLabelSelector, label).parents('[data-test="dhis2-uiwidgets-orgunittree-node"]');
14
+ };
15
+
16
+ (0, _steps.Given)('a OrganisationUnitTree with children and no paths in the initiallyExpanded prop is rendered', () => {
17
+ cy.visitStory('OrganisationUnitTree/expanded', 'No initially expanded paths');
18
+ });
19
+ (0, _steps.Given)('a OrganisationUnitTree with children and the path of the first unit on the second level in the initiallyExpanded prop is rendered', () => {
20
+ cy.visitStory('OrganisationUnitTree/expanded', 'Initially expanded paths');
21
+ });
22
+ (0, _steps.Given)('both a sub org unit with children and a main org unit are root org units', () => {
23
+ cy.visitStory('OrganisationUnitTree/expanded', 'with root main and root sub org unit');
24
+ });
25
+ (0, _steps.Given)('the root main org unit is expanded', () => {
26
+ getRootOrgUnitByLabel('Org Unit 1').find('> [data-test="dhis2-uiwidgets-orgunittree-node-toggle"]').click();
27
+ });
28
+ (0, _steps.When)('the user expands the sub org unit within the main org unit tree', () => {
29
+ getRootOrgUnitByLabel('Org Unit 1').contains('[data-test="dhis2-uiwidgets-orgunittree-node"]', 'Org Unit 2').find('> [data-test="dhis2-uiwidgets-orgunittree-node-toggle"]').click().should('have.class', 'open');
30
+ });
31
+ (0, _steps.When)('the user expands the root sub org unit', () => {
32
+ getRootOrgUnitByLabel('Org Unit 2').find('> [data-test="dhis2-uiwidgets-orgunittree-node-toggle"]').click().should('have.class', 'open');
33
+ });
34
+ (0, _steps.Then)('the root unit is closed', () => {
35
+ cy.getOrgUnitByLabel('Org Unit 1').shouldBeAClosedNode();
36
+ });
37
+ (0, _steps.Then)('the root unit is opened', () => {
38
+ cy.getOrgUnitByLabel('Org Unit 1').shouldBeAnOrgUnitNode();
39
+ });
40
+ (0, _steps.Then)('the root sub org unit should not expand', () => {
41
+ getRootOrgUnitByLabel('Org Unit 2').find('> [data-test="dhis2-uiwidgets-orgunittree-node-toggle"]').should('not.have.class', 'open');
42
+ });
43
+ (0, _steps.Then)('the sub org unit within the main org unit tree should not expand', () => {
44
+ getRootOrgUnitByLabel('Org Unit 1').contains('[data-test="dhis2-uiwidgets-orgunittree-node"]', 'Org Unit 2').find('> [data-test="dhis2-uiwidgets-orgunittree-node-toggle"]').should('not.have.class', 'open');
45
+ });
@@ -0,0 +1,27 @@
1
+ Feature: Nodes can be expanded
2
+
3
+ Scenario: No initially expanded paths are provided
4
+ Given a OrganisationUnitTree with children and no paths in the initiallyExpanded prop is rendered
5
+ Then the root unit is closed
6
+
7
+ # The given step is really long.. but I don't know how to split it while
8
+ # being able to test/prepare that with cypress
9
+ Scenario: The first unit on the second level is provided as initially expanded path
10
+ Given a OrganisationUnitTree with children and the path of the first unit on the second level in the initiallyExpanded prop is rendered
11
+ Then the root unit is opened
12
+
13
+ # For info what a "sub", "main" and "root" unit is, see
14
+ # "sub_unit_as_root.feature"
15
+ Scenario: A sub org unit gets expanded within the main org unit tree
16
+ Given both a sub org unit with children and a main org unit are root org units
17
+ And the root main org unit is expanded
18
+ When the user expands the sub org unit within the main org unit tree
19
+ Then the root sub org unit should not expand
20
+
21
+ # For info what a "sub", "main" and "root" unit is, see
22
+ # "sub_unit_as_root.feature"
23
+ Scenario: A root sub org unit gets expanded which is also in the main org unit tree
24
+ Given both a sub org unit with children and a main org unit are root org units
25
+ And the root main org unit is expanded
26
+ When the user expands the root sub org unit
27
+ Then the sub org unit within the main org unit tree should not expand
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ var _steps = require("cypress-cucumber-preprocessor/steps");
4
+
5
+ const rootOrgUnitLabelSelector = `
6
+ [data-test="dhis2-uiwidgets-orgunittree"]
7
+ > [data-test="dhis2-uiwidgets-orgunittree-node"]
8
+ > [data-test="dhis2-uiwidgets-orgunittree-node-content"]
9
+ > [data-test="dhis2-uiwidgets-orgunittree-node-label"]
10
+ label
11
+ `;
12
+ (0, _steps.Given)('a sub org unit is a root org unit', () => {
13
+ cy.visitStory('OrganisationUnitTree', 'multiple root sub and one main org unit');
14
+ });
15
+ (0, _steps.Given)('both a sub org unit and a main org unit are root org units', () => {
16
+ cy.visitStory('OrganisationUnitTree', 'multiple root sub and one main org unit');
17
+ });
18
+ (0, _steps.Given)('both a sub org unit and a main org unit are root org units', () => {
19
+ cy.visitStory('OrganisationUnitTree', 'multiple root sub and one main org unit');
20
+ });
21
+ (0, _steps.Given)('multiple sub org units is a root org unit', () => {
22
+ cy.visitStory('OrganisationUnitTree', 'multiple root sub and one main org unit');
23
+ });
24
+ (0, _steps.Given)('the root sub org unit is a child of the root main org unit', () => {
25
+ cy.visitStory('OrganisationUnitTree', 'multiple root sub and one main org unit');
26
+ });
27
+ (0, _steps.Given)('the root sub org unit is a child of the root main org unit', () => {
28
+ cy.visitStory('OrganisationUnitTree', 'multiple root sub and one main org unit');
29
+ });
30
+ (0, _steps.Given)('the user provided one root sub org unit to the filter', () => {
31
+ cy.get('input[type="input"]').clear().type('/A0000000001');
32
+ });
33
+ (0, _steps.Given)('the user provided one non-root sub org unit to the filter', () => {
34
+ cy.get('input[type="input"]').clear().type('/A0000000000/A0000000006');
35
+ });
36
+ (0, _steps.When)('the user selects sub org unit in the main org unit tree', () => {
37
+ cy.contains('label', 'Org Unit 1').click();
38
+ cy.get('[data-test="dhis2-uiwidgets-orgunittree-node-content"]').contains('label', 'Org Unit 2').click();
39
+ });
40
+ (0, _steps.When)('the user selects the root sub org unit', () => {
41
+ cy.contains(rootOrgUnitLabelSelector, 'Org Unit 2').click();
42
+ });
43
+ (0, _steps.Then)('all root sub org units but the filtered sub org unit should be hidden', () => {
44
+ cy.contains(rootOrgUnitLabelSelector, 'Org Unit 2').should('exist');
45
+ cy.contains(rootOrgUnitLabelSelector, 'Org Unit 1').should('not.exist');
46
+ cy.contains(rootOrgUnitLabelSelector, 'Org Unit 3').should('not.exist');
47
+ });
48
+ (0, _steps.Then)('the root main org unit should be marked as indeterminate', () => {
49
+ cy.contains(rootOrgUnitLabelSelector, 'Org Unit 1').find('> .icon svg').should('have.class', 'indeterminate');
50
+ });
51
+ (0, _steps.Then)('the root sub org unit should be selected', () => {
52
+ cy.contains(rootOrgUnitLabelSelector, 'Org Unit 2').find('> .icon svg').should('have.class', 'checked');
53
+ });
54
+ (0, _steps.Then)('only the root main org units should be visible', () => {
55
+ cy.contains(rootOrgUnitLabelSelector, 'Org Unit 1').should('exist');
56
+ cy.contains(rootOrgUnitLabelSelector, 'Org Unit 2').should('not.exist');
57
+ cy.contains(rootOrgUnitLabelSelector, 'Org Unit 3').should('not.exist');
58
+ });
@@ -0,0 +1,34 @@
1
+ Feature: Sub-org units can be a root org unit
2
+
3
+ Main org unit : is an actual root org unit in the configured hierarchy
4
+ Sub org unit : is an org unit which is inside the tree of a "main org unit"
5
+ Root org unit : refers to an org unit which is a root node in the component
6
+ ---
7
+ Org unit components can have multiple selections in all of the scenarios
8
+
9
+ Scenario: The user selects the root sub org unit
10
+ Given a sub org unit is a root org unit
11
+ When the user selects the root sub org unit
12
+ Then the root sub org unit should be selected
13
+
14
+ Scenario: The user selects the root sub org unit which is included in the tree of a root main org unit
15
+ Given both a sub org unit and a main org unit are root org units
16
+ And the root sub org unit is a child of the root main org unit
17
+ When the user selects the root sub org unit
18
+ Then the root main org unit should be marked as indeterminate
19
+
20
+ Scenario: The user selects the a child in the root main org unit which is also a root sub org unit
21
+ Given both a sub org unit and a main org unit are root org units
22
+ And the root sub org unit is a child of the root main org unit
23
+ When the user selects sub org unit in the main org unit tree
24
+ Then the root sub org unit should be selected
25
+
26
+ Scenario: The user filtered the tree by a root sub unit path
27
+ Given multiple sub org units is a root org unit
28
+ And the user provided one root sub org unit to the filter
29
+ Then all root sub org units but the filtered sub org unit should be hidden
30
+
31
+ Scenario: The user filtered the tree by a non-root sub unit path in the root main org unit
32
+ Given multiple sub org units is a root org unit
33
+ And the user provided one non-root sub org unit to the filter
34
+ Then only the root main org units should be visible
@@ -9,6 +9,12 @@ Object.defineProperty(exports, "isPathIncluded", {
9
9
  return _isPathIncluded.isPathIncluded;
10
10
  }
11
11
  });
12
+ Object.defineProperty(exports, "leftTrimToRootId", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _leftTrimToRootId.leftTrimToRootId;
16
+ }
17
+ });
12
18
  Object.defineProperty(exports, "sortNodeChildrenAlphabetically", {
13
19
  enumerable: true,
14
20
  get: function () {
@@ -18,4 +24,6 @@ Object.defineProperty(exports, "sortNodeChildrenAlphabetically", {
18
24
 
19
25
  var _isPathIncluded = require("./is-path-included.js");
20
26
 
27
+ var _leftTrimToRootId = require("./left-trim-to-root-id.js");
28
+
21
29
  var _sortNodeChildrenAlphabetically = require("./sort-node-children-alphabetically.js");
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.leftTrimToRootId = void 0;
7
+
8
+ const leftTrimToRootId = (path, rootId) => {
9
+ return path.replace(new RegExp(`^.*(/${rootId})`), '$1');
10
+ };
11
+
12
+ exports.leftTrimToRootId = leftTrimToRootId;