playbook_ui 12.26.0.pre.alpha.railsmultilevelimprovements805 → 12.26.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79c732fa4dc676050bdbc6dda57f9a180670d812ffeeb73ba5d410a683a2c6bf
4
- data.tar.gz: 332c5b9b341d69f47d83af65dfd5936918ee3b7e4149884892a8c4926b7ec3e7
3
+ metadata.gz: 7fbc9b56c02a9915257f3a1169f85773e8a063c14de44a2492a250f9015dee65
4
+ data.tar.gz: f70c024e4feae26b0767595ad538df87eb08e78453a56c6ca22de07552d60d5d
5
5
  SHA512:
6
- metadata.gz: bd51e6d5feffbe630c6e315e17e108d3f2c2d55a55b2ba12fbe14894950f61e9d457cb29899993a7f990564140e95e78c8251e675cfa7f3048dacfb7cb24d72f
7
- data.tar.gz: fd53b4b633ea48c3b6db1f2f87c017509db18cf1d7732d9a1992ee3147e8df41d6e0b05fa1bf5f876c2304c3ae71ddb8627deb1e5abd65de8d8f14ccac9bc139
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
- formattedData: { [key: string]: any }[],
3
+ data: { [key: string]: any }[],
20
4
  item: { [key: string]: any }
21
5
  ) => {
22
6
  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
- }
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
- 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);
82
+ const traverseTree = (items:{ [key: string]: any }[]) => {
83
+ if (!Array.isArray(items)) {
84
+ return;
130
85
  }
131
- });
132
- return childIds;
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
- 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);
102
+ if (item.children && item.children.length > 0) {
103
+ traverseTree(item.children);
144
104
  }
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;
105
+ });
106
+ };
107
+
108
+ traverseTree(treeData);
109
+
110
+ return checkedDefault;
157
111
  };
158
112
 
159
- export const recursiveReturnOnlyParent = (
160
- items: { [key: string]: any },
161
- formattedData: { [key: string]: any }[],
162
- defaultReturn: { [key: string]: any }[],
163
- setDefaultReturn: any
113
+ export const recursiveCheckParent = (
114
+ item: { [key: string]: any },
115
+ data:any
164
116
  ) => {
165
- const parent = filterFormattedDataById(formattedData, items.parent_id);
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
- recursiveReturnOnlyParent(
126
+ recursiveCheckParent(
187
127
  parent[0],
188
- formattedData,
189
- filteredDefaultReturn,
190
- setDefaultReturn
128
+ data
191
129
  );
192
130
  }
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
- };
131
+ }
132
+ }
133
+ return data;
134
+ }