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

Keep (Parent Route) Query Parameters #476

Open
buschtoens opened this issue Nov 16, 2020 · 5 comments
Open

Keep (Parent Route) Query Parameters #476

buschtoens opened this issue Nov 16, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@buschtoens
Copy link
Owner

buschtoens commented Nov 16, 2020

The default behavior of Ember's <LinkTo> is to keep the query parameters of parent routes.

<Link> does not auto-append any query parameters to the generated URL. They need to be passed in explicitly via @query. This is über annoying, when you want to use <Link> as a substitute for <LinkTo> in a scenario where a child route links back to a parent route.

<Link> and {{link}} should offer a @keepQuery option. It can take these values:

  • none / falsy value (default, current behavior): No QPs of the current location are kept.
    • Only QPs provided via @query are appended.
  • known: Only QPs of the current location at the time of invocation that are defined as known QPs in the current route hierarchy are kept.
    • QPs provided via @query override these QPs individually.
    • A null / undefiend value in the @query object will remove a kept QP.
  • all: All QPs of the current location at the time of invocation are kept.
    • QPs provided via @query override these QPs individually.
    • A null / undefiend value in the @query object will remove a kept QP.
  • tracked-known: Only QPs that are defined as known QPs in the current route hierarchy are kept.
    • When the the current route / QPs change, the url will be updated live.
    • QPs provided via @query override these QPs individually.
    • A null / undefiend value in the @query object will remove a kept QP.
  • tracked-all: All QPs of the current location are kept.
    • When the the current route / QPs change, the url will be updated live.
    • QPs provided via @query override these QPs individually.
    • A null / undefiend value in the @query object will remove a kept QP.

Unresolved Questions

none is the current behavior. Changing this would be a breaking change IMO, so I'd make it the default, too. Do we want to keep it this way though or switch to a different default?

Assuming we want to switch, we could raise a deprecation warning, prompting the user to explicitly chose none or a different behavior.
Should the default be configurable or should we allow users to opt-in to the new default mode prior to upgrading to the next major version?

Do the names used here make sense? @keepQuery, none, known, all, tracked-*, untracked-*?

Do we need the tracked-* variants? Or do we not need the untracked variant? Should the untracked variants also be prefixed with untracked-*? Or should the tracked-* variants instead have no prefix?

@buschtoens buschtoens added the enhancement New feature or request label Nov 16, 2020
@betocantu93
Copy link

betocantu93 commented May 18, 2023

+1! I wanted to make a super useful wrapper around this primitive like

class IssueModel extends Model {
   @cached
   get editLink() {
        return this.linkManager.createLink({ route: 'auth.projects.issues', models:[1,3] })
   }
}

//any template

<a href={{@issue.editLink.url}} />

//any js

@action
onClick(issue: IssueModel) {
   issueModel.editLink.transitionTo();
}

But I wanted these urls to be live, respect like, tracked-all scenario

@betocantu93
Copy link

betocantu93 commented May 18, 2023

I think what ember-href-to does is just recalculating on route change

https://github.com/intercom/ember-href-to/blob/fa089ab8a8c32a9053da0fec989b4e81ebe95188/addon/helpers/href-to.js#L35

@betocantu93
Copy link

Screen Shot 2023-05-18 at 16 57 18

This is a PoC but it works

@betocantu93
Copy link

I got it working!

@betocantu93
Copy link

I think the only one that is hard to have a non-tracked version is known because accesing the qps metadata from the current route inside an autotracking context entangles it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants