DEV: Support custom icon when adding custom link to sidebar via plugin API (#21760)

This commit is contained in:
Alan Guo Xiang Tan
2023-05-26 17:46:33 +09:00
committed by GitHub
parent ae74d5b32e
commit 0bff95fcad
3 changed files with 27 additions and 6 deletions

View File

@@ -1848,10 +1848,11 @@ class PluginApi {
* *
* @param {(addCommunitySectionLinkCallback|Object)} arg - A callback function or an Object. * @param {(addCommunitySectionLinkCallback|Object)} arg - A callback function or an Object.
* @param {string} arg.name - The name of the link. Needs to be dasherized and lowercase. * @param {string} arg.name - The name of the link. Needs to be dasherized and lowercase.
* @param {string=} arg.route - The Ember route name to generate the href attribute for the link.
* @param {string=} arg.href - The href attribute for the link.
* @param {string} arg.title - The title attribute for the link. * @param {string} arg.title - The title attribute for the link.
* @param {string} arg.text - The text to display for the link. * @param {string} arg.text - The text to display for the link.
* @param {string} [arg.route] - The Ember route name to generate the href attribute for the link.
* @param {string} [arg.href] - The href attribute for the link.
* @param {string} [arg.icon] - The FontAwesome icon to display for the link.
* @param {Boolean} [secondary] - Determines whether the section link should be added to the main or secondary section in the "More..." links drawer. * @param {Boolean} [secondary] - Determines whether the section link should be added to the main or secondary section in the "More..." links drawer.
*/ */
addCommunitySectionLink(arg, secondary) { addCommunitySectionLink(arg, secondary) {
@@ -1904,7 +1905,7 @@ class PluginApi {
* @param {Object} arg - An object * @param {Object} arg - An object
* @param {string} arg.badgeTextFunction - Function used to generate the text for the badge displayed in the section link. * @param {string} arg.badgeTextFunction - Function used to generate the text for the badge displayed in the section link.
* @param {string} arg.route - The Ember route name to generate the href attribute for the link. * @param {string} arg.route - The Ember route name to generate the href attribute for the link.
* @param {Object=} arg.routeQuery - Object representing the query params that should be appended to the route generated. * @param {Object} [arg.routeQuery] - Object representing the query params that should be appended to the route generated.
* @param {shouldRegister} arg.shouldRegister - Function used to determine if the countable should be registered for the category. * @param {shouldRegister} arg.shouldRegister - Function used to determine if the countable should be registered for the category.
* @param {refreshCountFunction} arg.refreshCountFunction - Function used to calculate the value used to set the property for the count whenever the sidebar section link refreshes. * @param {refreshCountFunction} arg.refreshCountFunction - Function used to calculate the value used to set the property for the count whenever the sidebar section link refreshes.
* @param {prioritizeOverDefaults} args.prioritizeOverDefaults - Function used to determine whether the countable should be prioritized over the default countables of unread/new. * @param {prioritizeOverDefaults} args.prioritizeOverDefaults - Function used to determine whether the countable should be prioritized over the default countables of unread/new.

View File

@@ -13,10 +13,11 @@ export let secondaryCustomSectionLinks = [];
* *
* @param {(addSectionLinkCallback|Object)} args - A callback function or an Object. * @param {(addSectionLinkCallback|Object)} args - A callback function or an Object.
* @param {string} args.name - The name of the link. Needs to be dasherized and lowercase. * @param {string} args.name - The name of the link. Needs to be dasherized and lowercase.
* @param {string=} args.route - The Ember route name to generate the href attribute for the link.
* @param {string=} args.href - The href attribute for the link.
* @param {string=} args.title - The title attribute for the link.
* @param {string} args.text - The text to display for the link. * @param {string} args.text - The text to display for the link.
* @param {string} [args.route] - The Ember route name to generate the href attribute for the link.
* @param {string} [args.href] - The href attribute for the link.
* @param {string} [args.title] - The title attribute for the link.
* @param {string} [args.icon] - The FontAwesome 5 icon to display for the link.
* @param {Boolean} [secondary] - Determines whether the section link should be added to the main or secondary section in the "More..." links drawer. * @param {Boolean} [secondary] - Determines whether the section link should be added to the main or secondary section in the "More..." links drawer.
*/ */
export function addSectionLink(args, secondary) { export function addSectionLink(args, secondary) {
@@ -65,6 +66,10 @@ export function addSectionLink(args, secondary) {
get title() { get title() {
return args.title; return args.title;
} }
get prefixValue() {
return args.icon || super.prefixValue;
}
}; };
links.push(klass); links.push(klass);

View File

@@ -1065,6 +1065,7 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) {
route: "discovery.unread", route: "discovery.unread",
text: "unread topics", text: "unread topics",
title: "List of unread topics", title: "List of unread topics",
icon: "wrench",
}); });
}); });
@@ -1088,6 +1089,13 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) {
"displays the right title for the link" "displays the right title for the link"
); );
assert.ok(
exists(
".sidebar-section-link[data-link-name='unread'] .sidebar-section-link-prefix.icon .d-icon-wrench"
),
"displays the wrench icon for the link"
);
await click(".sidebar-section-link[data-link-name='unread']"); await click(".sidebar-section-link[data-link-name='unread']");
assert.strictEqual(currentURL(), "/unread", "links to the right URL"); assert.strictEqual(currentURL(), "/unread", "links to the right URL");
@@ -1154,6 +1162,13 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) {
"displays the right title for the link" "displays the right title for the link"
); );
assert.ok(
exists(
".sidebar-section-link[data-link-name='user-summary'] .sidebar-section-link-prefix.icon .d-icon-link"
),
"displays the link icon for the link"
);
await click(".btn-sidebar-toggle"); await click(".btn-sidebar-toggle");
assert.ok(teardownCalled, "section link teardown callback was called"); assert.ok(teardownCalled, "section link teardown callback was called");