Skip to content

Conversation

@yomete
Copy link
Contributor

@yomete yomete commented Jan 7, 2026

This PR extends useURLState, useQueryState, and related hooks to support view-aware state management.

The core change is adding a mergeStrategy option to useURLState with three modes: replace (default), preserve-existing (only apply if URL param is empty), and append (merge arrays with deduplication). This enables views to provide default configuration that respects user modifications already in the URL.

The useQueryState hook now supports viewDefaults props passed from upstream and methods like applyViewDefaults() and forceApplyViewDefaults() for applying view settings. It also now parses expressions to extract profile type components and can auto-prepend a profile type to matchers-only expressions (e.g., {comm='parca'}).

The useProfileFiltersUrlState hook now also supports a applyViewDefaults() and forceApplyFilters() for managing profile filter defaults from views.

Also added comprehensive tests for the new functionality including useURLState merge strategies and view defaults application.

Enhances the useURLState hook with mergeStrategy ('replace', 'append', 'preserve-existing'), namespace, and enabled options for more flexible URL state management. Adds useURLStateReset hook to clear specific URL params and a hasQueryParams helper. Updates tests to cover new behaviors and options.
Introduces support for view-specific defaults in useQueryState and related hooks, ensuring defaults are only applied when URL params are empty and do not overwrite existing values.
Introduces a forceApplyFilters method to profile filter hooks for bypassing the preserve-existing strategy. Enhances useQueryState to support matchers-only view defaults by prepending the first available profile type, and ensures view defaults are reapplied when profile types finish loading. Also removes debug logging from useLabels.
Introduces a forceApplyViewDefaults method to the useQueryState hook, allowing view defaults to be forcibly applied and overwrite existing URL parameters. Updates tests to cover this new behavior and ensures groupBy and sumBy are applied even if profile types are loading or unavailable for matchers-only expressions. Also fixes groupBy handling in useURLState to always return an array.
@yomete yomete requested a review from a team as a code owner January 7, 2026 14:42
@alwaysmeticulous
Copy link

alwaysmeticulous bot commented Jan 7, 2026

✅ Meticulous spotted visual differences in 33 of 378 screens tested, but all differences have already been approved: view differences detected.

Meticulous evaluated ~4 hours of user flows against your PR.

Last updated for commit 9e64bd4. This comment will update as new commits are pushed.

- Add return types to helper functions in useQueryState.test.tsx
- Remove unnecessary undefined initialization
- Restore build-preview.sh that was corrupted with Go code
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