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:
parent
a24bcceb19
commit
8dd0f8a712
|
@ -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}$/)) {
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
@hoverAction={{link.hoverAction}}
|
||||
@hoverTitle={{link.hoverTitle}}
|
||||
@currentWhen={{link.currentWhen}}
|
||||
@willDestroy={{link.willDestroy}}
|
||||
@content={{link.text}} />
|
||||
{{/each}}
|
||||
</Sidebar::Section>
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue