fix: SelectTree shows empty dropdown when filtered results have no root items #178
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When using
SelectTreewithmodifyQueryUsingto filter results, the component would show an empty dropdown if the filtered results didn't contain any items withparent_ulid = null(root items). This happened because the component was only looking for items that matched the expected parent structure, but filtered queries might return items that don't fit this hierarchy.Example scenario:
type_slug='page' AND slug='your-industry'Root Cause
The
buildTreeFromResults()method was only displaying items that hadparent_ulid = null(or the configured parent null value) as root items. When a query was filtered usingmodifyQueryUsing, the filtered results might not contain any true root items, causing the tree to be empty even though valid results existed.Solution
Modified
buildTreeFromResults()to handle the edge case where:modifyQueryUsingis set)$rootResultsis empty)$resultsis not empty)In this case, the component now displays all filtered results as root items to prevent empty trees, while preserving the original hierarchical behavior for normal use cases.
Changes
buildTreeFromResults()to detect filtered queries with no root itemsTesting
modifyQueryUsing) works as beforeThis fix ensures that SelectTree works correctly with filtered queries while maintaining backward compatibility with existing implementations.