playbook_ui 12.26.0.pre.alpha.railsmultilevelimprovements805 → 12.26.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/pb_multi_level_select/_helper_functions.tsx +47 -125
- data/app/pb_kits/playbook/pb_multi_level_select/_multi_level_select.tsx +190 -259
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_default.html.erb +2 -2
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_default.jsx +1 -1
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_default.md +1 -1
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_return_all_selected.html.erb +2 -1
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_return_all_selected.jsx +1 -1
- data/app/pb_kits/playbook/pb_multi_level_select/docs/example.yml +0 -3
- data/app/pb_kits/playbook/pb_multi_level_select/docs/index.js +1 -2
- data/app/pb_kits/playbook/pb_multi_level_select/multi_level_select.rb +0 -6
- data/dist/playbook-rails.js +5 -5
- data/lib/playbook/forms/builder.rb +0 -1
- data/lib/playbook/version.rb +1 -1
- metadata +7 -11
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_return_complete_data.html.erb +0 -73
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_return_complete_data.jsx +0 -87
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_with_form.html.erb +0 -72
- data/lib/playbook/forms/builder/multi_level_select_field.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fbc9b56c02a9915257f3a1169f85773e8a063c14de44a2492a250f9015dee65
|
4
|
+
data.tar.gz: f70c024e4feae26b0767595ad538df87eb08e78453a56c6ca22de07552d60d5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e40a155458785168e1fb5f5f63efe8c5bcd7dca3d1b8c618557d86453d5008336454d205330742fc029e6593e05e566610eb853577b42a993934eeb20408ffa5
|
7
|
+
data.tar.gz: 9acc8dcd73190cc433572b49bdef61cb4e425304125aaf8d5b61c7426f5f4c2a314f1e2b38e9b55a5f37b6f45b56cb8079ec9b82070c461699ae9b2357689a2d
|
@@ -1,58 +1,16 @@
|
|
1
|
-
//function for unchecking items in formattedData
|
2
|
-
export const unCheckIt = (
|
3
|
-
formattedData: { [key: string]: any }[],
|
4
|
-
id: string
|
5
|
-
) => {
|
6
|
-
formattedData.map((item: { [key: string]: any }) => {
|
7
|
-
if (item.id === id && item.checked) {
|
8
|
-
item.checked = false;
|
9
|
-
}
|
10
|
-
if (item.children && item.children.length > 0) {
|
11
|
-
unCheckIt(item.children, id);
|
12
|
-
}
|
13
|
-
return item;
|
14
|
-
});
|
15
|
-
};
|
16
|
-
|
17
1
|
//function to retrieve all ancestors of unchecked item and set checked to false
|
18
2
|
export const getAncestorsOfUnchecked = (
|
19
|
-
|
3
|
+
data: { [key: string]: any }[],
|
20
4
|
item: { [key: string]: any }
|
21
5
|
) => {
|
22
6
|
if (item.parent_id) {
|
23
|
-
const
|
24
|
-
|
25
|
-
|
26
|
-
if (ancestors[0].parent_id) {
|
27
|
-
getAncestorsOfUnchecked(formattedData, ancestors[0]);
|
28
|
-
}
|
7
|
+
const ancestor = filterFormattedDataById(data, item.parent_id);
|
8
|
+
ancestor[0].checked = false;
|
9
|
+
ancestor[0].parent_id && getAncestorsOfUnchecked(data, ancestor[0])
|
29
10
|
}
|
11
|
+
return data;
|
30
12
|
};
|
31
|
-
|
32
|
-
//recursively check all child and grandchild items if parent checked
|
33
|
-
export const checkedRecursive = (item: { [key: string]: any }) => {
|
34
|
-
if (!item.checked) {
|
35
|
-
item.checked = true;
|
36
|
-
}
|
37
|
-
if (item.children && item.children.length > 0) {
|
38
|
-
item.children.forEach((childItem: { [key: string]: any }) => {
|
39
|
-
checkedRecursive(childItem);
|
40
|
-
});
|
41
|
-
}
|
42
|
-
};
|
43
|
-
|
44
|
-
//recursively uncheck all child and grandchild items if parent unchecked
|
45
|
-
export const unCheckedRecursive = (item: { [key: string]: any }) => {
|
46
|
-
if (item.checked) {
|
47
|
-
item.checked = false;
|
48
|
-
}
|
49
|
-
if (item.children && item.children.length > 0) {
|
50
|
-
item.children.forEach((childItem: { [key: string]: any }) => {
|
51
|
-
unCheckedRecursive(childItem);
|
52
|
-
});
|
53
|
-
}
|
54
|
-
};
|
55
|
-
|
13
|
+
|
56
14
|
//function is going over formattedData and returning all objects that match the
|
57
15
|
//id of the clicked item from the dropdown
|
58
16
|
export const filterFormattedDataById = (
|
@@ -64,6 +22,7 @@ export const filterFormattedDataById = (
|
|
64
22
|
for (const item of data) {
|
65
23
|
if (item.id.toLowerCase() === (term.toLowerCase())) {
|
66
24
|
matched.push(item);
|
25
|
+
return
|
67
26
|
}
|
68
27
|
|
69
28
|
if (item.children && item.children.length > 0) {
|
@@ -116,97 +75,60 @@ export const getCheckedItems = (
|
|
116
75
|
});
|
117
76
|
return checkedItems;
|
118
77
|
};
|
78
|
+
|
79
|
+
export const getDefaultCheckedItems = (treeData:{ [key: string]: any }[]) => {
|
80
|
+
const checkedDefault: { [key: string]: any }[] = [];
|
119
81
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
) => {
|
124
|
-
let childIds: string[] = [];
|
125
|
-
item.children.forEach((child: { [key: string]: any }) => {
|
126
|
-
childIds.push(child.id);
|
127
|
-
if (child.children && child.children.length > 0) {
|
128
|
-
const childChildIds = getChildIds(child, defaultArray);
|
129
|
-
childIds.push(...childChildIds);
|
82
|
+
const traverseTree = (items:{ [key: string]: any }[]) => {
|
83
|
+
if (!Array.isArray(items)) {
|
84
|
+
return;
|
130
85
|
}
|
131
|
-
|
132
|
-
|
133
|
-
|
86
|
+
items.forEach((item:{ [key: string]: any }) => {
|
87
|
+
if (item.checked) {
|
88
|
+
if (item.children && item.children.length > 0) {
|
89
|
+
const uncheckedChildren = item.children.filter((child:{ [key: string]: any }) => !child.checked);
|
90
|
+
if (uncheckedChildren.length === 0) {
|
91
|
+
checkedDefault.push(item);
|
92
|
+
return;
|
93
|
+
}
|
94
|
+
} else {
|
95
|
+
const parent = items.find((parentItem:{ [key: string]: any }) => parentItem.id === item.parentId);
|
96
|
+
if (!parent || !parent.checked) {
|
97
|
+
checkedDefault.push(item);
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
134
101
|
|
135
|
-
|
136
|
-
|
137
|
-
for (const item of newChecked) {
|
138
|
-
if (item.children && item.children.length > 0) {
|
139
|
-
const allChildrenChecked = item.children.every(
|
140
|
-
(child: { [key: string]: any }) => child.checked
|
141
|
-
);
|
142
|
-
if (allChildrenChecked) {
|
143
|
-
updatedCheckedItems.push(item);
|
102
|
+
if (item.children && item.children.length > 0) {
|
103
|
+
traverseTree(item.children);
|
144
104
|
}
|
145
|
-
}
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
const filteredReturn = updatedCheckedItems.filter((item) => {
|
152
|
-
return !updatedCheckedItems.find(
|
153
|
-
(otherItem) => otherItem.id === item.parent_id
|
154
|
-
);
|
155
|
-
});
|
156
|
-
return filteredReturn;
|
105
|
+
});
|
106
|
+
};
|
107
|
+
|
108
|
+
traverseTree(treeData);
|
109
|
+
|
110
|
+
return checkedDefault;
|
157
111
|
};
|
158
112
|
|
159
|
-
export const
|
160
|
-
|
161
|
-
|
162
|
-
defaultReturn: { [key: string]: any }[],
|
163
|
-
setDefaultReturn: any
|
113
|
+
export const recursiveCheckParent = (
|
114
|
+
item: { [key: string]: any },
|
115
|
+
data:any
|
164
116
|
) => {
|
165
|
-
|
117
|
+
if (item.parent_id !== null) {
|
118
|
+
const parent = filterFormattedDataById(data, item.parent_id);
|
166
119
|
const allChildrenChecked = parent[0].children.every(
|
167
120
|
(child: { [key: string]: any }) => child.checked
|
168
121
|
);
|
169
122
|
if (allChildrenChecked) {
|
170
|
-
// Only return the parent and remove its children from defaultReturn
|
171
123
|
parent[0].checked = true;
|
172
|
-
const filteredDefaultReturn = defaultReturn.filter((item) => {
|
173
|
-
// Remove children of the specific parent
|
174
|
-
if (
|
175
|
-
parent[0].children.find(
|
176
|
-
(child: { [key: string]: any }) => child.id === item.id
|
177
|
-
)
|
178
|
-
) {
|
179
|
-
return false;
|
180
|
-
}
|
181
|
-
});
|
182
|
-
setDefaultReturn([...filteredDefaultReturn, parent[0]]);
|
183
|
-
// Check if the parent has a parent and its children are all checked
|
184
124
|
const parentHasParent = parent[0].parent_id !== null;
|
185
125
|
if (parentHasParent) {
|
186
|
-
|
126
|
+
recursiveCheckParent(
|
187
127
|
parent[0],
|
188
|
-
|
189
|
-
filteredDefaultReturn,
|
190
|
-
setDefaultReturn
|
128
|
+
data
|
191
129
|
);
|
192
130
|
}
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
const updatedDefaultReturn = [...defaultReturn, ...checkedChildren];
|
198
|
-
setDefaultReturn(updatedDefaultReturn);
|
199
|
-
}
|
200
|
-
};
|
201
|
-
|
202
|
-
export const removeChildrenIfParentChecked = (
|
203
|
-
items: { [key: string]: any },
|
204
|
-
defaultReturn: { [key: string]: any }[],
|
205
|
-
setDefaultReturn: any
|
206
|
-
) => {
|
207
|
-
const childIds = getChildIds(items, defaultReturn);
|
208
|
-
const filteredDefaultArray = defaultReturn.filter(
|
209
|
-
(item: { [key: string]: any }) => childIds !== item.id
|
210
|
-
);
|
211
|
-
setDefaultReturn([...filteredDefaultArray, items]);
|
212
|
-
};
|
131
|
+
}
|
132
|
+
}
|
133
|
+
return data;
|
134
|
+
}
|