@@ -74,6 +74,14 @@ const setPreSelectedItems = (items: TreeViewDataItem[], selectedIds: string[]):
7474 } ;
7575 } ) ;
7676
77+ // Helper function to uncheck all items recursively
78+ const uncheckRecursive = ( items : TreeViewDataItem [ ] ) : TreeViewDataItem [ ] =>
79+ items . map ( item => ( {
80+ ...item ,
81+ checkProps : item . checkProps ? { ...item . checkProps , checked : false } : undefined ,
82+ children : item . children ? uncheckRecursive ( item . children ) : undefined
83+ } ) ) ;
84+
7785export interface DataViewTreeFilterProps {
7886 /** Unique key for the filter attribute */
7987 filterId : string ;
@@ -177,13 +185,6 @@ export const DataViewTreeFilter: FC<DataViewTreeFilterProps> = ({
177185
178186 // Only update if there are checked items that need to be unchecked
179187 if ( currentCheckedItems . length > 0 ) {
180- const uncheckRecursive = ( items : TreeViewDataItem [ ] ) : TreeViewDataItem [ ] =>
181- items . map ( item => ( {
182- ...item ,
183- checkProps : item . checkProps ? { ...item . checkProps , checked : false } : undefined ,
184- children : item . children ? uncheckRecursive ( item . children ) : undefined
185- } ) ) ;
186-
187188 return uncheckRecursive ( currentTreeData ) ;
188189 }
189190
@@ -310,13 +311,6 @@ export const DataViewTreeFilter: FC<DataViewTreeFilterProps> = ({
310311
311312 // Uncheck all items in the tree
312313 const uncheckAllItems = ( ) => {
313- const uncheckRecursive = ( items : TreeViewDataItem [ ] ) : TreeViewDataItem [ ] =>
314- items . map ( item => ( {
315- ...item ,
316- checkProps : item . checkProps ? { ...item . checkProps , checked : false } : undefined ,
317- children : item . children ? uncheckRecursive ( item . children ) : undefined
318- } ) ) ;
319-
320314 const updatedTreeData = uncheckRecursive ( treeData ) ;
321315 setTreeData ( updatedTreeData ) ;
322316 onChange ?.( undefined , [ ] ) ;
0 commit comments