FIX: uses simpler pattern for custom href on extra nav items (#8015)

THe main advantage of this solution is that it will be called on each rerendered whereas the other is not once href has been set.

Example API:
```
      api.addNavigationBarItem({
        name: "foo",
        displayName: "Foo",
        customHref: function(category, args) {
          const router = api.container.lookup("service:router");
          const queryParams = { bar: "1" };
          return router.urlFor(router.currentRouteName, category, {
            queryParams
          });
        }
      });
```
This commit is contained in:
Joffrey JAFFEUX 2019-08-19 08:27:16 +02:00 committed by Sam
parent 10b36c6446
commit 897cdfb596

View File

@ -101,18 +101,8 @@ const NavItem = Discourse.Model.extend({
});
const ExtraNavItem = NavItem.extend({
href: Ember.computed({
set(key, value) {
let customHref;
NavItem.customNavItemHrefs.forEach(function(cb) {
customHref = cb.call(this, this);
if (customHref) {
return false;
}
}, this);
return customHref || value;
}
}),
@computed("href")
href: href => href,
customFilter: null
});
@ -189,6 +179,11 @@ NavItem.reopenClass({
return item.customFilter.call(this, category, args);
});
extraItems.forEach(item => {
if (!item.customHref) return;
item.set("href", item.customHref.call(this, category, args));
});
return items.concat(extraItems);
}
});