@snack-uikit/tree 0.9.37-preview-c4cc1815.0 → 0.9.37-preview-ea1a9bc3.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/dist/cjs/helperComponents/ExpandableTreeNode/ExpandableTreeNode.js +1 -1
- package/dist/cjs/helpers/__tests__/collectIds.spec.d.ts +1 -0
- package/dist/cjs/helpers/__tests__/collectIds.spec.js +14 -0
- package/dist/cjs/helpers/__tests__/constants.d.ts +2 -0
- package/dist/cjs/helpers/__tests__/constants.js +42 -0
- package/dist/cjs/helpers/__tests__/getSearchedTreeItems.spec.d.ts +1 -0
- package/dist/cjs/helpers/__tests__/getSearchedTreeItems.spec.js +183 -0
- package/dist/cjs/helpers/__tests__/getSearchedTreeNodeById.spec.d.ts +1 -0
- package/dist/cjs/helpers/__tests__/getSearchedTreeNodeById.spec.js +123 -0
- package/dist/cjs/helpers/checkNestedNodesSelection.d.ts +5 -0
- package/dist/cjs/helpers/checkNestedNodesSelection.js +17 -0
- package/dist/cjs/helpers/collectIds.d.ts +2 -0
- package/dist/cjs/helpers/collectIds.js +13 -0
- package/dist/cjs/helpers/extractTreeNodeTitle.d.ts +2 -0
- package/dist/cjs/helpers/extractTreeNodeTitle.js +15 -0
- package/dist/cjs/helpers/findAllChildNodeIds.d.ts +2 -0
- package/dist/cjs/helpers/findAllChildNodeIds.js +21 -0
- package/dist/cjs/helpers/findAllExpandedChildNodeIds.d.ts +2 -0
- package/dist/cjs/helpers/findAllExpandedChildNodeIds.js +19 -0
- package/dist/cjs/helpers/getSearchedTreeItems.d.ts +10 -0
- package/dist/cjs/helpers/getSearchedTreeItems.js +43 -0
- package/dist/cjs/helpers/getSearchedTreeNodeById.d.ts +11 -0
- package/dist/cjs/helpers/getSearchedTreeNodeById.js +39 -0
- package/dist/cjs/helpers/index.d.ts +8 -0
- package/dist/cjs/helpers/index.js +32 -0
- package/dist/cjs/helpers/lookupTreeForSelectedNodes.d.ts +6 -0
- package/dist/cjs/{helpers.js → helpers/lookupTreeForSelectedNodes.js} +5 -43
- package/dist/cjs/helpers/sortTreeItemsByTitle.d.ts +2 -0
- package/dist/cjs/helpers/sortTreeItemsByTitle.js +13 -0
- package/dist/cjs/helpers/traverse.d.ts +2 -0
- package/dist/cjs/helpers/traverse.js +40 -0
- package/dist/cjs/types.d.ts +3 -0
- package/dist/esm/helpers/__tests__/collectIds.spec.d.ts +1 -0
- package/dist/esm/helpers/__tests__/collectIds.spec.js +20 -0
- package/dist/esm/helpers/__tests__/constants.d.ts +2 -0
- package/dist/esm/helpers/__tests__/constants.js +52 -0
- package/dist/esm/helpers/__tests__/getSearchedTreeItems.spec.d.ts +1 -0
- package/dist/esm/helpers/__tests__/getSearchedTreeItems.spec.js +165 -0
- package/dist/esm/helpers/__tests__/getSearchedTreeNodeById.spec.d.ts +1 -0
- package/dist/esm/helpers/__tests__/getSearchedTreeNodeById.spec.js +112 -0
- package/dist/esm/helpers/checkNestedNodesSelection.d.ts +5 -0
- package/dist/esm/helpers/checkNestedNodesSelection.js +11 -0
- package/dist/esm/helpers/collectIds.d.ts +2 -0
- package/dist/esm/helpers/collectIds.js +6 -0
- package/dist/esm/helpers/extractTreeNodeTitle.d.ts +2 -0
- package/dist/esm/helpers/extractTreeNodeTitle.js +1 -0
- package/dist/esm/helpers/findAllChildNodeIds.d.ts +2 -0
- package/dist/esm/helpers/findAllChildNodeIds.js +15 -0
- package/dist/esm/helpers/findAllExpandedChildNodeIds.d.ts +2 -0
- package/dist/esm/helpers/findAllExpandedChildNodeIds.js +13 -0
- package/dist/esm/helpers/getSearchedTreeItems.d.ts +10 -0
- package/dist/esm/helpers/getSearchedTreeItems.js +31 -0
- package/dist/esm/helpers/getSearchedTreeNodeById.d.ts +11 -0
- package/dist/esm/helpers/getSearchedTreeNodeById.js +23 -0
- package/dist/esm/helpers/index.d.ts +8 -0
- package/dist/esm/helpers/index.js +8 -0
- package/dist/esm/helpers/lookupTreeForSelectedNodes.d.ts +6 -0
- package/dist/esm/{helpers.js → helpers/lookupTreeForSelectedNodes.js} +2 -38
- package/dist/esm/helpers/sortTreeItemsByTitle.d.ts +2 -0
- package/dist/esm/helpers/sortTreeItemsByTitle.js +6 -0
- package/dist/esm/helpers/traverse.d.ts +2 -0
- package/dist/esm/helpers/traverse.js +19 -0
- package/dist/esm/types.d.ts +3 -0
- package/package.json +7 -6
- package/src/helperComponents/TreeNode/TreeNode.tsx +2 -1
- package/src/helpers/__tests__/collectIds.spec.ts +23 -0
- package/src/helpers/__tests__/constants.ts +54 -0
- package/src/helpers/__tests__/getSearchedTreeItems.spec.ts +191 -0
- package/src/helpers/__tests__/getSearchedTreeNodeById.spec.ts +138 -0
- package/src/helpers/checkNestedNodesSelection.ts +15 -0
- package/src/helpers/collectIds.ts +10 -0
- package/src/helpers/extractTreeNodeTitle.ts +4 -0
- package/src/helpers/findAllChildNodeIds.ts +20 -0
- package/src/helpers/findAllExpandedChildNodeIds.ts +18 -0
- package/src/helpers/getSearchedTreeItems.ts +50 -0
- package/src/helpers/getSearchedTreeNodeById.ts +46 -0
- package/src/helpers/index.ts +8 -0
- package/src/{helpers.ts → helpers/lookupTreeForSelectedNodes.ts} +3 -50
- package/src/helpers/sortTreeItemsByTitle.ts +10 -0
- package/src/helpers/traverse.ts +27 -0
- package/src/types.ts +4 -0
- package/dist/cjs/helpers.d.ts +0 -11
- package/dist/esm/helpers.d.ts +0 -11
|
@@ -156,7 +156,7 @@ exports.ExpandableTreeNode = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
156
156
|
children: [(0, jsx_runtime_1.jsx)(TreeLine_1.TreeLine, {
|
|
157
157
|
visible: showLines,
|
|
158
158
|
"data-test-id": constants_1.TEST_IDS.line,
|
|
159
|
-
height:
|
|
159
|
+
height: "calc(100% - ".concat(lastItemHeight, "px)"),
|
|
160
160
|
className: styles_module_scss_1.default.treeLine
|
|
161
161
|
}), (0, jsx_runtime_1.jsx)("div", {
|
|
162
162
|
className: styles_module_scss_1.default.expandableNested,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
const vitest_1 = require("vitest");
|
|
7
|
+
const collectIds_1 = require("../collectIds");
|
|
8
|
+
const constants_1 = require("./constants");
|
|
9
|
+
(0, vitest_1.describe)('collect tree ids', () => {
|
|
10
|
+
(0, vitest_1.it)('find all ids', () => {
|
|
11
|
+
const expected = ['customer 1', 'customer 2', 'same_hierarchy customer', 'department 1.1', 'department 1.2', 'department 2.1', 'same_hierarchy department', 'project 1.1.1', 'project 1.1.2', 'same_hierarchy project'];
|
|
12
|
+
(0, vitest_1.expect)((0, collectIds_1.collectIds)(constants_1.tree)).toEqual(expected);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.tree = void 0;
|
|
7
|
+
exports.tree = [{
|
|
8
|
+
id: 'customer 1',
|
|
9
|
+
title: 'customer 1',
|
|
10
|
+
nested: [{
|
|
11
|
+
id: 'department 1.1',
|
|
12
|
+
title: 'department 1.1',
|
|
13
|
+
nested: [{
|
|
14
|
+
id: 'project 1.1.1',
|
|
15
|
+
title: 'project 1.1.1'
|
|
16
|
+
}, {
|
|
17
|
+
id: 'project 1.1.2',
|
|
18
|
+
title: 'project 1.1.2'
|
|
19
|
+
}]
|
|
20
|
+
}, {
|
|
21
|
+
id: 'department 1.2',
|
|
22
|
+
title: 'department 1.2'
|
|
23
|
+
}]
|
|
24
|
+
}, {
|
|
25
|
+
id: 'customer 2',
|
|
26
|
+
title: 'customer 2',
|
|
27
|
+
nested: [{
|
|
28
|
+
id: 'department 2.1',
|
|
29
|
+
title: 'department 2.1'
|
|
30
|
+
}]
|
|
31
|
+
}, {
|
|
32
|
+
id: 'same_hierarchy customer',
|
|
33
|
+
title: 'same_hierarchy customer',
|
|
34
|
+
nested: [{
|
|
35
|
+
id: 'same_hierarchy department',
|
|
36
|
+
title: 'same_hierarchy department',
|
|
37
|
+
nested: [{
|
|
38
|
+
id: 'same_hierarchy project',
|
|
39
|
+
title: 'same_hierarchy project'
|
|
40
|
+
}]
|
|
41
|
+
}]
|
|
42
|
+
}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
const vitest_1 = require("vitest");
|
|
7
|
+
const getSearchedTreeItems_1 = require("../getSearchedTreeItems");
|
|
8
|
+
const constants_1 = require("./constants");
|
|
9
|
+
(0, vitest_1.describe)('search tree items', () => {
|
|
10
|
+
(0, vitest_1.it)('find items if 1 project is matched', () => {
|
|
11
|
+
const expected = [{
|
|
12
|
+
id: 'customer 1',
|
|
13
|
+
title: 'customer 1',
|
|
14
|
+
nested: [{
|
|
15
|
+
id: 'department 1.1',
|
|
16
|
+
title: 'department 1.1',
|
|
17
|
+
nested: [{
|
|
18
|
+
id: 'project 1.1.1',
|
|
19
|
+
title: 'project 1.1.1'
|
|
20
|
+
}]
|
|
21
|
+
}]
|
|
22
|
+
}];
|
|
23
|
+
(0, vitest_1.expect)((0, getSearchedTreeItems_1.getSearchedTreeItems)({
|
|
24
|
+
tree: constants_1.tree,
|
|
25
|
+
searchOptions: {
|
|
26
|
+
query: 'project 1.1.1'
|
|
27
|
+
}
|
|
28
|
+
})).toEqual(expected);
|
|
29
|
+
});
|
|
30
|
+
(0, vitest_1.it)('find items if 2 projects are matched', () => {
|
|
31
|
+
const expected = [{
|
|
32
|
+
id: 'customer 1',
|
|
33
|
+
title: 'customer 1',
|
|
34
|
+
nested: [{
|
|
35
|
+
id: 'department 1.1',
|
|
36
|
+
title: 'department 1.1',
|
|
37
|
+
nested: [{
|
|
38
|
+
id: 'project 1.1.1',
|
|
39
|
+
title: 'project 1.1.1'
|
|
40
|
+
}, {
|
|
41
|
+
id: 'project 1.1.2',
|
|
42
|
+
title: 'project 1.1.2'
|
|
43
|
+
}]
|
|
44
|
+
}]
|
|
45
|
+
}];
|
|
46
|
+
(0, vitest_1.expect)((0, getSearchedTreeItems_1.getSearchedTreeItems)({
|
|
47
|
+
tree: constants_1.tree,
|
|
48
|
+
searchOptions: {
|
|
49
|
+
query: 'project 1.1'
|
|
50
|
+
}
|
|
51
|
+
})).toEqual(expected);
|
|
52
|
+
});
|
|
53
|
+
(0, vitest_1.it)('find items if 1 department is matched', () => {
|
|
54
|
+
const expected = [{
|
|
55
|
+
id: 'customer 1',
|
|
56
|
+
title: 'customer 1',
|
|
57
|
+
nested: [{
|
|
58
|
+
id: 'department 1.1',
|
|
59
|
+
title: 'department 1.1'
|
|
60
|
+
}]
|
|
61
|
+
}];
|
|
62
|
+
(0, vitest_1.expect)((0, getSearchedTreeItems_1.getSearchedTreeItems)({
|
|
63
|
+
tree: constants_1.tree,
|
|
64
|
+
searchOptions: {
|
|
65
|
+
query: 'department 1.1'
|
|
66
|
+
}
|
|
67
|
+
})).toEqual(expected);
|
|
68
|
+
});
|
|
69
|
+
(0, vitest_1.it)('find items if 2 departments are matched', () => {
|
|
70
|
+
const expected = [{
|
|
71
|
+
id: 'customer 1',
|
|
72
|
+
title: 'customer 1',
|
|
73
|
+
nested: [{
|
|
74
|
+
id: 'department 1.1',
|
|
75
|
+
title: 'department 1.1'
|
|
76
|
+
}, {
|
|
77
|
+
id: 'department 1.2',
|
|
78
|
+
title: 'department 1.2'
|
|
79
|
+
}]
|
|
80
|
+
}];
|
|
81
|
+
(0, vitest_1.expect)((0, getSearchedTreeItems_1.getSearchedTreeItems)({
|
|
82
|
+
tree: constants_1.tree,
|
|
83
|
+
searchOptions: {
|
|
84
|
+
query: 'department 1.'
|
|
85
|
+
}
|
|
86
|
+
})).toEqual(expected);
|
|
87
|
+
});
|
|
88
|
+
(0, vitest_1.it)('find items if 1 customer is matched', () => {
|
|
89
|
+
const expected = [{
|
|
90
|
+
id: 'customer 1',
|
|
91
|
+
title: 'customer 1'
|
|
92
|
+
}];
|
|
93
|
+
(0, vitest_1.expect)((0, getSearchedTreeItems_1.getSearchedTreeItems)({
|
|
94
|
+
tree: constants_1.tree,
|
|
95
|
+
searchOptions: {
|
|
96
|
+
query: 'customer 1'
|
|
97
|
+
}
|
|
98
|
+
})).toEqual(expected);
|
|
99
|
+
});
|
|
100
|
+
(0, vitest_1.it)('find items if not one items are matched', () => {
|
|
101
|
+
const expected = [];
|
|
102
|
+
(0, vitest_1.expect)((0, getSearchedTreeItems_1.getSearchedTreeItems)({
|
|
103
|
+
tree: constants_1.tree,
|
|
104
|
+
searchOptions: {
|
|
105
|
+
query: 'test'
|
|
106
|
+
}
|
|
107
|
+
})).toEqual(expected);
|
|
108
|
+
});
|
|
109
|
+
(0, vitest_1.it)('find items if empty query', () => {
|
|
110
|
+
(0, vitest_1.expect)((0, getSearchedTreeItems_1.getSearchedTreeItems)({
|
|
111
|
+
tree: constants_1.tree,
|
|
112
|
+
searchOptions: {
|
|
113
|
+
query: ''
|
|
114
|
+
}
|
|
115
|
+
})).toEqual(constants_1.tree);
|
|
116
|
+
});
|
|
117
|
+
(0, vitest_1.it)('find items if empty searchOptions', () => {
|
|
118
|
+
(0, vitest_1.expect)((0, getSearchedTreeItems_1.getSearchedTreeItems)({
|
|
119
|
+
tree: constants_1.tree
|
|
120
|
+
})).toEqual(constants_1.tree);
|
|
121
|
+
});
|
|
122
|
+
(0, vitest_1.it)('find matches in the same hierarchy', () => {
|
|
123
|
+
const expected = [{
|
|
124
|
+
id: 'same_hierarchy customer',
|
|
125
|
+
title: 'same_hierarchy customer',
|
|
126
|
+
nested: [{
|
|
127
|
+
id: 'same_hierarchy department',
|
|
128
|
+
title: 'same_hierarchy department',
|
|
129
|
+
nested: [{
|
|
130
|
+
id: 'same_hierarchy project',
|
|
131
|
+
title: 'same_hierarchy project'
|
|
132
|
+
}]
|
|
133
|
+
}]
|
|
134
|
+
}];
|
|
135
|
+
(0, vitest_1.expect)((0, getSearchedTreeItems_1.getSearchedTreeItems)({
|
|
136
|
+
tree: constants_1.tree,
|
|
137
|
+
searchOptions: {
|
|
138
|
+
query: 'same_hierarchy'
|
|
139
|
+
}
|
|
140
|
+
})).toEqual(expected);
|
|
141
|
+
});
|
|
142
|
+
(0, vitest_1.it)('find all items from customer 2', () => {
|
|
143
|
+
const expected = [{
|
|
144
|
+
id: 'customer 2',
|
|
145
|
+
title: 'customer 2',
|
|
146
|
+
nested: [{
|
|
147
|
+
id: 'department 2.1',
|
|
148
|
+
title: 'department 2.1'
|
|
149
|
+
}]
|
|
150
|
+
}];
|
|
151
|
+
(0, vitest_1.expect)((0, getSearchedTreeItems_1.getSearchedTreeItems)({
|
|
152
|
+
tree: constants_1.tree,
|
|
153
|
+
searchOptions: {
|
|
154
|
+
query: 'customer 2',
|
|
155
|
+
includeChildrenMatchedParent: true
|
|
156
|
+
}
|
|
157
|
+
})).toEqual(expected);
|
|
158
|
+
});
|
|
159
|
+
(0, vitest_1.it)('find all items from department 1.1', () => {
|
|
160
|
+
const expected = [{
|
|
161
|
+
id: 'customer 1',
|
|
162
|
+
title: 'customer 1',
|
|
163
|
+
nested: [{
|
|
164
|
+
id: 'department 1.1',
|
|
165
|
+
title: 'department 1.1',
|
|
166
|
+
nested: [{
|
|
167
|
+
id: 'project 1.1.1',
|
|
168
|
+
title: 'project 1.1.1'
|
|
169
|
+
}, {
|
|
170
|
+
id: 'project 1.1.2',
|
|
171
|
+
title: 'project 1.1.2'
|
|
172
|
+
}]
|
|
173
|
+
}]
|
|
174
|
+
}];
|
|
175
|
+
(0, vitest_1.expect)((0, getSearchedTreeItems_1.getSearchedTreeItems)({
|
|
176
|
+
tree: constants_1.tree,
|
|
177
|
+
searchOptions: {
|
|
178
|
+
query: 'department 1.1',
|
|
179
|
+
includeChildrenMatchedParent: true
|
|
180
|
+
}
|
|
181
|
+
})).toEqual(expected);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
const vitest_1 = require("vitest");
|
|
7
|
+
const getSearchedTreeNodeById_1 = require("../getSearchedTreeNodeById");
|
|
8
|
+
const constants_1 = require("./constants");
|
|
9
|
+
(0, vitest_1.describe)('get tree items by id', () => {
|
|
10
|
+
(0, vitest_1.it)('should return the item with nested when it exists', () => {
|
|
11
|
+
const expected = {
|
|
12
|
+
id: 'customer 1',
|
|
13
|
+
title: 'customer 1',
|
|
14
|
+
nested: [{
|
|
15
|
+
id: 'department 1.1',
|
|
16
|
+
title: 'department 1.1',
|
|
17
|
+
nested: [{
|
|
18
|
+
id: 'project 1.1.1',
|
|
19
|
+
title: 'project 1.1.1'
|
|
20
|
+
}, {
|
|
21
|
+
id: 'project 1.1.2',
|
|
22
|
+
title: 'project 1.1.2'
|
|
23
|
+
}]
|
|
24
|
+
}, {
|
|
25
|
+
id: 'department 1.2',
|
|
26
|
+
title: 'department 1.2'
|
|
27
|
+
}]
|
|
28
|
+
};
|
|
29
|
+
(0, vitest_1.expect)((0, getSearchedTreeNodeById_1.getSearchedTreeNodeById)({
|
|
30
|
+
tree: constants_1.tree,
|
|
31
|
+
searchOptions: {
|
|
32
|
+
id: 'customer 1'
|
|
33
|
+
}
|
|
34
|
+
})).toEqual(expected);
|
|
35
|
+
});
|
|
36
|
+
(0, vitest_1.it)('should return the item without nested when it exists', () => {
|
|
37
|
+
const expected = {
|
|
38
|
+
id: 'customer 1',
|
|
39
|
+
title: 'customer 1'
|
|
40
|
+
};
|
|
41
|
+
(0, vitest_1.expect)((0, getSearchedTreeNodeById_1.getSearchedTreeNodeById)({
|
|
42
|
+
tree: constants_1.tree,
|
|
43
|
+
searchOptions: {
|
|
44
|
+
id: 'customer 1',
|
|
45
|
+
includeNested: false
|
|
46
|
+
}
|
|
47
|
+
})).toEqual(expected);
|
|
48
|
+
});
|
|
49
|
+
(0, vitest_1.it)('should return null or undefined when the item does not exist', () => {
|
|
50
|
+
const expected = null;
|
|
51
|
+
(0, vitest_1.expect)((0, getSearchedTreeNodeById_1.getSearchedTreeNodeById)({
|
|
52
|
+
tree: constants_1.tree,
|
|
53
|
+
searchOptions: {
|
|
54
|
+
id: 'customer none'
|
|
55
|
+
}
|
|
56
|
+
})).toEqual(expected);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
(0, vitest_1.describe)('get tree items by ids', () => {
|
|
60
|
+
(0, vitest_1.it)('should return the item when only 1 item exists with nested', () => {
|
|
61
|
+
const expected = [{
|
|
62
|
+
id: 'department 1.1',
|
|
63
|
+
title: 'department 1.1',
|
|
64
|
+
nested: [{
|
|
65
|
+
id: 'project 1.1.1',
|
|
66
|
+
title: 'project 1.1.1'
|
|
67
|
+
}, {
|
|
68
|
+
id: 'project 1.1.2',
|
|
69
|
+
title: 'project 1.1.2'
|
|
70
|
+
}]
|
|
71
|
+
}];
|
|
72
|
+
(0, vitest_1.expect)((0, getSearchedTreeNodeById_1.getSearchedTreeNodeById)({
|
|
73
|
+
tree: constants_1.tree,
|
|
74
|
+
searchOptions: {
|
|
75
|
+
id: ['department 1.1']
|
|
76
|
+
}
|
|
77
|
+
})).toEqual(expected);
|
|
78
|
+
});
|
|
79
|
+
(0, vitest_1.it)('should return the item when only 1 item exists without nested', () => {
|
|
80
|
+
const expected = [{
|
|
81
|
+
id: 'department 1.1',
|
|
82
|
+
title: 'department 1.1'
|
|
83
|
+
}];
|
|
84
|
+
(0, vitest_1.expect)((0, getSearchedTreeNodeById_1.getSearchedTreeNodeById)({
|
|
85
|
+
tree: constants_1.tree,
|
|
86
|
+
searchOptions: {
|
|
87
|
+
id: ['department 1.1'],
|
|
88
|
+
includeNested: false
|
|
89
|
+
}
|
|
90
|
+
})).toEqual(expected);
|
|
91
|
+
});
|
|
92
|
+
(0, vitest_1.it)('should return both items when 2 items exist', () => {
|
|
93
|
+
const expected = [{
|
|
94
|
+
id: 'department 1.1',
|
|
95
|
+
title: 'department 1.1',
|
|
96
|
+
nested: [{
|
|
97
|
+
id: 'project 1.1.1',
|
|
98
|
+
title: 'project 1.1.1'
|
|
99
|
+
}, {
|
|
100
|
+
id: 'project 1.1.2',
|
|
101
|
+
title: 'project 1.1.2'
|
|
102
|
+
}]
|
|
103
|
+
}, {
|
|
104
|
+
id: 'department 1.2',
|
|
105
|
+
title: 'department 1.2'
|
|
106
|
+
}];
|
|
107
|
+
(0, vitest_1.expect)((0, getSearchedTreeNodeById_1.getSearchedTreeNodeById)({
|
|
108
|
+
tree: constants_1.tree,
|
|
109
|
+
searchOptions: {
|
|
110
|
+
id: ['department 1.1', 'department 1.2']
|
|
111
|
+
}
|
|
112
|
+
})).toEqual(expected);
|
|
113
|
+
});
|
|
114
|
+
(0, vitest_1.it)('should return an empty array or null when no items exist', () => {
|
|
115
|
+
const expected = [];
|
|
116
|
+
(0, vitest_1.expect)((0, getSearchedTreeNodeById_1.getSearchedTreeNodeById)({
|
|
117
|
+
tree: constants_1.tree,
|
|
118
|
+
searchOptions: {
|
|
119
|
+
id: ['department 1.1test', 'department 1.2test']
|
|
120
|
+
}
|
|
121
|
+
})).toEqual(expected);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.checkNestedNodesSelection = checkNestedNodesSelection;
|
|
7
|
+
const findAllChildNodeIds_1 = require("./findAllChildNodeIds");
|
|
8
|
+
function checkNestedNodesSelection(nodes, selectedKeys) {
|
|
9
|
+
const allIds = (0, findAllChildNodeIds_1.findAllChildNodeIds)(nodes);
|
|
10
|
+
const selected = allIds.filter(id => selectedKeys.includes(id));
|
|
11
|
+
const someSelected = selected.length > 0;
|
|
12
|
+
const allSelected = someSelected && allIds.length === selected.length;
|
|
13
|
+
return {
|
|
14
|
+
someSelected: !allSelected && someSelected,
|
|
15
|
+
allSelected
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.collectIds = void 0;
|
|
7
|
+
const traverse_1 = require("./traverse");
|
|
8
|
+
const collectIds = treeNodes => {
|
|
9
|
+
const ids = [];
|
|
10
|
+
(0, traverse_1.traverse)(treeNodes, node => ids.push(node.id));
|
|
11
|
+
return ids;
|
|
12
|
+
};
|
|
13
|
+
exports.collectIds = collectIds;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.extractTreeNodeTitle = void 0;
|
|
7
|
+
const extractTreeNodeTitle = _ref => {
|
|
8
|
+
let {
|
|
9
|
+
title,
|
|
10
|
+
getTitle
|
|
11
|
+
} = _ref;
|
|
12
|
+
var _a;
|
|
13
|
+
return typeof title === 'string' ? title : (_a = getTitle === null || getTitle === void 0 ? void 0 : getTitle()) !== null && _a !== void 0 ? _a : '';
|
|
14
|
+
};
|
|
15
|
+
exports.extractTreeNodeTitle = extractTreeNodeTitle;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.findAllChildNodeIds = findAllChildNodeIds;
|
|
7
|
+
function findAllChildNodeIds(nodes) {
|
|
8
|
+
var _a;
|
|
9
|
+
const stack = [...nodes];
|
|
10
|
+
const ids = [];
|
|
11
|
+
let node;
|
|
12
|
+
while (node = stack.pop()) {
|
|
13
|
+
if (!node.disabled) {
|
|
14
|
+
ids.push(node.id);
|
|
15
|
+
if ((_a = node.nested) === null || _a === void 0 ? void 0 : _a.length) {
|
|
16
|
+
stack.push(...node.nested);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return ids;
|
|
21
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.findAllExpandedChildNodeIds = findAllExpandedChildNodeIds;
|
|
7
|
+
function findAllExpandedChildNodeIds(nodes, expandedNodes) {
|
|
8
|
+
var _a;
|
|
9
|
+
const stack = [...nodes];
|
|
10
|
+
const ids = [];
|
|
11
|
+
let node;
|
|
12
|
+
while (node = stack.shift()) {
|
|
13
|
+
ids.push(node.id);
|
|
14
|
+
if (((_a = node.nested) === null || _a === void 0 ? void 0 : _a.length) && expandedNodes.includes(node.id)) {
|
|
15
|
+
stack.unshift(...node.nested);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return ids;
|
|
19
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ExtendedTreeNodeProps } from '../types';
|
|
2
|
+
type SearchParams = {
|
|
3
|
+
tree: ExtendedTreeNodeProps[];
|
|
4
|
+
searchOptions?: Partial<{
|
|
5
|
+
query: string;
|
|
6
|
+
includeChildrenMatchedParent: boolean;
|
|
7
|
+
}>;
|
|
8
|
+
};
|
|
9
|
+
export declare const getSearchedTreeItems: ({ tree, searchOptions }: SearchParams) => ExtendedTreeNodeProps[];
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSearchedTreeItems = void 0;
|
|
7
|
+
const extractTreeNodeTitle_1 = require("./extractTreeNodeTitle");
|
|
8
|
+
const isMatchedTreeItem = search => {
|
|
9
|
+
const searchLower = search.toLocaleLowerCase();
|
|
10
|
+
return treeItem => {
|
|
11
|
+
const currentValue = (0, extractTreeNodeTitle_1.extractTreeNodeTitle)(treeItem);
|
|
12
|
+
return currentValue.toLocaleLowerCase().includes(searchLower);
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
const getSearchedTreeItems = _ref => {
|
|
16
|
+
let {
|
|
17
|
+
tree,
|
|
18
|
+
searchOptions
|
|
19
|
+
} = _ref;
|
|
20
|
+
if (!(searchOptions === null || searchOptions === void 0 ? void 0 : searchOptions.query)) return tree;
|
|
21
|
+
const {
|
|
22
|
+
query = '',
|
|
23
|
+
includeChildrenMatchedParent
|
|
24
|
+
} = searchOptions;
|
|
25
|
+
const matchFunc = isMatchedTreeItem(query);
|
|
26
|
+
const searchItems = treeItems => treeItems.reduce((acc, item) => {
|
|
27
|
+
const hasMatchingTitle = matchFunc(item);
|
|
28
|
+
const needDeepSearch = !(hasMatchingTitle && includeChildrenMatchedParent);
|
|
29
|
+
const matchedChildren = item.nested && (needDeepSearch ? searchItems(item.nested) : item.nested);
|
|
30
|
+
if (hasMatchingTitle || (matchedChildren === null || matchedChildren === void 0 ? void 0 : matchedChildren.length)) {
|
|
31
|
+
const newItem = Object.assign({}, item);
|
|
32
|
+
if (matchedChildren === null || matchedChildren === void 0 ? void 0 : matchedChildren.length) {
|
|
33
|
+
newItem.nested = matchedChildren;
|
|
34
|
+
} else {
|
|
35
|
+
delete newItem.nested;
|
|
36
|
+
}
|
|
37
|
+
acc.push(newItem);
|
|
38
|
+
}
|
|
39
|
+
return acc;
|
|
40
|
+
}, []);
|
|
41
|
+
return searchItems(tree);
|
|
42
|
+
};
|
|
43
|
+
exports.getSearchedTreeItems = getSearchedTreeItems;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ExtendedTreeNodeProps } from '../types';
|
|
2
|
+
type ReturnSearch<I, T> = I extends string ? T | null : T[];
|
|
3
|
+
type SearchByIdParams<I, T> = {
|
|
4
|
+
tree: T[];
|
|
5
|
+
searchOptions: {
|
|
6
|
+
id: I;
|
|
7
|
+
includeNested?: boolean;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export declare const getSearchedTreeNodeById: <I extends string | string[], T extends ExtendedTreeNodeProps>({ tree, searchOptions: { id, includeNested }, }: SearchByIdParams<I, T>) => ReturnSearch<I, T>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSearchedTreeNodeById = void 0;
|
|
7
|
+
const getSearchedTreeNodeById = _ref => {
|
|
8
|
+
let {
|
|
9
|
+
tree,
|
|
10
|
+
searchOptions: {
|
|
11
|
+
id,
|
|
12
|
+
includeNested = true
|
|
13
|
+
}
|
|
14
|
+
} = _ref;
|
|
15
|
+
const isArrayIds = Array.isArray(id);
|
|
16
|
+
if (!id || isArrayIds && id.length === 0) {
|
|
17
|
+
return isArrayIds ? [] : null;
|
|
18
|
+
}
|
|
19
|
+
const foundItems = [];
|
|
20
|
+
const searchNodes = nodes => {
|
|
21
|
+
for (const node of nodes) {
|
|
22
|
+
const matchCondition = isArrayIds ? id.includes(node.id) : node.id === id;
|
|
23
|
+
if (matchCondition) {
|
|
24
|
+
foundItems.push(includeNested ? node : Object.assign(Object.assign({}, node), {
|
|
25
|
+
nested: undefined
|
|
26
|
+
}));
|
|
27
|
+
if (!isArrayIds) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (node.nested) {
|
|
32
|
+
searchNodes(node.nested);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
searchNodes(tree);
|
|
37
|
+
return isArrayIds ? foundItems : foundItems[0] || null;
|
|
38
|
+
};
|
|
39
|
+
exports.getSearchedTreeNodeById = getSearchedTreeNodeById;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './checkNestedNodesSelection';
|
|
2
|
+
export * from './collectIds';
|
|
3
|
+
export * from './findAllExpandedChildNodeIds';
|
|
4
|
+
export * from './getSearchedTreeItems';
|
|
5
|
+
export * from './getSearchedTreeNodeById';
|
|
6
|
+
export * from './lookupTreeForSelectedNodes';
|
|
7
|
+
export * from './sortTreeItemsByTitle';
|
|
8
|
+
export * from './traverse';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return m[k];
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
} : function (o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
});
|
|
19
|
+
var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
});
|
|
25
|
+
__exportStar(require("./checkNestedNodesSelection"), exports);
|
|
26
|
+
__exportStar(require("./collectIds"), exports);
|
|
27
|
+
__exportStar(require("./findAllExpandedChildNodeIds"), exports);
|
|
28
|
+
__exportStar(require("./getSearchedTreeItems"), exports);
|
|
29
|
+
__exportStar(require("./getSearchedTreeNodeById"), exports);
|
|
30
|
+
__exportStar(require("./lookupTreeForSelectedNodes"), exports);
|
|
31
|
+
__exportStar(require("./sortTreeItemsByTitle"), exports);
|
|
32
|
+
__exportStar(require("./traverse"), exports);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ParentNode, TreeNodeId, TreeNodeProps } from '../types';
|
|
2
|
+
export declare function lookupTreeForSelectedNodes({ node, selectedNodes, parentNode, }: {
|
|
3
|
+
node: Pick<TreeNodeProps, 'id' | 'nested' | 'disabled'>;
|
|
4
|
+
selectedNodes: TreeNodeId[];
|
|
5
|
+
parentNode?: ParentNode;
|
|
6
|
+
}): string[];
|