Give ExtraNavItem more control over when it can be displayed.

This commit is contained in:
Guo Xiang Tan 2018-07-30 17:11:20 +08:00
parent ba64ebbf10
commit ef78268c01
2 changed files with 19 additions and 2 deletions

View File

@ -668,6 +668,18 @@ class PluginApi {
* displayName: "Discourse"
* href: "https://www.discourse.org",
* })
*
* An optional `customFilter` callback can be included to not display the
* nav item on certain routes
*
* Example:
*
* addNavigationBarItem({
* name: "link-to-bugs-category",
* displayName: "bugs"
* href: "/c/bugs",
* customFilter: (category, args) => { category && category.get('name') !== 'bug' }
* })
*/
addNavigationBarItem(item) {
if (!item["name"]) {

View File

@ -102,7 +102,8 @@ const NavItem = Discourse.Model.extend({
});
const ExtraNavItem = NavItem.extend({
@computed("href") href: href => href
@computed("href") href: href => href,
customFilter: null
});
NavItem.reopenClass({
@ -169,7 +170,11 @@ NavItem.reopenClass({
i => i !== null && !(category && i.get("name").indexOf("categor") === 0)
);
return items.concat(NavItem.extraNavItems);
const extraItems = NavItem.extraNavItems.filter(item => {
return item.customFilter && item.customFilter.call(this, category, args);
});
return items.concat(extraItems);
}
});