-
Notifications
You must be signed in to change notification settings - Fork 83
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
feat!: match query params when determining highlighted items #7139
Conversation
const paths = ['', '/', '/path', 'base/path']; | ||
|
||
beforeEach(() => { | ||
documentBaseURI = sinon.stub(document, 'baseURI').value('http://localhost/'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: web-test-runner adds a unique query parameter with a session ID to the base URI, which causes some tests to fail because they don't expect it. Stubbing the baseURI solves this problem.
Quality Gate passedIssues Measures |
this.pathAliases.some((alias) => matchPaths(document.location.pathname, alias)) | ||
); | ||
|
||
const browserPath = `${document.location.pathname}${document.location.search}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't found a trivial way to stub document.location
properties since they can't be rewritten, so I only verified this change through manual testing. Any ideas how to test it are welcome.
Snippet for manual testing: <vaadin-side-nav>
<span slot="label">Menu</span>
<vaadin-side-nav-item path="/dev/side-nav.html">
/dev/side-nav.html
</vaadin-side-nav-item>
<vaadin-side-nav-item path="/dev/side-nav.html?view">
/dev/side-nav.html?view
</vaadin-side-nav-item>
<vaadin-side-nav-item path="/dev/side-nav.html?view=users">
/dev/side-nav.html?view=users
</vaadin-side-nav-item>
<vaadin-side-nav-item path="/dev/side-nav.html?view=products">
/dev/side-nav.html?view=products
</vaadin-side-nav-item>
<vaadin-side-nav-item path="/dev/side-nav.html?view=products&product[]=1">
/dev/side-nav.html?view=products&product[]=1
</vaadin-side-nav-item>
<vaadin-side-nav-item path="/dev/side-nav.html?view=products&product[]=1&product[]=2">
/dev/side-nav.html?view=products&product[]=1&product[]=2
</vaadin-side-nav-item>
</vaadin-side-nav> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Regarding the following comment from the issue:
When using an item's URL to set defaults for dynamic params, such as for filtering or pagination, then changing those params would break matching. For example, if you configure an item with a URL like /products?pageSize=10 and then the page size is changed, the item wouldn't match anymore. Could be fixed on the application side by adding a path alias without the dynamic query params, or applying the defaults based on their absence in the URL.
As this could be a breaking change for some, let's note this down somehow, so that we can add something to the release notes.
expect(matchPaths('/products?c=socks', '/products?c=socks')).to.be.true; | ||
expect(matchPaths('/products?c=socks&item=5', '/products?c=socks')).to.be.true; | ||
expect(matchPaths('/products?item=5&c=socks', '/products?c=socks')).to.be.true; | ||
expect(matchPaths('/products?c=socks&c=pants', '/products?c=socks')).to.be.true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: The browser URL /products?c=socks&c=pants
matches the item path /products?c=socks
in my implementation, which deviates from @sissbruecker's proposal – see the case that is marked with a question mark in the table. In my opinion, the implemented behavior is more consistent with other cases.
This ticket/PR has been released with Vaadin 24.4.0. |
Description
The PR adds new logic to side-nav to match query params when determining highlighted items. A side-nav item is highlighted if the browser URL has the same base origin, the same path, and at least contains all the query parameters from the item's path.
Here is a table that illustrates which browser URLs would match which item URLs with the new logic:
Browser URL ⬇️
/products
/products?c=socks
/products?c=
/products?c=socks&c=pants
/products?socks
/products
/products?c=socks
/products?c=pants
/products?c=
/products?c=socks&item=5
/products?item=5&c=socks
/products?c=socks&c=pants
/products?socks
/products?socks=
Warning
Note that it's a breaking change for some configurations. When using an item's URL to set defaults for dynamic params, such as for filtering or pagination, then changing those params would break matching. For example, if you configure an item with a URL like /products?pageSize=10 and then the page size is changed, the item wouldn't match anymore. Could be fixed on the application side by adding a path alias without the dynamic query params, or applying the defaults based on their absence in the URL.
Fixes #6778
Type of change