Skip to content

Conversation

@Baspa
Copy link
Contributor

@Baspa Baspa commented Sep 25, 2025

Problem

When using SelectTree with modifyQueryUsing to filter results, the component would show an empty dropdown if the filtered results didn't contain any items with parent_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:

  • Content type has parent filter: type_slug='page' AND slug='your-industry'
  • The filtered result is a single item that has a parent (not a root item)
  • SelectTree would show empty dropdown instead of the filtered item

Root Cause

The buildTreeFromResults() method was only displaying items that had parent_ulid = null (or the configured parent null value) as root items. When a query was filtered using modifyQueryUsing, 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:

  1. A query modification is being used (modifyQueryUsing is set)
  2. No root results are found ($rootResults is empty)
  3. But filtered results still exist ($results is 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.

Screenshot 2025-09-25 at 06 45 57 Screenshot 2025-09-25 at 06 45 45

Changes

  • Added conditional logic in buildTreeFromResults() to detect filtered queries with no root items
  • When detected, display all results as root items instead of showing empty tree
  • Preserves all existing functionality for normal tree building scenarios

Testing

  • ✅ Normal tree building (without modifyQueryUsing) works as before
  • ✅ Hierarchical trees with proper root items work as before
  • ✅ Filtered queries that return no results still show empty (correct behavior)
  • ✅ Filtered queries that return non-root items now display the results (fixed)

This fix ensures that SelectTree works correctly with filtered queries while maintaining backward compatibility with existing implementations.

@CodeWithDennis
Copy link
Owner

Cool! I need to test it properly. I’ll try to check it out this weekend and make a release. @Baspa

@CodeWithDennis CodeWithDennis merged commit b953e6d into CodeWithDennis:4.x Sep 27, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants