-
-
Notifications
You must be signed in to change notification settings - Fork 161
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
Links include default param in url in 0.24 #1279
Comments
Actually, that was something @stephendolan requested and @matthewmcgarvey made a PR for 😅 #1201 So I guess the question is... which way do we want it? I can't think of a way where we can have both 🤔 |
@jwoertink hehe, typical. Why I want to fill parameters even if it defaults is to make it easier to handle fallback if it is not filled. Now I would need to do if statement for every parameter to check if it is default value. How it worked before was nice as I didn't need to think about that. I think it seems to be good to use in different situations. |
maybe @stephendolan and @matthewmcgarvey have some ideas as well? Would love to discuss how we can solve this is the best way :) Otherwise, I will just fork and revert #1201 |
I agree that in your case it's not a clean url, but I don't know of any examples where it wouldn't look like that in another framework. Looking into kindmetrics source, I see that most of the issue is coming from https://github.com/kindmetrics/kindmetrics/blob/66cffa4042a8c9201c1d601a5447d83cb3d95371/src/pages/domains/show_page.cr#L150-L158 Maybe instead of setting the default value if it is missing you could set it to nil. By making it nil it won't be added to the generated url. Would that work? |
@matthewmcgarvey those are only used for the tabs (filters) when clicking on the page URL or sources to filter it, you will get a tab on top left corner. These are used there. I can fix these at least with nil. So it solves one part of the puzzle. On the date picker dropdown and on all links, it won't work. Those would need to add if statements as they don't use it. |
Would making the |
Yeah, my original submission (thinking it was a bug) mainly stemmed from a lot of confusion about why things I was explicitly passing seemed to be disappearing since other frameworks I've used didn't handle things that way. I do still think that going with the implementation of "least surprise" that we're at now seems nicer from a framework perspective, but if we can find a way to eject from that default and filter them from the URL more elegantly I'm certainly in favor. |
As an example: I think Granted, it can lead to some ugly URLs, but since the code asked for those parts of the URL explicitly, that feels correct. And I completely understand @confact's problem here that a page necessarily needs to know what parameterized data to display and those parameters have to come from somewhere. It's a difficult problem to solve with only a route object. Could a solution be to push the problem up to the param level instead of trying to solve it in the route level? Instead of having multiple
I think this allows:
Thoughts? |
@edwardloveall that sounds like a good solution in the right direction. I am not totally sold on having one object handling all params. but indeed sound like a good start point. Maybe have the object in the background and let it be controller by macro methods to set the settings could be a good way? @matthewmcgarvey thank you for trying to help me fix the issues. I have fixed most of the issues which were due to empty strings here: kindmetrics/kindmetrics#106 - But it still doesn't act the way I want on to and from and period due to default value. I would need to add checks on the period on the links there if the period is the default value. Otherwise, it is okay, 50 lines more code, and still works almost the same. I really did like that the URL generator took care of my default values for me. That was actually one of the things that made me go wow when coding https://github.com/microgit-com/microgit and Kindmetrics. This does feel like a personal touch/interest. And I understand I am the minority here. So you can close this and I have to find ways to figure out my issues with default values on |
Just seeing this now. I do think the current behavior is the "least surprising" but I do get what you mean @confact. I think ideally we keep the current behavior as-is, but add an option for the param show_something : Bool = true, hide_defaults_from_params: true This is a horrible option name, but I think this could make it so people can customize the handling of params. I think this is a lower priority since there are lots of other feature, but this could be an option if the code isn't too crazy. Thoughts? |
@paulcsmith I understand that for the majority it is easier as it is now. So I am okay with that. I like this setting to the param macro. the option name could be: param show_something : Bool = true, hide_default: true it should maybe default to So in summary, I do like this more. I hope @edwardloveall, @matthewmcgarvey, and @jwoertink agrees :) |
I noticed that after I upgraded to 0.24 it started including the query in links even if they are not really set and should use the default values.
This is deployed in production on Kindmetrics as it does work but doesn't look nice. You can see at the demo:
https://app.kindmetrics.io/share/851Jv1PW
Click on pages or sources and you can see the URL have all queries with default values.
I use this code to generate the URLs (which worked prev 0.24):
This would be nice to get fixed as it doesn't look nice :)
The text was updated successfully, but these errors were encountered: