A platform for community discussion. Free, open, simple.
DEV: Drop PluginOutlet `parentView` and DButton string actions (#31624)
David Taylor2041eaf89dbf
diff --git a/app/assets/javascripts/discourse/app/components/d-button.gjs b/app/assets/javascripts/discourse/app/components/d-button.gjsindex 6a895635fcc..a4140f58155 100644--- a/app/assets/javascripts/discourse/app/components/d-button.gjs+++ b/app/assets/javascripts/discourse/app/components/d-button.gjs@@ -1,3 +1,4 @@+import Component from "@glimmer/component";import { on } from "@ember/modifier";import { action } from "@ember/object";import { empty, equal, notEmpty } from "@ember/object/computed";@@ -5,19 +6,12 @@ import { next } from "@ember/runloop";import { service } from "@ember/service";import { htmlSafe } from "@ember/template";import { or } from "truth-helpers";-import GlimmerComponentWithDeprecatedParentView from "discourse/components/glimmer-component-with-deprecated-parent-view";import concatClass from "discourse/helpers/concat-class";import icon from "discourse/helpers/d-icon";import element from "discourse/helpers/element";-import deprecated from "discourse/lib/deprecated";import { i18n } from "discourse-i18n";-const ACTION_AS_STRING_DEPRECATION_ARGS = [- "DButton no longer supports @action as a string. Please refactor to use an closure action instead.",- { id: "discourse.d-button-action-string" },-];--export default class DButton extends GlimmerComponentWithDeprecatedParentView {+export default class DButton extends Component {@service router;@service capabilities;@@ -27,13 +21,6 @@ export default class DButton extends GlimmerComponentWithDeprecatedParentView {@empty("computedLabel") noText;- constructor() {- super(...arguments);- if (typeof this.args.action === "string") {- deprecated(...ACTION_AS_STRING_DEPRECATION_ARGS);- }- }-get forceDisabled() {return !!this.args.isLoading;}@@ -121,16 +108,7 @@ export default class DButton extends GlimmerComponentWithDeprecatedParentView {if (actionVal) {const { actionParam, forwardEvent } = this.args;- if (typeof actionVal === "string") {- deprecated(...ACTION_AS_STRING_DEPRECATION_ARGS);- if (this._target?.send) {- this._target.send(actionVal, actionParam);- } else {- throw new Error(- "DButton could not find a target for the action. Use a closure action instead"- );- }- } else if (typeof actionVal === "object" && actionVal.value) {+ if (typeof actionVal === "object" && actionVal.value) {if (isIOS) {// Don't optimise INP in iOS// it results in focus events not being triggereddiff --git a/app/assets/javascripts/discourse/app/components/glimmer-component-with-deprecated-parent-view.gjs b/app/assets/javascripts/discourse/app/components/glimmer-component-with-deprecated-parent-view.gjsdeleted file mode 100644index 2935b34afe0..00000000000--- a/app/assets/javascripts/discourse/app/components/glimmer-component-with-deprecated-parent-view.gjs+++ /dev/null@@ -1,47 +0,0 @@-import Component from "@glimmer/component";-import EmberGlimmerComponentManager from "@glimmer/component/-private/ember-component-manager";-import {- CustomComponentManager,- setInternalComponentManager,-} from "@glimmer/manager";-import { valueForRef } from "@glimmer/reference";--class GlimmerComponentWithParentViewManager extends CustomComponentManager {- create(- owner,- componentClass,- args,- environment,- dynamicScope,- callerSelfRef- ) {- const result = super.create(...arguments);-- result.component.parentView = dynamicScope.view;- dynamicScope.view = result.component;-- result.component._target = valueForRef(callerSelfRef);-- return result;- }-- getCapabilities() {- return { ...super.getCapabilities(), createCaller: true };- }-}--/**- * This component has a lightly-extended version of Ember's default Glimmer component manager.- * It gives Glimmer components the ability to reference their parent view which can be useful- * when building backwards-compatible versions of components. Any use of the parentView property- * of the component should be considered deprecated.- */-// eslint-disable-next-line ember/no-empty-glimmer-component-classes-export default class GlimmerComponentWithDeprecatedParentView extends Component {}--setInternalComponentManager(- new GlimmerComponentWithParentViewManager(- (owner) => new EmberGlimmerComponentManager(owner)- ),- GlimmerComponentWithDeprecatedParentView-);diff --git a/app/assets/javascripts/discourse/app/components/plugin-outlet.js b/app/assets/javascripts/discourse/app/components/plugin-outlet.jsindex a00125960c9..29255f617b7 100644--- a/app/assets/javascripts/discourse/app/components/plugin-outlet.js+++ b/app/assets/javascripts/discourse/app/components/plugin-outlet.js@@ -1,9 +1,9 @@+import Component from "@glimmer/component";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 { bind } from "discourse/lib/decorators";import deprecated from "discourse/lib/deprecated";import { helperContext } from "discourse/lib/helpers";@@ -13,8 +13,6 @@ import {renderedConnectorsFor,} from "discourse/lib/plugin-connectors";-const PARENT_VIEW_DEPRECATION_MSG =- "parentView should not be used within plugin outlets. Use the available outlet arguments, or inject a service which can provide the context you need.";const GET_DEPRECATION_MSG ="Plugin outlet context is no longer an EmberObject - using `get()` is deprecated.";const TAG_NAME_DEPRECATION_MSG =@@ -49,13 +47,10 @@ const ARGS_DEPRECATION_MSG =**/-export default class PluginOutletComponent extends GlimmerComponentWithDeprecatedParentView {+export default class PluginOutletComponent extends Component {@service clientErrorHandler;context = {...helperContext(),- get parentView() {- return this.parentView;- },get() {deprecated(GET_DEPRECATION_MSG, {id: "discourse.plugin-outlet-context-get",@@ -64,8 +59,6 @@ export default class PluginOutletComponent extends GlimmerComponentWithDeprecate},};- #parentView;-constructor() {const result = super(...arguments);@@ -135,45 +128,10 @@ export default class PluginOutletComponent extends GlimmerComponentWithDeprecate);}- get parentView() {- deprecated(`${PARENT_VIEW_DEPRECATION_MSG} (outlet: ${this.args.name})`, {- id: "discourse.plugin-outlet-parent-view",- });- return this.#parentView;- }-- set parentView(value) {- this.#parentView = value;- }-- get _parentView() {- return this.parentView;- }-// Older plugin outlets have a `tagName` which we need to preserve for backwards-compatibilityget wrapperComponent() {return PluginOutletWithTagNameWrapper;}}-class PluginOutletWithTagNameWrapper extends ClassicComponent {- #parentView;-- // Overridden parentView to make this wrapper 'transparent'- // Calling this will trigger the deprecation notice in PluginOutletComponent- get parentView() {- // init() of CoreView calls `this.parentView`. That would trigger the deprecation notice,- // so skip it until this component is initialized.- if (this._state) {- return this.#parentView.parentView;- }- }-- set parentView(value) {- this.#parentView = value;- }-- get _parentView() {- return this.parentView;- }-}+class PluginOutletWithTagNameWrapper extends ClassicComponent {}diff --git a/app/assets/javascripts/discourse/app/services/deprecation-warning-handler.js b/app/assets/javascripts/discourse/app/services/deprecation-warning-handler.jsindex 228d9073ab4..f78b12520d6 100644--- a/app/assets/javascripts/discourse/app/services/deprecation-warning-handler.js+++ b/app/assets/javascripts/discourse/app/services/deprecation-warning-handler.js@@ -18,8 +18,6 @@ export const CRITICAL_DEPRECATIONS = ["discourse.add-header-panel","discourse.header-widget-overrides","discourse.plugin-outlet-tag-name",- "discourse.plugin-outlet-parent-view",- "discourse.d-button-action-string","discourse.post-menu-widget-overrides","discourse.fontawesome-6-upgrade","discourse.add-flag-property",diff --git a/app/assets/javascripts/discourse/tests/acceptance/plugin-outlet-parent-view-test.js b/app/assets/javascripts/discourse/tests/acceptance/plugin-outlet-parent-view-test.jsdeleted file mode 100644index 49b935cbd6e..00000000000--- a/app/assets/javascripts/discourse/tests/acceptance/plugin-outlet-parent-view-test.js+++ /dev/null@@ -1,36 +0,0 @@-import Component from "@ember/component";-import { render } from "@ember/test-helpers";-import { hbs } from "ember-cli-htmlbars";-import { setupRenderingTest } from "ember-qunit";-import { module, test } from "qunit";-import { withSilencedDeprecationsAsync } from "discourse/lib/deprecated";-import { registerTemporaryModule } from "discourse/tests/helpers/temporary-module-helper";--module("Plugin Outlet - Deprecated parentView", function (hooks) {- setupRenderingTest(hooks);-- test("Can access parentView", async function (assert) {- this.component = class AComponent extends Component {- layout = hbs`<PluginOutlet @name="an-outlet" @connectorTagName="div" />`;- };-- registerTemporaryModule(- "discourse/templates/connectors/an-outlet/hello",- hbs`<span class="hello-username">{{this.parentView.parentView.constructor.name}}</span>`- );-- await withSilencedDeprecationsAsync(- "discourse.plugin-outlet-parent-view",- async () => {- await render(hbs`<this.component />`);-- assert- .dom(".hello-username")- .hasText(- "AComponent",- "it renders a value from parentView.parentView"- );- }- );- });-});diff --git a/app/assets/javascripts/discourse/tests/integration/components/d-button-test.js b/app/assets/javascripts/discourse/tests/integration/components/d-button-test.jsindex 0613bb3a87c..e99180aac05 100644--- a/app/assets/javascripts/discourse/tests/integration/components/d-button-test.js+++ b/app/assets/javascripts/discourse/tests/integration/components/d-button-test.js@@ -1,8 +1,6 @@-import ClassicComponent from "@ember/component";import { click, render, triggerKeyEvent } from "@ember/test-helpers";import { hbs } from "ember-cli-htmlbars";import { module, test } from "qunit";-import { withSilencedDeprecationsAsync } from "discourse/lib/deprecated";import { setupRenderingTest } from "discourse/tests/helpers/component-test";import I18n, { i18n } from "discourse-i18n";@@ -228,62 +226,6 @@ module("Integration | Component | d-button", function (hooks) {assert.strictEqual(this.foo, "bar");});- test("@action can sendAction when passed a string", async function (assert) {- this.set("foo", null);- this.set("legacyActionTriggered", () => this.set("foo", "bar"));-- this.classicComponent = class extends ClassicComponent {- actions = {- myLegacyAction() {- this.legacyActionTriggered();- },- };- layout = hbs`<DButton @action="myLegacyAction" />`;- };-- await withSilencedDeprecationsAsync(- "discourse.d-button-action-string",- async () => {- await render(- hbs`<this.classicComponent @legacyActionTriggered={{this.legacyActionTriggered}} />`- );-- await click(".btn");- }- );-- assert.strictEqual(this.foo, "bar");- });-- test("Uses correct target with @action string when component called with block", async function (assert) {- this.set("foo", null);- this.set("legacyActionTriggered", () => this.set("foo", "bar"));-- this.simpleWrapperComponent = class extends ClassicComponent {};-- this.classicComponent = class extends ClassicComponent {- actions = {- myLegacyAction() {- this.legacyActionTriggered();- },- };- layout = hbs`<@simpleWrapperComponent><DButton @action="myLegacyAction" /></@simpleWrapperComponent>`;- };-- await withSilencedDeprecationsAsync(- "discourse.d-button-action-string",- async () => {- await render(- hbs`<this.classicComponent @legacyActionTriggered={{this.legacyActionTriggered}} @simpleWrapperComponent={{this.simpleWrapperComponent}} />`- );-- await click(".btn");- }- );-- assert.strictEqual(this.foo, "bar");- });-test("ellipses", async function (assert) {await render(hbs`<DButton @translatedLabel="test label" @ellipsis={{true}} />`