Backport: Add support for sorting saved searches & dashboards by favorite status (7.0)#24847
Merged
Backport: Add support for sorting saved searches & dashboards by favorite status (7.0)#24847
Conversation
#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>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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:
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:
ViewServiceTest.searchPaginatedSortedByFavorite()Types of changes
Checklist: