search-ui icon indicating copy to clipboard operation
search-ui copied to clipboard

[Issue / Feature Request] Dynamic URL tracking (urlTrackState)

Open wentaoxu415 opened this issue 3 years ago • 7 comments

Issue

As of now, the package offers a way to configure whether to do URL tracking through the urlTrackState config at the initial app mount. However, there isn't a way to dynamically configure URL tracking based on the search state / URL state during the same page session.

Having a way to support dynamic URL tracking is useful for the case in which you want to have fine control over the URL tracking behavior. For example, you want to have URL tracking enabled for most cases so that users can share URLs to get to the same search results. However, you want to turn this off for the case in which you want custom params to handle syncing the search state instead to be under browsers' max URL length or have the URL stay much shorter for simplicity.

Proposed Solution

Add support for dynamic toggle (switching on / off)

This solution will enable application developers to switch on / off URL tracking by passing config to the SearchProvider component

@JasonStoltz had already added a support for Dynamic Search Configuration, so this solution will built on top of that approach by adding an additional check for urlTrackState param in the config.

Pros

  • Very simple implementation

Cons

  • Can only toggle on / off URL tracking which leaves the responsibility of managing sync between URL and search state to developers in an unopinionated manner.

Alternatives

Add support for customized URL tracking

This solution will enable application developers to define customized URL tracking as a handler in the config.

At a high level, this solution will follow the approach already used by existing handlers (onSearch, onAutocomplete, onAutocompleteResultClick, onAutocompleteResultClick) and add support for a new handler that will pass params such as searchState and location object such that the application developers can define their custom logic in a function.

Pros

  • An opinionated and a clear way for application developers to define their custom URL tracking behavior

Cons

  • More work will be required to change how the URL tracking is currently done in searchDriver

wentaoxu415 avatar Jan 15 '22 23:01 wentaoxu415

So my vote will be for customized Url tracking which I think is something we need to introduce anyway to allow the developer to customise the url for other reasons (SEO namely)

Will come back with some examples of how this could work.

joemcelroy avatar Jan 17 '22 13:01 joemcelroy

Thanks for your input @joemcelroy. I agree that the long-term solution should support customized URL tracking.

In the short term, would your team be open to taking the PR for the dynamic toggle (the main proposal highlighted above)?

If so, I can create one from the patch that I used for my forked project. The patch consists of a few line changes along with unit test updates.

It is a very minor extension of @JasonStoltz 's work on Dynamic Search Configuration so hope that is still aligned with the current development pattern and support one more use case until the long-term solution can be established

wentaoxu415 avatar Jan 18 '22 21:01 wentaoxu415

Hey @wentaoxu415! continue to use your patch on your fork. Lets wait for more developers who ask for this feature, in meantime we will look to revisit URL management in the next month.

joemcelroy avatar Jan 19 '22 13:01 joemcelroy

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Is this issue still important to you? If so, please leave a comment and let us know. As always, thank you for your contributions.

botelastic[bot] avatar Mar 20 '22 13:03 botelastic[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Is this issue still important to you? If so, please leave a comment and let us know. As always, thank you for your contributions.

botelastic[bot] avatar May 20 '22 16:05 botelastic[bot]

I have similar issue with urlTrackState . I want to track some additional items thru URL but the only options I see is - not doing it and keep urlTrackState = true, or set urlTrackState = false and keep tracking everything myself. Would be great if there was a way to add items to track without need to reinvent a wheel.

karepiu avatar Jun 13 '22 16:06 karepiu

Tracking the work for this here: https://github.com/elastic/search-ui/issues/790

JasonStoltz avatar Jul 08 '22 17:07 JasonStoltz