inviton-powerduck 0.0.217 → 0.0.219

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.
@@ -109,7 +109,8 @@ import { PortalUtils } from '../../../common/utils/utils';
109
109
  return stripDiacritics(text).toUpperCase();
110
110
  };
111
111
 
112
- let data = self.currentData || [];
112
+ let data = self.currentData || [] ;
113
+
113
114
  const searchTerm = normalizeForSearch(params.data?.term?.trim());
114
115
 
115
116
  if (searchTerm == null || searchTerm.trim() == '') {
@@ -117,10 +118,33 @@ import { PortalUtils } from '../../../common/utils/utils';
117
118
  return;
118
119
  }
119
120
 
120
- const filteredData = data.filter(item => {
121
- const itemText = normalizeForSearch(item.text);
122
- return itemText.includes(searchTerm);
123
- });
121
+ const filterItems = (items: any[], searchTerm: string): any[] => {
122
+ return items
123
+ .map(item => {
124
+ const itemText = normalizeForSearch(item.text);
125
+
126
+ // If item has children, filter them recursively
127
+ if (item.children && item.children.length > 0) {
128
+ const filteredChildren = filterItems(item.children, searchTerm);
129
+
130
+ // Keep parent if it matches OR if any child matches
131
+ if (itemText.includes(searchTerm) || filteredChildren.length > 0) {
132
+ return {
133
+ ...item,
134
+ children: filteredChildren
135
+ };
136
+ }
137
+ return null;
138
+ } else {
139
+ // Leaf node: keep if it matches
140
+ return itemText.includes(searchTerm) ? item : null;
141
+ }
142
+ })
143
+ .filter(Boolean); // remove nulls
144
+ };
145
+
146
+
147
+ const filteredData = filterItems(data, searchTerm);
124
148
 
125
149
  success({ results: filteredData || [] });
126
150
  // success({ results: data || [] });