Skip to content

Commit

Permalink
fix(linked-items): use named dynamic segments
Browse files Browse the repository at this point in the history
  • Loading branch information
anehx committed Jan 31, 2022
1 parent 9f63956 commit 1d7a8db
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions addon/components/-private/linked-list-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import { inject as service } from "@ember/service";
import Component from "@glimmer/component";

function getParams(currentRouteInfo) {
let params = [];
const params = { ...currentRouteInfo.params };

while (currentRouteInfo.parent) {
params = [currentRouteInfo.params, ...params];
currentRouteInfo = currentRouteInfo.parent;
if (currentRouteInfo.parent) {
return { ...params, ...getParams(currentRouteInfo.parent) };
}

return params.map(Object.values).flat();
return params;
}

export default class LinkedListItemComponent extends Component {
Expand Down Expand Up @@ -61,17 +60,17 @@ export default class LinkedListItemComponent extends Component {

if (!routeInfo) return null;

return { routeInfo, dynamicSegments: getParams(routeInfo) };
return { routeInfo, models: getParams(routeInfo) };
}

get active() {
if (!this.route || this.args.active !== undefined) {
return this.args.active ?? false;
}

const { routeInfo, dynamicSegments } = this.route;
const { routeInfo, models } = this.route;

return this.router.isActive(routeInfo.name, ...dynamicSegments, {
return this.router.isActive(routeInfo.name, models, {
queryParams: routeInfo.queryParams,
});
}
Expand All @@ -83,8 +82,8 @@ export default class LinkedListItemComponent extends Component {
if (typeof this.args.onClick === "function") {
this.args.onClick(...[event, this.href].filter(Boolean));
} else if (this.route) {
const { routeInfo, dynamicSegments } = this.route;
this.router.transitionTo(routeInfo.name, ...dynamicSegments, {
const { routeInfo, models } = this.route;
this.router.transitionTo(routeInfo.name, models, {
queryParams: routeInfo.queryParams,
});
}
Expand Down

0 comments on commit 1d7a8db

Please sign in to comment.