Tag Browse Tree - Do NOT Show Empty Folders

Ignition Version 8.1.44 - Perspective

Current Use:
I am using the TagBrowseTree's extension function, filterBrowseNode, to only return tags with history.

from com.inductiveautomation.ignition.common.tags.browsing import NodeAttribute
return node.attributes.contains(NodeAttribute("history")) or node.hasChildren()

Issue:
The TagBrowseTree currently shows empty folders in the tag browser.

Goal:
Continue to filter the tree to only show tags with history, but only shows folders that contain tags with history.

Any suggests are greatly appreciated, thanks!

You will need to remove node.hasChildren() from the return, and write a recursive filter function.

Thank you for the reply!

I have previously attempted using recursion in this instance, but I am unsure how to iterate through the children nodes.

I have attempted:

for child in node:
for child in node.getChildren():
for child in node.getChildNodes():
for child in node.iterate():

If you have any insight on how to iterate through the child nodes, or don't think that it is necessary, and have any suggestions please let me know.