Skip to content

A platform for community discussion. Free, open, simple.

FIX: pass sidebar custom link willDestroy (#17565)

Krzysztof Kotlarek8dd0f8a71208
diff --git a/app/assets/javascripts/discourse/app/components/sidebar/section-link.js b/app/assets/javascripts/discourse/app/components/sidebar/section-link.js
index f34d267aa68..1a1b51c6319 100644
--- a/app/assets/javascripts/discourse/app/components/sidebar/section-link.js
+++ b/app/assets/javascripts/discourse/app/components/sidebar/section-link.js
@@ -2,6 +2,12 @@ import GlimmerComponent from "@glimmer/component";
import { htmlSafe } from "@ember/template";
export default class SectionLink extends GlimmerComponent {
+ willDestroy() {
+ if (this.args.willDestroy) {
+ this.args.willDestroy();
+ }
+ }
+
get prefixCSS() {
const color = this.args.prefixColor;
if (!color || !color.match(/^\w{6}$/)) {
diff --git a/app/assets/javascripts/discourse/app/templates/components/sidebar/sections.hbs b/app/assets/javascripts/discourse/app/templates/components/sidebar/sections.hbs
index 18d58292f0b..076e09e6c60 100644
--- a/app/assets/javascripts/discourse/app/templates/components/sidebar/sections.hbs
+++ b/app/assets/javascripts/discourse/app/templates/components/sidebar/sections.hbs
@@ -39,6 +39,7 @@
@hoverAction={{link.hoverAction}}
@hoverTitle={{link.hoverTitle}}
@currentWhen={{link.currentWhen}}
+ @willDestroy={{link.willDestroy}}
@content={{link.text}} />
{{/each}}
</Sidebar::Section>
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 3d42921850a..aab97c2907c 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
@@ -9,13 +9,17 @@ import {
} from "discourse/tests/helpers/qunit-helpers";
import { withPluginApi } from "discourse/lib/plugin-api";
import { resetSidebarSection } from "discourse/lib/sidebar/custom-sections";
+import { bind } from "discourse-common/utils/decorators";
acceptance("Sidebar - section API", function (needs) {
needs.user({ experimental_sidebar_enabled: true });
needs.hooks.afterEach(() => {
resetSidebarSection();
+ linkDestroy = undefined;
+ sectionDestroy = undefined;
});
+ let linkDestroy, sectionDestroy;
test("Multiple header actions and links", async function (assert) {
withPluginApi("1.3.0", (api) => {
@@ -54,6 +58,10 @@ acceptance("Sidebar - section API", function (needs) {
},
];
}
+ @bind
+ willDestroy() {
+ sectionDestroy = "section test";
+ }
get links() {
return [
new (class extends BaseCustomSidebarSectionLink {
@@ -93,6 +101,10 @@ acceptance("Sidebar - section API", function (needs) {
get suffixCSSClass() {
return "unread";
}
+ @bind
+ willDestroy() {
+ linkDestroy = "link test";
+ }
})(),
new (class extends BaseCustomSidebarSectionLink {
get name() {
@@ -275,6 +287,17 @@ acceptance("Sidebar - section API", function (needs) {
"hover button title attribute",
"displays hover button with correct title"
);
+ await click(".header-sidebar-toggle button");
+ assert.strictEqual(
+ linkDestroy,
+ "link test",
+ "calls link willDestroy function"
+ );
+ assert.strictEqual(
+ sectionDestroy,
+ "section test",
+ "calls section willDestroy function"
+ );
});
test("Single header action and no links", async function (assert) {