JairajJangle / react-native-tree-multi-select

Super-fast tree view with multi-selection capabilities, using checkboxes and search filtering.
MIT License
35 stars 4 forks source link

[FEAT-REQ] Handle empty children array like no children array attribute. #62

Open edencorbin opened 3 weeks ago

edencorbin commented 3 weeks ago

Is your feature request related to a problem? Please describe. I was getting weird behavior, checking sort-of working but unable to un-check, when there were empty arrays of children, if I recursively delete any empty arrays of "children" attributes it works as intended, the library should gracefully handle an empty array.

Describe the solution you'd like The library should handle no "children" attribute just as well / the same as an empty array children.

Describe alternatives you've considered I had to add this to my function:

// Step 3: Remove empty children arrays
function removeEmptyChildren(rmArr: any[]) {
  rmArr.forEach(rm => {
      if (rm.children.length === 0) {
          delete rm.children;
      } else {
          removeEmptyChildren(rm.children);
      }
  });
}

removeEmptyChildren(tree);

Screenshots or screen records NA

Additional context NA

Would you like to work on this feature? Potentially, havn't really dug into the code yet.

JairajJangle commented 2 weeks ago

Hey there! 👋

Thank you for bringing this issue to my attention! 😊

I will update the test cases to cover this scenario. Instead of patching the tree data to remove empty children, as suggested in your workaround, I believe it would be more elegant to address this directly within the tree check/uncheck logic. I'll look into implementing a fix for this in the core logic itself.

Could you please update your issue description with the version of the react-native-tree-multi-select module you are using? This will help me ensure compatibility and proper testing.

Thanks again for your valuable feedback! 🙏