playbook_ui 12.25.0.pre.alpha.railsmultilevelimprovements785 → 12.25.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/_playbook.scss +0 -1
  3. data/app/pb_kits/playbook/index.js +0 -1
  4. data/app/pb_kits/playbook/pb_avatar/docs/_avatar_swift.md +1 -82
  5. data/app/pb_kits/playbook/pb_docs/kit_example.html.erb +13 -14
  6. data/app/pb_kits/playbook/pb_form_pill/_form_pill.tsx +2 -3
  7. data/app/pb_kits/playbook/pb_multi_level_select/_multi_level_select.scss +98 -58
  8. data/app/pb_kits/playbook/pb_multi_level_select/_multi_level_select.tsx +86 -356
  9. data/app/pb_kits/playbook/pb_multi_level_select/_multi_select_helper.tsx +31 -0
  10. data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_default.md +1 -1
  11. data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_return_all_selected.html.erb +1 -1
  12. data/app/pb_kits/playbook/pb_multi_level_select/docs/example.yml +0 -1
  13. data/app/pb_kits/playbook/pb_multi_level_select/helper_functions.ts +87 -0
  14. data/app/pb_kits/playbook/pb_multi_level_select/multi_level_select.rb +0 -3
  15. data/app/pb_kits/playbook/pb_multi_level_select/multi_level_select.test.jsx +1 -1
  16. data/app/pb_kits/playbook/playbook-doc.js +0 -2
  17. data/dist/menu.yml +0 -1
  18. data/dist/playbook-rails.js +7 -7
  19. data/lib/playbook/forms/builder.rb +0 -1
  20. data/lib/playbook/version.rb +2 -2
  21. metadata +9 -29
  22. data/app/pb_kits/playbook/pb_detail/_detail.scss +0 -44
  23. data/app/pb_kits/playbook/pb_detail/_detail.tsx +0 -55
  24. data/app/pb_kits/playbook/pb_detail/_detail_mixins.scss +0 -29
  25. data/app/pb_kits/playbook/pb_detail/detail.html.erb +0 -7
  26. data/app/pb_kits/playbook/pb_detail/detail.rb +0 -31
  27. data/app/pb_kits/playbook/pb_detail/detail.test.jsx +0 -46
  28. data/app/pb_kits/playbook/pb_detail/docs/_description.md +0 -1
  29. data/app/pb_kits/playbook/pb_detail/docs/_detail_bold.html.erb +0 -34
  30. data/app/pb_kits/playbook/pb_detail/docs/_detail_bold.jsx +0 -49
  31. data/app/pb_kits/playbook/pb_detail/docs/_detail_bold.md +0 -1
  32. data/app/pb_kits/playbook/pb_detail/docs/_detail_colors.html.erb +0 -24
  33. data/app/pb_kits/playbook/pb_detail/docs/_detail_colors.jsx +0 -38
  34. data/app/pb_kits/playbook/pb_detail/docs/_detail_colors.md +0 -6
  35. data/app/pb_kits/playbook/pb_detail/docs/_detail_default.html.erb +0 -3
  36. data/app/pb_kits/playbook/pb_detail/docs/_detail_default.jsx +0 -13
  37. data/app/pb_kits/playbook/pb_detail/docs/_detail_styled.html.erb +0 -22
  38. data/app/pb_kits/playbook/pb_detail/docs/_detail_styled.jsx +0 -32
  39. data/app/pb_kits/playbook/pb_detail/docs/example.yml +0 -11
  40. data/app/pb_kits/playbook/pb_detail/docs/index.js +0 -4
  41. data/app/pb_kits/playbook/pb_multi_level_select/_helper_functions.tsx +0 -212
  42. data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_with_form.html.erb +0 -72
  43. data/lib/playbook/forms/builder/multi_level_select_field.rb +0 -12
@@ -1,212 +0,0 @@
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
- //function to retrieve all ancestors of unchecked item and set checked to false
18
- export const getAncestorsOfUnchecked = (
19
- formattedData: { [key: string]: any }[],
20
- item: { [key: string]: any }
21
- ) => {
22
- if (item.parent_id) {
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
- }
29
- }
30
- };
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
-
56
- //function is going over formattedData and returning all objects that match the
57
- //id of the clicked item from the dropdown
58
- export const filterFormattedDataById = (
59
- formattedData: { [key: string]: any }[],
60
- id: string
61
- ) => {
62
- const matched: { [key: string]: any }[] = [];
63
- const recursiveSearch = (data: { [key: string]: any }[], term: string) => {
64
- for (const item of data) {
65
- if (item.id.toLowerCase() === (term.toLowerCase())) {
66
- matched.push(item);
67
- }
68
-
69
- if (item.children && item.children.length > 0) {
70
- recursiveSearch(item.children, term);
71
- }
72
- }
73
- };
74
-
75
- recursiveSearch(formattedData, id);
76
- return matched;
77
- };
78
-
79
- export const findByFilter = (
80
- formattedData: { [key: string]: any }[],
81
- searchTerm: string
82
- ) => {
83
- const matchedItems: { [key: string]: any }[] = [];
84
- const recursiveSearch = (data: { [key: string]: any }[], term: string) => {
85
- for (const item of data) {
86
- if (item.label.toLowerCase().includes(term.toLowerCase())) {
87
- matchedItems.push(item);
88
- }
89
-
90
- if (item.children) {
91
- recursiveSearch(item.children, term);
92
- }
93
- }
94
- };
95
-
96
- recursiveSearch(formattedData, searchTerm);
97
- return matchedItems;
98
- };
99
-
100
- //function to get all items with checked = true
101
- export const getCheckedItems = (
102
- data: { [key: string]: any }[]
103
- ): { [key: string]: any }[] => {
104
- const checkedItems: { [key: string]: any }[] = [];
105
- if (!Array.isArray(data)) {
106
- return;
107
- }
108
- data.forEach((item: { [key: string]: any }) => {
109
- if (item.checked) {
110
- checkedItems.push(item);
111
- }
112
- if (item.children && item.children.length > 0) {
113
- const childCheckedItems = getCheckedItems(item.children);
114
- checkedItems.push(...childCheckedItems);
115
- }
116
- });
117
- return checkedItems;
118
- };
119
-
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);
130
- }
131
- });
132
- return childIds;
133
- };
134
-
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);
144
- }
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;
157
- };
158
-
159
- export const recursiveReturnOnlyParent = (
160
- items: { [key: string]: any },
161
- formattedData: { [key: string]: any }[],
162
- defaultReturn: { [key: string]: any }[],
163
- setDefaultReturn: any
164
- ) => {
165
- const parent = filterFormattedDataById(formattedData, items.parent_id);
166
- const allChildrenChecked = parent[0].children.every(
167
- (child: { [key: string]: any }) => child.checked
168
- );
169
- if (allChildrenChecked) {
170
- // Only return the parent and remove its children from defaultReturn
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
184
- const parentHasParent = parent[0].parent_id !== null;
185
- if (parentHasParent) {
186
- recursiveReturnOnlyParent(
187
- parent[0],
188
- formattedData,
189
- filteredDefaultReturn,
190
- setDefaultReturn
191
- );
192
- }
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
- };
@@ -1,72 +0,0 @@
1
- <%= pb_form_with(scope: :example, url: "", method: :get) do |form| %>
2
-
3
- <% treeData = [{
4
- label: "Power Home Remodeling",
5
- value: "Power Home Remodeling",
6
- id: "powerhome1",
7
- expanded: true,
8
- children: [
9
- {
10
- label: "People",
11
- value: "People",
12
- id: "people1",
13
- children: [
14
- {
15
- label: "Talent Acquisition",
16
- value: "Talent Acquisition",
17
- id: "talent1",
18
- },
19
- {
20
- label: "Business Affairs",
21
- value: "Business Affairs",
22
- id: "business1",
23
- children: [
24
- {
25
- label: "Initiatives",
26
- value: "Initiatives",
27
- id: "initiative1",
28
- },
29
- {
30
- label: "Learning & Development",
31
- value: "Learning & Development",
32
- id: "development1",
33
- },
34
- ],
35
- },
36
- {
37
- label: "People Experience",
38
- value: "People Experience",
39
- id: "experience1",
40
- },
41
- ],
42
- },
43
- {
44
- label: "Contact Center",
45
- value: "Contact Center",
46
- id: "contact1",
47
- children: [
48
- {
49
- label: "Appointment Management",
50
- value: "Appointment Management",
51
- id: "appointment1",
52
- },
53
- {
54
- label: "Customer Service",
55
- value: "Customer Service",
56
- id: "customer1",
57
- },
58
- {
59
- label: "Energy",
60
- value: "Energy",
61
- id: "energy1",
62
- },
63
- ],
64
- },
65
- ],
66
- }] %>
67
-
68
- <%= form.multi_level_select :example, props: {id: "with-form-multi-level-select", tree_data: treeData, return_all_selected: true } %>
69
- <%= form.actions do |action| %>
70
- <%= action.button props: { type: "submit", text: "Submit", variant: "primary", margin_top: "lg" } %>
71
- <% end %>
72
- <% end %>
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Playbook
4
- module Forms
5
- class Builder
6
- def multi_level_select(name, props: {})
7
- props[:name] = name
8
- @template.pb_rails("multi_level_select", props: props)
9
- end
10
- end
11
- end
12
- end