@dhis2-ui/organisation-unit-tree 7.16.1 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/__e2e__/common.js +51 -24
- package/build/cjs/__e2e__/tree_api.stories.e2e.js +13 -5
- package/build/cjs/__stories__/development-stories.js +1 -3
- package/build/cjs/__stories__/shared.js +50 -17
- package/build/cjs/features/controlled_expanded/index.js +9 -3
- package/build/cjs/features/tree_api/index.js +4 -3
- package/build/cjs/helpers/sort-node-children-alphabetically.js +2 -17
- package/build/cjs/locales/en/translations.json +3 -2
- package/build/cjs/organisation-unit-node/label/label.js +2 -5
- package/build/cjs/organisation-unit-node/loading-spinner.js +32 -0
- package/build/cjs/organisation-unit-node/organisation-unit-node-children.js +120 -0
- package/build/cjs/organisation-unit-node/organisation-unit-node.js +43 -68
- package/build/cjs/organisation-unit-node/use-org-children.js +81 -0
- package/build/cjs/organisation-unit-node/use-org-children.test.js +319 -0
- package/build/cjs/organisation-unit-node/use-org-data/use-org-data.js +10 -33
- package/build/cjs/organisation-unit-node/use-org-data/use-org-data.test.js +3 -169
- package/build/cjs/organisation-unit-tree/organisation-unit-tree.js +4 -2
- package/build/cjs/organisation-unit-tree/use-root-org-data/use-root-org-data.js +7 -5
- package/build/es/__e2e__/common.js +52 -24
- package/build/es/__e2e__/tree_api.stories.e2e.js +13 -5
- package/build/es/__stories__/development-stories.js +1 -3
- package/build/es/__stories__/shared.js +51 -17
- package/build/es/features/controlled_expanded/index.js +9 -3
- package/build/es/features/tree_api/index.js +4 -3
- package/build/es/helpers/sort-node-children-alphabetically.js +2 -17
- package/build/es/locales/en/translations.json +3 -2
- package/build/es/organisation-unit-node/label/label.js +2 -5
- package/build/es/organisation-unit-node/loading-spinner.js +17 -0
- package/build/es/organisation-unit-node/organisation-unit-node-children.js +103 -0
- package/build/es/organisation-unit-node/organisation-unit-node.js +41 -65
- package/build/es/organisation-unit-node/use-org-children.js +69 -0
- package/build/es/organisation-unit-node/use-org-children.test.js +311 -0
- package/build/es/organisation-unit-node/use-org-data/use-org-data.js +10 -31
- package/build/es/organisation-unit-node/use-org-data/use-org-data.test.js +3 -169
- package/build/es/organisation-unit-tree/organisation-unit-tree.js +4 -2
- package/build/es/organisation-unit-tree/use-root-org-data/use-root-org-data.js +7 -5
- package/package.json +5 -5
|
@@ -25,39 +25,59 @@ const delayResponse = (delay, response) => () => new Promise(resolve => setTimeo
|
|
|
25
25
|
|
|
26
26
|
exports.delayResponse = delayResponse;
|
|
27
27
|
|
|
28
|
-
const
|
|
28
|
+
const createResponse = ({
|
|
29
|
+
fields,
|
|
30
|
+
id,
|
|
31
|
+
path,
|
|
32
|
+
displayName,
|
|
33
|
+
children
|
|
34
|
+
}) => ({ ...(fields.includes('id') ? {
|
|
35
|
+
id
|
|
36
|
+
} : {}),
|
|
37
|
+
...(fields.includes('path') ? {
|
|
38
|
+
path
|
|
39
|
+
} : {}),
|
|
40
|
+
...(fields.includes('displayName') ? {
|
|
41
|
+
displayName
|
|
42
|
+
} : {}),
|
|
43
|
+
...(fields.includes('children::size') ? {
|
|
44
|
+
children: children.length
|
|
45
|
+
} : {}),
|
|
46
|
+
...(fields.includes('children[id,path,displayName]') ? {
|
|
47
|
+
children
|
|
48
|
+
} : {})
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const getOrganisationUnitData = (id, {
|
|
52
|
+
fields
|
|
53
|
+
}) => {
|
|
29
54
|
let data;
|
|
30
55
|
|
|
31
56
|
if (id === 'A0000000000') {
|
|
32
|
-
data = {
|
|
57
|
+
data = createResponse({
|
|
58
|
+
fields,
|
|
33
59
|
id: 'A0000000000',
|
|
34
60
|
path: '/A0000000000',
|
|
35
61
|
displayName: 'Org Unit 1',
|
|
36
62
|
children: [{
|
|
37
63
|
id: 'A0000000001',
|
|
38
64
|
path: '/A0000000000/A0000000001',
|
|
39
|
-
children: [{
|
|
40
|
-
id: 'A0000000003'
|
|
41
|
-
}, {
|
|
42
|
-
id: 'A0000000004'
|
|
43
|
-
}],
|
|
44
65
|
displayName: 'Org Unit 2'
|
|
45
66
|
}, {
|
|
46
67
|
id: 'A0000000002',
|
|
47
68
|
path: '/A0000000000/A0000000002',
|
|
48
|
-
children: [],
|
|
49
69
|
displayName: 'Org Unit 3'
|
|
50
70
|
}, {
|
|
51
71
|
id: 'A0000000006',
|
|
52
72
|
path: '/A0000000000/A0000000006',
|
|
53
|
-
children: [],
|
|
54
73
|
displayName: 'Org Unit 7'
|
|
55
74
|
}]
|
|
56
|
-
};
|
|
75
|
+
});
|
|
57
76
|
}
|
|
58
77
|
|
|
59
78
|
if (id === 'A0000000001') {
|
|
60
|
-
data = {
|
|
79
|
+
data = createResponse({
|
|
80
|
+
fields,
|
|
61
81
|
id: 'A0000000001',
|
|
62
82
|
path: '/A0000000000/A0000000001',
|
|
63
83
|
displayName: 'Org Unit 2',
|
|
@@ -72,20 +92,22 @@ const getOrganisationUnitData = id => {
|
|
|
72
92
|
children: [],
|
|
73
93
|
displayName: 'Org Unit 5'
|
|
74
94
|
}]
|
|
75
|
-
};
|
|
95
|
+
});
|
|
76
96
|
}
|
|
77
97
|
|
|
78
98
|
if (id === 'A0000000002') {
|
|
79
|
-
data = {
|
|
99
|
+
data = createResponse({
|
|
100
|
+
fields,
|
|
80
101
|
displayName: 'Org Unit 3',
|
|
81
102
|
id: 'A0000000002',
|
|
82
103
|
path: '/A0000000000/A0000000002',
|
|
83
104
|
children: []
|
|
84
|
-
};
|
|
105
|
+
});
|
|
85
106
|
}
|
|
86
107
|
|
|
87
108
|
if (id === 'A0000000003') {
|
|
88
|
-
data = {
|
|
109
|
+
data = createResponse({
|
|
110
|
+
fields,
|
|
89
111
|
displayName: 'Org Unit 4',
|
|
90
112
|
id: 'A0000000003',
|
|
91
113
|
path: '/A0000000000/A0000000001/A0000000003',
|
|
@@ -95,34 +117,37 @@ const getOrganisationUnitData = id => {
|
|
|
95
117
|
children: [],
|
|
96
118
|
displayName: 'Org Unit 8'
|
|
97
119
|
}]
|
|
98
|
-
};
|
|
120
|
+
});
|
|
99
121
|
}
|
|
100
122
|
|
|
101
123
|
if (id === 'A0000000004') {
|
|
102
|
-
data = {
|
|
124
|
+
data = createResponse({
|
|
125
|
+
fields,
|
|
103
126
|
displayName: 'Org Unit 5',
|
|
104
127
|
id: 'A0000000004',
|
|
105
128
|
path: '/A0000000000/A0000000001/A0000000004',
|
|
106
129
|
children: []
|
|
107
|
-
};
|
|
130
|
+
});
|
|
108
131
|
}
|
|
109
132
|
|
|
110
133
|
if (id === 'A0000000006') {
|
|
111
|
-
data = {
|
|
134
|
+
data = createResponse({
|
|
135
|
+
fields,
|
|
112
136
|
displayName: 'Org Unit 7',
|
|
113
137
|
id: 'A0000000006',
|
|
114
138
|
path: '/A0000000000/A0000000006',
|
|
115
139
|
children: []
|
|
116
|
-
};
|
|
140
|
+
});
|
|
117
141
|
}
|
|
118
142
|
|
|
119
143
|
if (id === 'A0000000007') {
|
|
120
|
-
data = {
|
|
144
|
+
data = createResponse({
|
|
145
|
+
fields,
|
|
121
146
|
displayName: 'Org Unit 8',
|
|
122
147
|
id: 'A0000000007',
|
|
123
148
|
path: '/A0000000000/A0000000001/A0000000003/A0000000007',
|
|
124
149
|
children: []
|
|
125
|
-
};
|
|
150
|
+
});
|
|
126
151
|
}
|
|
127
152
|
|
|
128
153
|
return data;
|
|
@@ -131,9 +156,11 @@ const getOrganisationUnitData = id => {
|
|
|
131
156
|
exports.getOrganisationUnitData = getOrganisationUnitData;
|
|
132
157
|
const dataProviderData = {
|
|
133
158
|
organisationUnits: (_, {
|
|
134
|
-
id
|
|
159
|
+
id,
|
|
160
|
+
params = {}
|
|
135
161
|
}) => {
|
|
136
|
-
|
|
162
|
+
console.log('id, params', id, params);
|
|
163
|
+
const data = getOrganisationUnitData(id, params);
|
|
137
164
|
|
|
138
165
|
if (!data) {
|
|
139
166
|
return Promise.reject(new Error('404 - Org unit not found'));
|
|
@@ -15,19 +15,27 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
15
15
|
const customizedDataProviderData = {
|
|
16
16
|
organisationUnits: (...args) => {
|
|
17
17
|
const [, {
|
|
18
|
-
id
|
|
18
|
+
id,
|
|
19
|
+
params
|
|
19
20
|
}] = args;
|
|
21
|
+
const {
|
|
22
|
+
fields
|
|
23
|
+
} = params;
|
|
20
24
|
|
|
21
25
|
if (id === 'A0000000000') {
|
|
22
|
-
return _common.dataProviderData.organisationUnits(...args).then(data =>
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
return _common.dataProviderData.organisationUnits(...args).then(data => {
|
|
27
|
+
var _data$children;
|
|
28
|
+
|
|
29
|
+
return { ...data,
|
|
30
|
+
children: fields.includes('children::size') ? 1 : (_data$children = data.children) === null || _data$children === void 0 ? void 0 : _data$children.slice(0, 1)
|
|
31
|
+
};
|
|
32
|
+
});
|
|
25
33
|
}
|
|
26
34
|
|
|
27
35
|
if (id === 'A0000000001') {
|
|
28
36
|
return _common.dataProviderData.organisationUnits(...args).then(data => ({ ...data,
|
|
29
37
|
path: '/A0000000001',
|
|
30
|
-
children: []
|
|
38
|
+
children: fields.includes('children::size') ? 0 : []
|
|
31
39
|
}));
|
|
32
40
|
}
|
|
33
41
|
|
|
@@ -90,9 +90,7 @@ const DxWithRealBackend = () => /*#__PURE__*/_react.default.createElement("div",
|
|
|
90
90
|
}, "Settings app / Access")), /*#__PURE__*/_react.default.createElement(_appRuntime.DataProvider, {
|
|
91
91
|
baseUrl: "https://debug.dhis2.org/dev",
|
|
92
92
|
apiVersion: ""
|
|
93
|
-
}, /*#__PURE__*/_react.default.createElement(Wrapper
|
|
94
|
-
, {
|
|
95
|
-
suppressAlphabeticalSorting: true,
|
|
93
|
+
}, /*#__PURE__*/_react.default.createElement(Wrapper, {
|
|
96
94
|
roots: ['ImspTQPwCqd', 'O6uvpzGd5pu', 'fdc6uOvgoji']
|
|
97
95
|
})));
|
|
98
96
|
|
|
@@ -36,11 +36,37 @@ const onChildrenLoaded = (...args) => log && console.log('onChildrenLoaded', ...
|
|
|
36
36
|
|
|
37
37
|
exports.onChildrenLoaded = onChildrenLoaded;
|
|
38
38
|
|
|
39
|
-
const
|
|
39
|
+
const createResponse = ({
|
|
40
|
+
fields,
|
|
41
|
+
id,
|
|
42
|
+
path,
|
|
43
|
+
displayName,
|
|
44
|
+
children
|
|
45
|
+
}) => ({ ...(fields.includes('id') ? {
|
|
46
|
+
id
|
|
47
|
+
} : {}),
|
|
48
|
+
...(fields.includes('path') ? {
|
|
49
|
+
path
|
|
50
|
+
} : {}),
|
|
51
|
+
...(fields.includes('displayName') ? {
|
|
52
|
+
displayName
|
|
53
|
+
} : {}),
|
|
54
|
+
...(fields.includes('children::size') ? {
|
|
55
|
+
children: children.length
|
|
56
|
+
} : {}),
|
|
57
|
+
...(fields.includes('children[id,path,displayName]') ? {
|
|
58
|
+
children
|
|
59
|
+
} : {})
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const getOrganisationUnitData = (id, {
|
|
63
|
+
fields
|
|
64
|
+
}) => {
|
|
40
65
|
let data;
|
|
41
66
|
|
|
42
67
|
if (id === 'A0000000000') {
|
|
43
|
-
data = {
|
|
68
|
+
data = createResponse({
|
|
69
|
+
fields,
|
|
44
70
|
id: 'A0000000000',
|
|
45
71
|
path: '/A0000000000',
|
|
46
72
|
displayName: 'Org Unit 1',
|
|
@@ -64,11 +90,12 @@ const getOrganisationUnitData = id => {
|
|
|
64
90
|
children: [],
|
|
65
91
|
displayName: 'Org Unit 7'
|
|
66
92
|
}]
|
|
67
|
-
};
|
|
93
|
+
});
|
|
68
94
|
}
|
|
69
95
|
|
|
70
96
|
if (id === 'A0000000001') {
|
|
71
|
-
data = {
|
|
97
|
+
data = createResponse({
|
|
98
|
+
fields,
|
|
72
99
|
id: 'A0000000001',
|
|
73
100
|
path: '/A0000000000/A0000000001',
|
|
74
101
|
displayName: 'Org Unit 2',
|
|
@@ -83,20 +110,22 @@ const getOrganisationUnitData = id => {
|
|
|
83
110
|
children: [],
|
|
84
111
|
displayName: 'Org Unit 5'
|
|
85
112
|
}]
|
|
86
|
-
};
|
|
113
|
+
});
|
|
87
114
|
}
|
|
88
115
|
|
|
89
116
|
if (id === 'A0000000002') {
|
|
90
|
-
data = {
|
|
117
|
+
data = createResponse({
|
|
118
|
+
fields,
|
|
91
119
|
displayName: 'Org Unit 3',
|
|
92
120
|
id: 'A0000000002',
|
|
93
121
|
path: '/A0000000000/A0000000002',
|
|
94
122
|
children: []
|
|
95
|
-
};
|
|
123
|
+
});
|
|
96
124
|
}
|
|
97
125
|
|
|
98
126
|
if (id === 'A0000000003') {
|
|
99
|
-
data = {
|
|
127
|
+
data = createResponse({
|
|
128
|
+
fields,
|
|
100
129
|
displayName: 'Org Unit 4',
|
|
101
130
|
id: 'A0000000003',
|
|
102
131
|
path: '/A0000000000/A0000000001/A0000000003',
|
|
@@ -106,34 +135,37 @@ const getOrganisationUnitData = id => {
|
|
|
106
135
|
children: [],
|
|
107
136
|
displayName: 'Org Unit 8'
|
|
108
137
|
}]
|
|
109
|
-
};
|
|
138
|
+
});
|
|
110
139
|
}
|
|
111
140
|
|
|
112
141
|
if (id === 'A0000000004') {
|
|
113
|
-
data = {
|
|
142
|
+
data = createResponse({
|
|
143
|
+
fields,
|
|
114
144
|
displayName: 'Org Unit 5',
|
|
115
145
|
id: 'A0000000004',
|
|
116
146
|
path: '/A0000000000/A0000000001/A0000000004',
|
|
117
147
|
children: []
|
|
118
|
-
};
|
|
148
|
+
});
|
|
119
149
|
}
|
|
120
150
|
|
|
121
151
|
if (id === 'A0000000006') {
|
|
122
|
-
data = {
|
|
152
|
+
data = createResponse({
|
|
153
|
+
fields,
|
|
123
154
|
displayName: 'Org Unit 7',
|
|
124
155
|
id: 'A0000000006',
|
|
125
156
|
path: '/A0000000000/A0000000006',
|
|
126
157
|
children: []
|
|
127
|
-
};
|
|
158
|
+
});
|
|
128
159
|
}
|
|
129
160
|
|
|
130
161
|
if (id === 'A0000000007') {
|
|
131
|
-
data = {
|
|
162
|
+
data = createResponse({
|
|
163
|
+
fields,
|
|
132
164
|
displayName: 'Org Unit 8',
|
|
133
165
|
id: 'A0000000007',
|
|
134
166
|
path: '/A0000000000/A0000000001/A0000000003/A0000000007',
|
|
135
167
|
children: []
|
|
136
|
-
};
|
|
168
|
+
});
|
|
137
169
|
}
|
|
138
170
|
|
|
139
171
|
return data;
|
|
@@ -142,9 +174,10 @@ const getOrganisationUnitData = id => {
|
|
|
142
174
|
exports.getOrganisationUnitData = getOrganisationUnitData;
|
|
143
175
|
const customData = {
|
|
144
176
|
organisationUnits: (_, {
|
|
145
|
-
id
|
|
177
|
+
id,
|
|
178
|
+
params = {}
|
|
146
179
|
}) => {
|
|
147
|
-
const data = getOrganisationUnitData(id);
|
|
180
|
+
const data = getOrganisationUnitData(id, params);
|
|
148
181
|
|
|
149
182
|
if (!data) {
|
|
150
183
|
return Promise.reject(new Error('404 - Org unit not found'));
|
|
@@ -5,7 +5,9 @@ var _steps = require("cypress-cucumber-preprocessor/steps");
|
|
|
5
5
|
var _common = require("../../__e2e__/common.js");
|
|
6
6
|
|
|
7
7
|
const expectOrgUnitsToBeDisplayed = ids => {
|
|
8
|
-
const expandedLabels = ids.map(id => (0, _common.getOrganisationUnitData)(id
|
|
8
|
+
const expandedLabels = ids.map(id => (0, _common.getOrganisationUnitData)(id, {
|
|
9
|
+
fields: ['displayName']
|
|
10
|
+
}).displayName);
|
|
9
11
|
expandedLabels.forEach(label => {
|
|
10
12
|
cy.get(`:contains("${label}")`).should('exist');
|
|
11
13
|
});
|
|
@@ -13,7 +15,9 @@ const expectOrgUnitsToBeDisplayed = ids => {
|
|
|
13
15
|
|
|
14
16
|
const expectOrgUnitsToNotBeDisplayed = ids => {
|
|
15
17
|
const expandedLabels = ids.map(id => {
|
|
16
|
-
const data = (0, _common.getOrganisationUnitData)(id
|
|
18
|
+
const data = (0, _common.getOrganisationUnitData)(id, {
|
|
19
|
+
fields: ['displayName']
|
|
20
|
+
});
|
|
17
21
|
return data.displayName;
|
|
18
22
|
});
|
|
19
23
|
expandedLabels.forEach(label => {
|
|
@@ -49,7 +53,9 @@ const expectOrgUnitsToNotBeDisplayed = ids => {
|
|
|
49
53
|
cy.get('@providedPaths').then(providedPaths => {
|
|
50
54
|
const providedIds = providedPaths.map(path => path.match(/[^/]+$/)[0]);
|
|
51
55
|
const hiddenChildrenIds = providedIds.reduce((acc, cur) => {
|
|
52
|
-
const curData = (0, _common.getOrganisationUnitData)(cur
|
|
56
|
+
const curData = (0, _common.getOrganisationUnitData)(cur, {
|
|
57
|
+
fields: ['children[id,path,displayName]']
|
|
58
|
+
});
|
|
53
59
|
const childrenIds = curData.children.map(({
|
|
54
60
|
id
|
|
55
61
|
}) => id);
|
|
@@ -97,9 +97,10 @@ const expectStubPayloadToEqual = (stub, prop, expected) => {
|
|
|
97
97
|
(0, _steps.Then)("the payload contains the loaded children's data", () => {
|
|
98
98
|
cy.window().should(win => {
|
|
99
99
|
const calls = win.onChildrenLoaded.getCalls();
|
|
100
|
-
|
|
100
|
+
expect(calls).to.have.length(1);
|
|
101
|
+
const [{
|
|
101
102
|
args
|
|
102
|
-
} = calls
|
|
103
|
-
expect(args[0].id).to.equal('
|
|
103
|
+
}] = calls;
|
|
104
|
+
expect(args[0].id).to.equal('A0000000000');
|
|
104
105
|
});
|
|
105
106
|
});
|
|
@@ -5,22 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.sortNodeChildrenAlphabetically = void 0;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return node;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const sortedChildren = [...node.children];
|
|
14
|
-
sortedChildren.sort((left, right) => {
|
|
15
|
-
if (left.displayName === right.displayName) {
|
|
16
|
-
return 0;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return left.displayName.localeCompare(right.displayName);
|
|
20
|
-
});
|
|
21
|
-
return { ...node,
|
|
22
|
-
children: sortedChildren
|
|
23
|
-
};
|
|
24
|
-
};
|
|
8
|
+
// sort mutates the original
|
|
9
|
+
const sortNodeChildrenAlphabetically = children => [...children].sort((left, right) => left.displayName.localeCompare(right.displayName));
|
|
25
10
|
|
|
26
11
|
exports.sortNodeChildrenAlphabetically = sortNodeChildrenAlphabetically;
|
|
@@ -86,7 +86,7 @@ const Label = ({
|
|
|
86
86
|
singleSelection,
|
|
87
87
|
rootId
|
|
88
88
|
}); // @TODO: It'd make more sense to pass the node as an object
|
|
89
|
-
//
|
|
89
|
+
// instead of spread it. But that'd be a breaking change
|
|
90
90
|
|
|
91
91
|
const payload = { ...node,
|
|
92
92
|
path: fullPath,
|
|
@@ -141,10 +141,7 @@ Label.propTypes = {
|
|
|
141
141
|
node: _propTypes.default.shape({
|
|
142
142
|
displayName: _propTypes.default.string.isRequired,
|
|
143
143
|
id: _propTypes.default.string.isRequired,
|
|
144
|
-
children: _propTypes.default.
|
|
145
|
-
displayName: _propTypes.default.string.isRequired,
|
|
146
|
-
id: _propTypes.default.string.isRequired
|
|
147
|
-
})),
|
|
144
|
+
children: _propTypes.default.number,
|
|
148
145
|
path: _propTypes.default.string
|
|
149
146
|
}).isRequired,
|
|
150
147
|
open: _propTypes.default.bool.isRequired,
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.LoadingSpinner = void 0;
|
|
7
|
+
|
|
8
|
+
var _style = _interopRequireDefault(require("styled-jsx/style"));
|
|
9
|
+
|
|
10
|
+
var _loader = require("@dhis2-ui/loader");
|
|
11
|
+
|
|
12
|
+
var _react = _interopRequireDefault(require("react"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
const loadingSpinnerStyles = {
|
|
17
|
+
styles: /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
18
|
+
id: "358163430"
|
|
19
|
+
}, [".extrasmall.jsx-358163430{display:block;margin:3px 0;}"]),
|
|
20
|
+
className: "jsx-358163430"
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const LoadingSpinner = () => /*#__PURE__*/_react.default.createElement("div", {
|
|
24
|
+
className: "jsx-2503342345"
|
|
25
|
+
}, /*#__PURE__*/_react.default.createElement(_loader.CircularLoader, {
|
|
26
|
+
extrasmall: true,
|
|
27
|
+
className: loadingSpinnerStyles.className
|
|
28
|
+
}), /*#__PURE__*/_react.default.createElement("style", null, loadingSpinnerStyles.styles), /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
29
|
+
id: "2503342345"
|
|
30
|
+
}, ["div.jsx-2503342345{width:24px;}"]));
|
|
31
|
+
|
|
32
|
+
exports.LoadingSpinner = LoadingSpinner;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.OrganisationUnitNodeChildren = void 0;
|
|
7
|
+
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
|
|
10
|
+
var _react = _interopRequireDefault(require("react"));
|
|
11
|
+
|
|
12
|
+
var _index = require("../helpers/index.js");
|
|
13
|
+
|
|
14
|
+
var _index2 = _interopRequireDefault(require("../locales/index.js"));
|
|
15
|
+
|
|
16
|
+
var _propTypes2 = require("../prop-types.js");
|
|
17
|
+
|
|
18
|
+
var _loadingSpinner = require("./loading-spinner.js");
|
|
19
|
+
|
|
20
|
+
var _useOrgChildren = require("./use-org-children.js");
|
|
21
|
+
|
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
+
|
|
24
|
+
const getFilteredChildren = ({
|
|
25
|
+
orgChildren,
|
|
26
|
+
filter,
|
|
27
|
+
node
|
|
28
|
+
}) => {
|
|
29
|
+
if (!(filter !== null && filter !== void 0 && filter.length)) {
|
|
30
|
+
return orgChildren;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return orgChildren.filter(child => {
|
|
34
|
+
return (0, _index.isPathIncluded)(filter, `${node.path}/${child.id}`);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const OrganisationUnitNodeChildren = ({
|
|
39
|
+
node,
|
|
40
|
+
autoExpandLoadingError,
|
|
41
|
+
dataTest,
|
|
42
|
+
disableSelection,
|
|
43
|
+
expanded,
|
|
44
|
+
filter,
|
|
45
|
+
highlighted,
|
|
46
|
+
isUserDataViewFallback,
|
|
47
|
+
onChange,
|
|
48
|
+
onChildrenLoaded,
|
|
49
|
+
onCollapse,
|
|
50
|
+
onExpand,
|
|
51
|
+
parentPath,
|
|
52
|
+
renderNodeLabel,
|
|
53
|
+
rootId,
|
|
54
|
+
selected,
|
|
55
|
+
singleSelection,
|
|
56
|
+
suppressAlphabeticalSorting,
|
|
57
|
+
OrganisationUnitNode
|
|
58
|
+
}) => {
|
|
59
|
+
const orgChildren = (0, _useOrgChildren.useOrgChildren)({
|
|
60
|
+
node,
|
|
61
|
+
isUserDataViewFallback,
|
|
62
|
+
suppressAlphabeticalSorting,
|
|
63
|
+
onComplete: onChildrenLoaded
|
|
64
|
+
});
|
|
65
|
+
const displayChildren = orgChildren.called && !orgChildren.loading && !orgChildren.error;
|
|
66
|
+
const filteredChildren = displayChildren ? getFilteredChildren({
|
|
67
|
+
orgChildren: orgChildren.data,
|
|
68
|
+
filter,
|
|
69
|
+
node
|
|
70
|
+
}) : [];
|
|
71
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, orgChildren.loading && /*#__PURE__*/_react.default.createElement(_loadingSpinner.LoadingSpinner, null), orgChildren.error && `Error: ${orgChildren.error}`, displayChildren && !filteredChildren.length && _index2.default.t('No children match filter'), !!filteredChildren.length && filteredChildren.map(child => {
|
|
72
|
+
const childPath = `${parentPath}/${child.id}`;
|
|
73
|
+
return /*#__PURE__*/_react.default.createElement(OrganisationUnitNode, {
|
|
74
|
+
autoExpandLoadingError: autoExpandLoadingError,
|
|
75
|
+
dataTest: dataTest,
|
|
76
|
+
disableSelection: disableSelection,
|
|
77
|
+
displayName: child.displayName,
|
|
78
|
+
expanded: expanded,
|
|
79
|
+
filter: filter,
|
|
80
|
+
highlighted: highlighted,
|
|
81
|
+
id: child.id,
|
|
82
|
+
isUserDataViewFallback: isUserDataViewFallback,
|
|
83
|
+
key: childPath,
|
|
84
|
+
onChange: onChange,
|
|
85
|
+
onChildrenLoaded: onChildrenLoaded,
|
|
86
|
+
onCollapse: onCollapse,
|
|
87
|
+
onExpand: onExpand,
|
|
88
|
+
path: childPath,
|
|
89
|
+
renderNodeLabel: renderNodeLabel,
|
|
90
|
+
rootId: rootId,
|
|
91
|
+
selected: selected,
|
|
92
|
+
singleSelection: singleSelection,
|
|
93
|
+
suppressAlphabeticalSorting: suppressAlphabeticalSorting
|
|
94
|
+
});
|
|
95
|
+
}));
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
exports.OrganisationUnitNodeChildren = OrganisationUnitNodeChildren;
|
|
99
|
+
OrganisationUnitNodeChildren.propTypes = {
|
|
100
|
+
// Prevent cirular imports
|
|
101
|
+
OrganisationUnitNode: _propTypes.default.func.isRequired,
|
|
102
|
+
dataTest: _propTypes.default.string.isRequired,
|
|
103
|
+
node: _propTypes.default.object.isRequired,
|
|
104
|
+
parentPath: _propTypes.default.string.isRequired,
|
|
105
|
+
renderNodeLabel: _propTypes.default.func.isRequired,
|
|
106
|
+
rootId: _propTypes.default.string.isRequired,
|
|
107
|
+
onChange: _propTypes.default.func.isRequired,
|
|
108
|
+
autoExpandLoadingError: _propTypes.default.bool,
|
|
109
|
+
disableSelection: _propTypes.default.bool,
|
|
110
|
+
expanded: _propTypes.default.arrayOf(_propTypes2.orgUnitPathPropType),
|
|
111
|
+
filter: _propTypes.default.arrayOf(_propTypes2.orgUnitPathPropType),
|
|
112
|
+
highlighted: _propTypes.default.arrayOf(_propTypes2.orgUnitPathPropType),
|
|
113
|
+
isUserDataViewFallback: _propTypes.default.bool,
|
|
114
|
+
selected: _propTypes.default.arrayOf(_propTypes2.orgUnitPathPropType),
|
|
115
|
+
singleSelection: _propTypes.default.bool,
|
|
116
|
+
suppressAlphabeticalSorting: _propTypes.default.bool,
|
|
117
|
+
onChildrenLoaded: _propTypes.default.func,
|
|
118
|
+
onCollapse: _propTypes.default.func,
|
|
119
|
+
onExpand: _propTypes.default.func
|
|
120
|
+
};
|