Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setDefaultQueryParamValue - not working as expected? #23

Closed
aaronfischer opened this issue May 25, 2017 · 5 comments
Closed

setDefaultQueryParamValue - not working as expected? #23

aaronfischer opened this issue May 25, 2017 · 5 comments

Comments

@aaronfischer
Copy link

aaronfischer commented May 25, 2017

First off, I think I just stumbled upon a gem. 👍 LOVE the problems this addon is proposing to solve!

(Let me know if my expectations are off on this or not.)
I'm assuming that anywhere/anytime I set setDefaultQueryParamValue and those queryParams are in the URI they'll be removed (because they are now the default)? Currently that isn't the case though, looks to be the same way in the demo as well. You add "Jump" to the tags and hit "Set as Defaults" but it remains in the URI.
Is this the expected behavior?

Then, my own application, (perhaps you can tell me if this is the improper place to use setDefaultQueryParamValue):
Within my route's setupController I make a request to the API and in that response I'm able to derive what my queryParams defaults will be so I fire controller.setDefaultQueryParamValue('facetContext', record.mapBy('key')); however like I previously noted the URI does not change and is still populated with the query param values (which should now be the defaults).

Thanks!


EDIT: I've also tried moving my setDefaultQueryParamValue call into the beforeModel hook in case things need to be set before a model hook resolves.
Just as a test if I was to statically set the defaultValue: ['value1', 'value2'], it will work as expected (omitting these values from the URL) but using setDefaultQueryParamValue instead does not work.

@offirgolan
Copy link
Owner

offirgolan commented May 27, 2017

@aaronfischer glad you're liking that addon!

You add "Jump" to the tags and hit "Set as Defaults" but it remains in the URI.
Is this the expected behavior?

This is actually intended behavior. Since we cant control whats in the URI, setDefaultQueryParamValue and defaultValue are only used to check for changes and give you the ability to reset your query params to their specified defaults.

EDIT:

I think this should be added to the documentation so others are not confused as well.

@aaronfischer
Copy link
Author

@offirgolan Oh okay, thanks! So, if you don't mind, where would be the proper place to set the defaultValue to not have it appear in the URI?

I was thinking that if setDefaultQueryParamValue was called in beforeModel that should prevent it from being added to the URI? (but I'm not finding that to be true)

@offirgolan
Copy link
Owner

@aaronfischer the URI default values are set by Ember on initial runtime. There currently is no way to change it no matter where you actually put the setDefaultQueryParamValue logic 😞 .

I guess one way to do this might be to make your API call in an initializer and create your QueryParam map from there and mix it in to the appropriate controller.

@aaronfischer
Copy link
Author

Thanks @offirgolan . I ended up re-evaluating how I could make this work, long story short, its not a requirement for our API to receive those defaultValues (if the arrays match) so I was able to essentially just not set that specific query controller property if its expected value matched the defaultValues.

A bit of additional management involved but it seems to work fine in our case.

Looks like this is/was a non-issue of the add-on, thanks!

@allthesignals
Copy link

allthesignals commented Apr 28, 2018

I guess one way to do this might be to make your API call in an initializer and create your QueryParam map from there and mix it in to the appropriate controller.

This is interesting and could be a way to approach my issue in #54. Curious if you have an example for it?

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

No branches or pull requests

3 participants