playbook_ui 12.26.0.pre.alpha.multiselectfixes825 → 12.26.0.pre.alpha.railsmultilevelimprovements805
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 +125 -47
- data/app/pb_kits/playbook/pb_multi_level_select/_multi_level_select.tsx +259 -190
- 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 +1 -2
- 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/_multi_level_select_return_complete_data.html.erb +73 -0
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_return_complete_data.jsx +87 -0
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_with_form.html.erb +72 -0
- data/app/pb_kits/playbook/pb_multi_level_select/docs/example.yml +3 -0
- data/app/pb_kits/playbook/pb_multi_level_select/docs/index.js +2 -1
- data/app/pb_kits/playbook/pb_multi_level_select/multi_level_select.rb +6 -0
- data/dist/playbook-rails.js +5 -5
- data/lib/playbook/forms/builder/multi_level_select_field.rb +12 -0
- data/lib/playbook/forms/builder.rb +1 -0
- data/lib/playbook/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79c732fa4dc676050bdbc6dda57f9a180670d812ffeeb73ba5d410a683a2c6bf
|
4
|
+
data.tar.gz: 332c5b9b341d69f47d83af65dfd5936918ee3b7e4149884892a8c4926b7ec3e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd51e6d5feffbe630c6e315e17e108d3f2c2d55a55b2ba12fbe14894950f61e9d457cb29899993a7f990564140e95e78c8251e675cfa7f3048dacfb7cb24d72f
|
7
|
+
data.tar.gz: fd53b4b633ea48c3b6db1f2f87c017509db18cf1d7732d9a1992ee3147e8df41d6e0b05fa1bf5f876c2304c3ae71ddb8627deb1e5abd65de8d8f14ccac9bc139
|
@@ -1,16 +1,58 @@
|
|
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
|
+
|
1
17
|
//function to retrieve all ancestors of unchecked item and set checked to false
|
2
18
|
export const getAncestorsOfUnchecked = (
|
3
|
-
|
19
|
+
formattedData: { [key: string]: any }[],
|
4
20
|
item: { [key: string]: any }
|
5
21
|
) => {
|
6
22
|
if (item.parent_id) {
|
7
|
-
const
|
8
|
-
|
9
|
-
|
23
|
+
const ancestors = filterFormattedDataById(formattedData, item.parent_id);
|
24
|
+
ancestors[0].checked = false;
|
25
|
+
|
26
|
+
if (ancestors[0].parent_id) {
|
27
|
+
getAncestorsOfUnchecked(formattedData, ancestors[0]);
|
28
|
+
}
|
10
29
|
}
|
11
|
-
return data;
|
12
30
|
};
|
13
|
-
|
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
|
+
|
14
56
|
//function is going over formattedData and returning all objects that match the
|
15
57
|
//id of the clicked item from the dropdown
|
16
58
|
export const filterFormattedDataById = (
|
@@ -22,7 +64,6 @@ export const filterFormattedDataById = (
|
|
22
64
|
for (const item of data) {
|
23
65
|
if (item.id.toLowerCase() === (term.toLowerCase())) {
|
24
66
|
matched.push(item);
|
25
|
-
return
|
26
67
|
}
|
27
68
|
|
28
69
|
if (item.children && item.children.length > 0) {
|
@@ -75,60 +116,97 @@ export const getCheckedItems = (
|
|
75
116
|
});
|
76
117
|
return checkedItems;
|
77
118
|
};
|
78
|
-
|
79
|
-
export const getDefaultCheckedItems = (treeData:{ [key: string]: any }[]) => {
|
80
|
-
const checkedDefault: { [key: string]: any }[] = [];
|
81
119
|
|
82
|
-
|
83
|
-
|
84
|
-
|
120
|
+
export const getChildIds = (
|
121
|
+
item: { [key: string]: any },
|
122
|
+
defaultArray: { [key: string]: any }[]
|
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);
|
85
130
|
}
|
86
|
-
|
87
|
-
|
88
|
-
|
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
|
-
}
|
131
|
+
});
|
132
|
+
return childIds;
|
133
|
+
};
|
101
134
|
|
102
|
-
|
103
|
-
|
135
|
+
export const updateReturnItems = (newChecked: { [key: string]: any }[]) => {
|
136
|
+
const updatedCheckedItems: { [key: string]: any }[] = [];
|
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);
|
104
144
|
}
|
105
|
-
}
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
145
|
+
}
|
146
|
+
const childItem = updatedCheckedItems.some((x) => x.id === item?.parent_id);
|
147
|
+
if (!childItem) {
|
148
|
+
updatedCheckedItems.push(item);
|
149
|
+
}
|
150
|
+
}
|
151
|
+
const filteredReturn = updatedCheckedItems.filter((item) => {
|
152
|
+
return !updatedCheckedItems.find(
|
153
|
+
(otherItem) => otherItem.id === item.parent_id
|
154
|
+
);
|
155
|
+
});
|
156
|
+
return filteredReturn;
|
111
157
|
};
|
112
158
|
|
113
|
-
export const
|
114
|
-
|
115
|
-
|
159
|
+
export const recursiveReturnOnlyParent = (
|
160
|
+
items: { [key: string]: any },
|
161
|
+
formattedData: { [key: string]: any }[],
|
162
|
+
defaultReturn: { [key: string]: any }[],
|
163
|
+
setDefaultReturn: any
|
116
164
|
) => {
|
117
|
-
|
118
|
-
const parent = filterFormattedDataById(data, item.parent_id);
|
165
|
+
const parent = filterFormattedDataById(formattedData, items.parent_id);
|
119
166
|
const allChildrenChecked = parent[0].children.every(
|
120
167
|
(child: { [key: string]: any }) => child.checked
|
121
168
|
);
|
122
169
|
if (allChildrenChecked) {
|
170
|
+
// Only return the parent and remove its children from defaultReturn
|
123
171
|
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
|
124
184
|
const parentHasParent = parent[0].parent_id !== null;
|
125
185
|
if (parentHasParent) {
|
126
|
-
|
186
|
+
recursiveReturnOnlyParent(
|
127
187
|
parent[0],
|
128
|
-
|
188
|
+
formattedData,
|
189
|
+
filteredDefaultReturn,
|
190
|
+
setDefaultReturn
|
129
191
|
);
|
130
192
|
}
|
131
|
-
}
|
132
|
-
|
133
|
-
|
134
|
-
|
193
|
+
} else {
|
194
|
+
const checkedChildren = parent[0].children.filter(
|
195
|
+
(child: { [key: string]: any }) => child.checked
|
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
|
+
};
|