Skip to content

Backport: Add support for sorting saved searches & dashboards by favorite status (7.0)#24847

Merged
janheise merged 2 commits into7.0from
issue-21659
Feb 2, 2026
Merged

Backport: Add support for sorting saved searches & dashboards by favorite status (7.0)#24847
janheise merged 2 commits into7.0from
issue-21659

Conversation

@kmerz
Copy link
Copy Markdown
Member

@kmerz kmerz commented Jan 27, 2026

Description

This PR enables users to sort their saved searches & dashboards by whether they are marked as favorites. Users can now click on the "Favorite" column header in the saved searches/dashboards list to toggle between:

  • Descending order (favorites first)
  • Ascending order (non-favorites first)

The implementation leverages the existing MongoDB aggregation pipeline that computes the favorite field at query time via a lookup join with the favorites collection, avoiding data duplication.

Note: This is a backport of #24809 to 7.0.

Motivation and Context

Users requested the ability to sort saved searches/dashboards by favorite status to quickly access their most important searches. Previously, the favorite field was displayed in the table but could not be used for sorting, requiring users to manually scan through the list to find their favorite searches.

How Has This Been Tested?

Backend testing:

  • Added comprehensive integration test ViewServiceTest.searchPaginatedSortedByFavorite()
    • Tests sorting by favorite in both DESC (favorites first) and ASC (non-favorites first) order
    • Validates that the MongoDB aggregation pipeline correctly computes and sorts by the favorite field
    • Manually inserts test favorites into the favorites collection to simulate real usage

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (non-breaking change)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have requested a documentation update.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

@kmerz kmerz changed the title Backport: Add support for sorting saved searches & dashboards by favorite status Backport: Add support for sorting saved searches & dashboards by favorite status (7.0) Jan 27, 2026
@janheise janheise self-assigned this Jan 28, 2026
kmerz and others added 2 commits January 29, 2026 14:38
#24809)

* Add support for sorting saved searches by favorite status

This change enables users to sort their saved searches by whether they
are marked as favorites. The sorting works by leveraging the existing
MongoDB aggregation pipeline that computes the favorite field at query
time via a lookup join with the favorites collection.

Changes:
- Add FIELD_FAVORITE to ViewDTO.SORT_FIELDS to allow sorting by this field
- Enable favorite sorting in SavedSearchesResource by removing sortable(false)
- Update OpenAPI schema to include "favorite" in allowable sort values
- Add integration test to verify favorite sorting works correctly in both
  ascending and descending order

The implementation maintains the current architecture where favorites
are stored in a separate collection, avoiding data duplication. The
favorite field is computed dynamically during the query via MongoDB
aggregation, then sorting is applied to the computed result.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Update saved searches test to include sortable favorite attribute

Update the mock attributes in SavedSearchesModal.test.tsx to include
the favorite attribute with sortable: true, reflecting the backend
change that now allows sorting by favorite status.

This ensures the test data matches the actual API response structure
and validates that the favorite column is properly displayed and
sortable in the saved searches list.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Use FavoritesService instead of direct MongoDB insert in test

Updated searchPaginatedSortedByFavorite test to use FavoritesService.save()
instead of directly inserting into the MongoDB favorites collection. This
addresses review feedback to prevent potential drift in the storage format.

Changes:
- Added GRNExtension to provide GRNRegistry for test setup
- Created FavoritesService using reflection to access protected constructor
- Created proper test user with specific ID using TestUser.builder()
- Use favoritesService.save() with FavoritesForUserDTO to create favorites
- Create GRNs using grnRegistry.newGRN() for proper GRN format

This ensures the test uses the same code path as production for creating
favorites, maintaining consistency with the actual storage format.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Add changelog entry for favorite sorting feature

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Fix forbidden API violation by using MongoCollection directly

Replace reflection-based FavoritesService instantiation with direct
MongoCollection access to avoid forbidden API violation (setAccessible).

The test now uses mongoCollections.collection("favorites", FavoritesForUserDTO.class)
to insert favorites, which ensures proper serialization using the same
FavoritesForUserDTO structure as FavoritesService, preventing storage
format drift without violating forbidden API rules.

Changes:
- Removed reflection imports and reflection-based constructor access
- Use MongoCollection<FavoritesForUserDTO> from mongoCollections
- Create and insert FavoritesForUserDTO directly using insertOne()
- Added comment explaining this uses the same structure as FavoritesService

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Enabling sort by favorite for dashboards as well.

* Updating changelog snippet.

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: Dennis Oelkers <dennis@graylog.com>
Copy link
Copy Markdown
Contributor

@janheise janheise left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@janheise janheise merged commit 68ff326 into 7.0 Feb 2, 2026
16 checks passed
@janheise janheise deleted the issue-21659 branch February 2, 2026 09:10
kmerz added a commit that referenced this pull request Feb 2, 2026
…rite status (7.0) (#24847)

* Add support for sorting saved searches & dashboards by favorite status (#24809)

* Add support for sorting saved searches by favorite status

This change enables users to sort their saved searches by whether they
are marked as favorites. The sorting works by leveraging the existing
MongoDB aggregation pipeline that computes the favorite field at query
time via a lookup join with the favorites collection.

Changes:
- Add FIELD_FAVORITE to ViewDTO.SORT_FIELDS to allow sorting by this field
- Enable favorite sorting in SavedSearchesResource by removing sortable(false)
- Update OpenAPI schema to include "favorite" in allowable sort values
- Add integration test to verify favorite sorting works correctly in both
  ascending and descending order

The implementation maintains the current architecture where favorites
are stored in a separate collection, avoiding data duplication. The
favorite field is computed dynamically during the query via MongoDB
aggregation, then sorting is applied to the computed result.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Update saved searches test to include sortable favorite attribute

Update the mock attributes in SavedSearchesModal.test.tsx to include
the favorite attribute with sortable: true, reflecting the backend
change that now allows sorting by favorite status.

This ensures the test data matches the actual API response structure
and validates that the favorite column is properly displayed and
sortable in the saved searches list.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Use FavoritesService instead of direct MongoDB insert in test

Updated searchPaginatedSortedByFavorite test to use FavoritesService.save()
instead of directly inserting into the MongoDB favorites collection. This
addresses review feedback to prevent potential drift in the storage format.

Changes:
- Added GRNExtension to provide GRNRegistry for test setup
- Created FavoritesService using reflection to access protected constructor
- Created proper test user with specific ID using TestUser.builder()
- Use favoritesService.save() with FavoritesForUserDTO to create favorites
- Create GRNs using grnRegistry.newGRN() for proper GRN format

This ensures the test uses the same code path as production for creating
favorites, maintaining consistency with the actual storage format.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Add changelog entry for favorite sorting feature

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Fix forbidden API violation by using MongoCollection directly

Replace reflection-based FavoritesService instantiation with direct
MongoCollection access to avoid forbidden API violation (setAccessible).

The test now uses mongoCollections.collection("favorites", FavoritesForUserDTO.class)
to insert favorites, which ensures proper serialization using the same
FavoritesForUserDTO structure as FavoritesService, preventing storage
format drift without violating forbidden API rules.

Changes:
- Removed reflection imports and reflection-based constructor access
- Use MongoCollection<FavoritesForUserDTO> from mongoCollections
- Create and insert FavoritesForUserDTO directly using insertOne()
- Added comment explaining this uses the same structure as FavoritesService

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Enabling sort by favorite for dashboards as well.

* Updating changelog snippet.

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: Dennis Oelkers <dennis@graylog.com>

* Enable sorting in the SavedSearchesResource

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: Dennis Oelkers <dennis@graylog.com>
janheise pushed a commit that referenced this pull request Feb 3, 2026
…rite status (7.0) (#24847) (#24913)

* Add support for sorting saved searches & dashboards by favorite status (#24809)

* Add support for sorting saved searches by favorite status

This change enables users to sort their saved searches by whether they
are marked as favorites. The sorting works by leveraging the existing
MongoDB aggregation pipeline that computes the favorite field at query
time via a lookup join with the favorites collection.

Changes:
- Add FIELD_FAVORITE to ViewDTO.SORT_FIELDS to allow sorting by this field
- Enable favorite sorting in SavedSearchesResource by removing sortable(false)
- Update OpenAPI schema to include "favorite" in allowable sort values
- Add integration test to verify favorite sorting works correctly in both
  ascending and descending order

The implementation maintains the current architecture where favorites
are stored in a separate collection, avoiding data duplication. The
favorite field is computed dynamically during the query via MongoDB
aggregation, then sorting is applied to the computed result.



* Update saved searches test to include sortable favorite attribute

Update the mock attributes in SavedSearchesModal.test.tsx to include
the favorite attribute with sortable: true, reflecting the backend
change that now allows sorting by favorite status.

This ensures the test data matches the actual API response structure
and validates that the favorite column is properly displayed and
sortable in the saved searches list.



* Use FavoritesService instead of direct MongoDB insert in test

Updated searchPaginatedSortedByFavorite test to use FavoritesService.save()
instead of directly inserting into the MongoDB favorites collection. This
addresses review feedback to prevent potential drift in the storage format.

Changes:
- Added GRNExtension to provide GRNRegistry for test setup
- Created FavoritesService using reflection to access protected constructor
- Created proper test user with specific ID using TestUser.builder()
- Use favoritesService.save() with FavoritesForUserDTO to create favorites
- Create GRNs using grnRegistry.newGRN() for proper GRN format

This ensures the test uses the same code path as production for creating
favorites, maintaining consistency with the actual storage format.



* Add changelog entry for favorite sorting feature



* Fix forbidden API violation by using MongoCollection directly

Replace reflection-based FavoritesService instantiation with direct
MongoCollection access to avoid forbidden API violation (setAccessible).

The test now uses mongoCollections.collection("favorites", FavoritesForUserDTO.class)
to insert favorites, which ensures proper serialization using the same
FavoritesForUserDTO structure as FavoritesService, preventing storage
format drift without violating forbidden API rules.

Changes:
- Removed reflection imports and reflection-based constructor access
- Use MongoCollection<FavoritesForUserDTO> from mongoCollections
- Create and insert FavoritesForUserDTO directly using insertOne()
- Added comment explaining this uses the same structure as FavoritesService



* Enabling sort by favorite for dashboards as well.

* Updating changelog snippet.

---------




* Enable sorting in the SavedSearchesResource

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: Dennis Oelkers <dennis@graylog.com>
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