FIX: Allow sidebar links to register didInsert actions (#19010)
Previously `this.chatService.appEvents.on( "chat:user-tracking-state-changed"...)` was registered on constructor and disabled on `willDestroy`. Constructor is evaluated only once, so when the section was collapsed and collapsed then the events were not observed anymore. didInsert allows evaluating code each time a component is rendered.
This commit is contained in:
parent
895898b363
commit
3d5753c42b
|
@ -1,5 +1,5 @@
|
||||||
{{#if this.shouldDisplay}}
|
{{#if this.shouldDisplay}}
|
||||||
<div class="sidebar-section-link-wrapper">
|
<div class="sidebar-section-link-wrapper" {{did-insert this.didInsert this.args}}>
|
||||||
{{#if @href}}
|
{{#if @href}}
|
||||||
<a href={{@href}} rel="noopener noreferrer" target="_blank" class={{this.classNames}} title={{@title}}>
|
<a href={{@href}} rel="noopener noreferrer" target="_blank" class={{this.classNames}} title={{@title}}>
|
||||||
<Sidebar::SectionLinkPrefix
|
<Sidebar::SectionLinkPrefix
|
||||||
|
|
|
@ -7,6 +7,12 @@ export default class SectionLink extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
didInsert(_element, [args]) {
|
||||||
|
if (args.didInsert) {
|
||||||
|
args.didInsert();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
get shouldDisplay() {
|
get shouldDisplay() {
|
||||||
if (this.args.shouldDisplay === undefined) {
|
if (this.args.shouldDisplay === undefined) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
@hoverAction={{link.hoverAction}}
|
@hoverAction={{link.hoverAction}}
|
||||||
@hoverTitle={{link.hoverTitle}}
|
@hoverTitle={{link.hoverTitle}}
|
||||||
@currentWhen={{link.currentWhen}}
|
@currentWhen={{link.currentWhen}}
|
||||||
|
@didInsert={{link.didInsert}}
|
||||||
@willDestroy={{link.willDestroy}}
|
@willDestroy={{link.willDestroy}}
|
||||||
@content={{link.text}} />
|
@content={{link.text}} />
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
|
@ -19,11 +19,12 @@ acceptance("Sidebar - Plugin API", function (needs) {
|
||||||
});
|
});
|
||||||
|
|
||||||
needs.hooks.afterEach(() => {
|
needs.hooks.afterEach(() => {
|
||||||
|
linkDidInsert = undefined;
|
||||||
linkDestroy = undefined;
|
linkDestroy = undefined;
|
||||||
sectionDestroy = undefined;
|
sectionDestroy = undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
let linkDestroy, sectionDestroy;
|
let linkDidInsert, 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) => {
|
||||||
|
@ -117,6 +118,11 @@ acceptance("Sidebar - Plugin API", function (needs) {
|
||||||
return "unread";
|
return "unread";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@bind
|
||||||
|
didInsert() {
|
||||||
|
linkDidInsert = "link test";
|
||||||
|
}
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
willDestroy() {
|
willDestroy() {
|
||||||
linkDestroy = "link test";
|
linkDestroy = "link test";
|
||||||
|
@ -201,6 +207,12 @@ acceptance("Sidebar - Plugin API", function (needs) {
|
||||||
|
|
||||||
await visit("/");
|
await visit("/");
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
linkDidInsert,
|
||||||
|
"link test",
|
||||||
|
"calls link didInsert function"
|
||||||
|
);
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
query(
|
query(
|
||||||
".sidebar-section-test-chat-channels .sidebar-section-header-text"
|
".sidebar-section-test-chat-channels .sidebar-section-header-text"
|
||||||
|
|
|
@ -34,16 +34,19 @@ export default {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
this.chatService = chatService;
|
this.chatService = chatService;
|
||||||
|
}
|
||||||
|
|
||||||
this.chatService.appEvents.on(
|
@bind
|
||||||
|
willDestroy() {
|
||||||
|
this.chatService.appEvents.off(
|
||||||
"chat:user-tracking-state-changed",
|
"chat:user-tracking-state-changed",
|
||||||
this._refreshTrackingState
|
this._refreshTrackingState
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
willDestroy() {
|
didInsert() {
|
||||||
this.chatService.appEvents.off(
|
this.chatService.appEvents.on(
|
||||||
"chat:user-tracking-state-changed",
|
"chat:user-tracking-state-changed",
|
||||||
this._refreshTrackingState
|
this._refreshTrackingState
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue