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";
|
import { htmlSafe } from "@ember/template";
|
||||||
|
|
||||||
export default class SectionLink extends GlimmerComponent {
|
export default class SectionLink extends GlimmerComponent {
|
||||||
|
willDestroy() {
|
||||||
|
if (this.args.willDestroy) {
|
||||||
|
this.args.willDestroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
get prefixCSS() {
|
get prefixCSS() {
|
||||||
const color = this.args.prefixColor;
|
const color = this.args.prefixColor;
|
||||||
if (!color || !color.match(/^\w{6}$/)) {
|
if (!color || !color.match(/^\w{6}$/)) {
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
@hoverAction={{link.hoverAction}}
|
@hoverAction={{link.hoverAction}}
|
||||||
@hoverTitle={{link.hoverTitle}}
|
@hoverTitle={{link.hoverTitle}}
|
||||||
@currentWhen={{link.currentWhen}}
|
@currentWhen={{link.currentWhen}}
|
||||||
|
@willDestroy={{link.willDestroy}}
|
||||||
@content={{link.text}} />
|
@content={{link.text}} />
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</Sidebar::Section>
|
</Sidebar::Section>
|
||||||
|
|
|
@ -9,13 +9,17 @@ import {
|
||||||
} from "discourse/tests/helpers/qunit-helpers";
|
} from "discourse/tests/helpers/qunit-helpers";
|
||||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||||
import { resetSidebarSection } from "discourse/lib/sidebar/custom-sections";
|
import { resetSidebarSection } from "discourse/lib/sidebar/custom-sections";
|
||||||
|
import { bind } from "discourse-common/utils/decorators";
|
||||||
|
|
||||||
acceptance("Sidebar - section API", function (needs) {
|
acceptance("Sidebar - section API", function (needs) {
|
||||||
needs.user({ experimental_sidebar_enabled: true });
|
needs.user({ experimental_sidebar_enabled: true });
|
||||||
|
|
||||||
needs.hooks.afterEach(() => {
|
needs.hooks.afterEach(() => {
|
||||||
resetSidebarSection();
|
resetSidebarSection();
|
||||||
|
linkDestroy = undefined;
|
||||||
|
sectionDestroy = undefined;
|
||||||
});
|
});
|
||||||
|
let linkDestroy, sectionDestroy;
|
||||||
|
|
||||||
test("Multiple header actions and links", async function (assert) {
|
test("Multiple header actions and links", async function (assert) {
|
||||||
withPluginApi("1.3.0", (api) => {
|
withPluginApi("1.3.0", (api) => {
|
||||||
|
@ -54,6 +58,10 @@ acceptance("Sidebar - section API", function (needs) {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@bind
|
||||||
|
willDestroy() {
|
||||||
|
sectionDestroy = "section test";
|
||||||
|
}
|
||||||
get links() {
|
get links() {
|
||||||
return [
|
return [
|
||||||
new (class extends BaseCustomSidebarSectionLink {
|
new (class extends BaseCustomSidebarSectionLink {
|
||||||
|
@ -93,6 +101,10 @@ acceptance("Sidebar - section API", function (needs) {
|
||||||
get suffixCSSClass() {
|
get suffixCSSClass() {
|
||||||
return "unread";
|
return "unread";
|
||||||
}
|
}
|
||||||
|
@bind
|
||||||
|
willDestroy() {
|
||||||
|
linkDestroy = "link test";
|
||||||
|
}
|
||||||
})(),
|
})(),
|
||||||
new (class extends BaseCustomSidebarSectionLink {
|
new (class extends BaseCustomSidebarSectionLink {
|
||||||
get name() {
|
get name() {
|
||||||
|
@ -275,6 +287,17 @@ acceptance("Sidebar - section API", function (needs) {
|
||||||
"hover button title attribute",
|
"hover button title attribute",
|
||||||
"displays hover button with correct title"
|
"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) {
|
test("Single header action and no links", async function (assert) {
|
||||||
|
|
Loading…
Reference in New Issue