From 117f6d92a8e9454921f873f7045db53dbb4bc598 Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Thu, 20 Jul 2023 11:07:18 +1000 Subject: [PATCH] FEATURE: allow sidebar section api to create external links (#22609) * FEATURE: allow sidebar section api to create external links Right now, sidebar API allows creating sections with internal links. It should be extended to allow creating links to external URLs as well. * FIX: after rebase --- .../app/components/sidebar/api-sections.hbs | 1 + .../base-custom-sidebar-section-link.js | 9 +++-- .../acceptance/sidebar-plugin-api-test.js | 34 +++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/sidebar/api-sections.hbs b/app/assets/javascripts/discourse/app/components/sidebar/api-sections.hbs index 7ad30dda5b6..a431fc454bf 100644 --- a/app/assets/javascripts/discourse/app/components/sidebar/api-sections.hbs +++ b/app/assets/javascripts/discourse/app/components/sidebar/api-sections.hbs @@ -17,6 +17,7 @@ @route={{link.route}} @model={{link.model}} @models={{link.models}} + @href={{link.href}} @title={{link.title}} @contentCSSClass={{link.contentCSSClass}} @prefixColor={{link.prefixColor}} diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/base-custom-sidebar-section-link.js b/app/assets/javascripts/discourse/app/lib/sidebar/base-custom-sidebar-section-link.js index 750c83fcd5d..c693a0ae921 100644 --- a/app/assets/javascripts/discourse/app/lib/sidebar/base-custom-sidebar-section-link.js +++ b/app/assets/javascripts/discourse/app/lib/sidebar/base-custom-sidebar-section-link.js @@ -19,9 +19,12 @@ export default class BaseCustomSidebarSectionLink { /** * @returns {string} The Ember route which the section link should link to. */ - get route() { - this._notImplemented(); - } + get route() {} + + /** + * @returns {string} URL to external website which the section link should link to. + */ + get href() {} /** * @returns {Object} `model` argument for the component. See https://api.emberjs.com/ember/release/classes/Ember.Templates.components/methods/LinkTo?anchor=LinkTo. diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-plugin-api-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-plugin-api-test.js index 848d7a7c872..c8443369ef1 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/sidebar-plugin-api-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-plugin-api-test.js @@ -206,6 +206,28 @@ acceptance("Sidebar - Plugin API", function (needs) { return "hover button title attribute"; } })(), + + new (class extends BaseCustomSidebarSectionLink { + get name() { + return "homepage"; + } + + get classNames() { + return "my-class-name"; + } + + get href() { + return "https://www.discourse.org"; + } + + get title() { + return "Homepage"; + } + + get text() { + return "Homepage"; + } + })(), ]; } }; @@ -349,6 +371,18 @@ acceptance("Sidebar - Plugin API", function (needs) { "uses correct prefix image url" ); + assert.strictEqual( + links[3].title, + "Homepage", + "displays external link with correct title attribute" + ); + + assert.strictEqual( + links[3].href, + "https://www.discourse.org/", + "displays external link with correct href attribute" + ); + assert.strictEqual( query(".sidebar-section-link-hover button").title, "hover button title attribute",