Skip to content

Commit

Permalink
Add fallback value to dd.LinkTo component (#658)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffdaley committed Mar 22, 2024
1 parent f8db8c0 commit fad671b
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 20 deletions.
1 change: 0 additions & 1 deletion web/app/components/header/facet-dropdown.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<:item as |dd|>
<dd.LinkTo
data-test-facet-dropdown-link
@route={{this.currentRouteName}}
@query={{get-facet-query-hash @name dd.value dd.attrs.isSelected}}
>
<X::DropdownList::CheckableItem
Expand Down
8 changes: 0 additions & 8 deletions web/app/components/header/facet-dropdown.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Component from "@glimmer/component";
import { FacetDropdownObjects } from "hermes/types/facets";
import { inject as service } from "@ember/service";
import RouterService from "@ember/routing/router-service";
import { FacetName } from "./toolbar";

interface HeaderFacetDropdownComponentSignature {
Expand All @@ -13,12 +11,6 @@ interface HeaderFacetDropdownComponentSignature {
}

export default class HeaderFacetDropdownComponent extends Component<HeaderFacetDropdownComponentSignature> {
@service declare router: RouterService;

protected get currentRouteName() {
return this.router.currentRouteName;
}

protected get isDisabled() {
return !this.args.facets || Object.keys(this.args.facets).length === 0;
}
Expand Down
1 change: 0 additions & 1 deletion web/app/components/header/sort-dropdown.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
</:anchor>
<:item as |dd|>
<dd.LinkTo
@route={{this.currentRouteName}}
@query={{hash
sortBy=(if (eq dd.value "Newest") this.dateDesc this.dateAsc)
}}
Expand Down
8 changes: 0 additions & 8 deletions web/app/components/header/sort-dropdown.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Component from "@glimmer/component";
import { SortByFacets, SortByValue } from "./toolbar";
import { inject as service } from "@ember/service";
import RouterService from "@ember/routing/router-service";
import { Placement } from "@floating-ui/dom";

interface HeaderSortDropdownComponentSignature {
Expand All @@ -15,12 +13,6 @@ interface HeaderSortDropdownComponentSignature {
}

export default class HeaderSortDropdownComponent extends Component<HeaderSortDropdownComponentSignature> {
@service declare router: RouterService;

get currentRouteName() {
return this.router.currentRouteName;
}

get dateDesc() {
return SortByValue.DateDesc;
}
Expand Down
2 changes: 1 addition & 1 deletion web/app/components/x/dropdown-list/link-to.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
aria-selected={{@isAriaSelected}}
tabindex="-1"
aria-checked={{@isAriaChecked}}
@route={{@route}}
@route={{this.route}}
@query={{maybe-query @query}}
@models={{model-or-models @model @models}}
class="x-dropdown-list-item-link {{if @isAriaSelected 'is-aria-selected'}}"
Expand Down
13 changes: 12 additions & 1 deletion web/app/components/x/dropdown-list/link-to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { XDropdownListInteractiveComponentArgs } from "./_shared";
import { action } from "@ember/object";
import Ember from "ember";
import { next, schedule } from "@ember/runloop";
import { inject as service } from "@ember/service";
import RouterService from "@ember/routing/router-service";

interface XDropdownListLinkToComponentSignature {
Element: HTMLAnchorElement;
Args: XDropdownListInteractiveComponentArgs & {
route: string;
route?: string;
query?: Record<string, unknown>;
model?: unknown;
models?: unknown[];
Expand All @@ -18,6 +20,15 @@ interface XDropdownListLinkToComponentSignature {
}

export default class XDropdownListLinkToComponent extends Component<XDropdownListLinkToComponentSignature> {
@service declare router: RouterService;

/**
* The route passed to Ember's <LinkTo> component.
* Uses the passed-in value or the current route name.
*/
protected get route() {
return this.args.route ?? this.router.currentRouteName;
}
/**
* The action to run when the item is clicked.
* We wait until the next run loop so that we don't interfere with
Expand Down

0 comments on commit fad671b

Please sign in to comment.