FIX: pass sidebar custom link willDestroy (#17565)

Custom sidebar link willDestroy function has to be passed to SidebarLink component to call when component is removed.

Very similar to https://github.com/discourse/discourse/pull/17551
This commit is contained in:
Krzysztof Kotlarek 2022-07-20 13:44:13 +10:00 committed by GitHub
parent a24bcceb19
commit 8dd0f8a712
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 0 deletions

View File

@ -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}$/)) {

View File

@ -39,6 +39,7 @@
@hoverAction={{link.hoverAction}}
@hoverTitle={{link.hoverTitle}}
@currentWhen={{link.currentWhen}}
@willDestroy={{link.willDestroy}}
@content={{link.text}} />
{{/each}}
</Sidebar::Section>

View File

@ -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) {