mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 08:57:10 -06:00
DEV: Add owner
arg to plugin connector's shouldRender
callbacks (#29488)
This commit is contained in:
parent
ae8d919528
commit
dc96b6e953
@ -1,6 +1,7 @@
|
||||
import { cached } from "@glimmer/tracking";
|
||||
import ClassicComponent from "@ember/component";
|
||||
import { get } from "@ember/object";
|
||||
import { getOwner } from "@ember/owner";
|
||||
import { service } from "@ember/service";
|
||||
import GlimmerComponentWithDeprecatedParentView from "discourse/components/glimmer-component-with-deprecated-parent-view";
|
||||
import {
|
||||
@ -88,7 +89,8 @@ export default class PluginOutletComponent extends GlimmerComponentWithDeprecate
|
||||
const connectors = renderedConnectorsFor(
|
||||
this.args.name,
|
||||
this.outletArgsWithDeprecations,
|
||||
this.context
|
||||
this.context,
|
||||
getOwner(this)
|
||||
);
|
||||
if (connectors.length > 1 && hasBlock) {
|
||||
const message = `Multiple connectors were registered for the ${this.args.name} outlet. Using the first.`;
|
||||
|
@ -224,10 +224,12 @@ export function connectorsFor(outletName) {
|
||||
return _connectorCache[outletName] || [];
|
||||
}
|
||||
|
||||
export function renderedConnectorsFor(outletName, args, context) {
|
||||
export function renderedConnectorsFor(outletName, args, context, owner) {
|
||||
return connectorsFor(outletName).filter((con) => {
|
||||
const shouldRender = con.connectorClass?.shouldRender;
|
||||
return !shouldRender || shouldRender(args, context);
|
||||
return (
|
||||
!con.connectorClass?.shouldRender ||
|
||||
con.connectorClass?.shouldRender(args, context, owner)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -60,8 +60,12 @@ module("Integration | Component | plugin-outlet", function (hooks) {
|
||||
});
|
||||
|
||||
registerTemporaryModule(`${CLASS_PREFIX}/test-name/conditional-render`, {
|
||||
shouldRender(args, context) {
|
||||
return args.shouldDisplay || context.siteSettings.always_display;
|
||||
shouldRender(args, context, owner) {
|
||||
return (
|
||||
args.shouldDisplay ||
|
||||
context.siteSettings.always_display ||
|
||||
owner.lookup("service:site-settings").alternativeAccess
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
@ -407,6 +411,17 @@ module("Integration | Component | plugin-outlet", function (hooks) {
|
||||
assert.dom(".conditional-render").exists("renders conditional outlet");
|
||||
});
|
||||
|
||||
test("shouldRender receives an owner argument", async function (assert) {
|
||||
await render(hbs`<PluginOutlet @name="test-name" />`);
|
||||
assert
|
||||
.dom(".conditional-render")
|
||||
.doesNotExist("doesn't render conditional outlet");
|
||||
|
||||
getOwner(this).lookup("service:site-settings").alternativeAccess = true;
|
||||
await settled();
|
||||
assert.dom(".conditional-render").exists("renders conditional outlet");
|
||||
});
|
||||
|
||||
test("Other outlets are not re-rendered", async function (assert) {
|
||||
this.set("shouldDisplay", false);
|
||||
await render(hbs`
|
||||
|
Loading…
Reference in New Issue
Block a user