A platform for community discussion. Free, open, simple.
DEV: Move `AdminConfigAreaCard` back to the admin bundle (#33429)
Osama Sayegh31d9d5b078ab
diff --git a/app/assets/javascripts/admin/addon/components/admin-config-area-card.gjs b/app/assets/javascripts/admin/addon/components/admin-config-area-card.gjsindex b1a5d134cb6..3bf1f45629b 100644--- a/app/assets/javascripts/admin/addon/components/admin-config-area-card.gjs+++ b/app/assets/javascripts/admin/addon/components/admin-config-area-card.gjs@@ -1,3 +1,94 @@-import AdminConfigAreaCard from "discourse/components/admin-config-area-card";+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { action } from "@ember/object";+import { or } from "truth-helpers";+import DButton from "discourse/components/d-button";+import icon from "discourse/helpers/d-icon";+import { i18n } from "discourse-i18n";-export default AdminConfigAreaCard;+export default class AdminConfigAreaCard extends Component {+ @tracked collapsed = this.args.collapsed;++ get computedHeading() {+ if (this.args.heading) {+ return i18n(this.args.heading);+ }+ return this.args.translatedHeading;+ }++ get hasHeading() {+ return this.args.heading || this.args.translatedHeading;+ }++ get computedDescription() {+ if (this.args.description) {+ return i18n(this.args.description);+ }+ return this.args.translatedDescription;+ }++ get hasDescription() {+ return this.args.description || this.args.translatedDescription;+ }++ get headerCaretIcon() {+ return this.collapsed ? "angle-right" : "angle-down";+ }++ @action+ toggleCardDisplay() {+ this.collapsed = !this.collapsed;+ }++ <template>+ <section class="admin-config-area-card" ...attributes>+ {{#if+ (or+ this.hasHeading+ (has-block "header")+ (has-block "headerAction")+ @collapsable+ )+ }}+ <div class="admin-config-area-card__header-wrapper">+ {{#if this.hasHeading}}+ <h3+ class="admin-config-area-card__title"+ >{{this.computedHeading}}</h3>+ {{else}}+ {{#if (has-block "header")}}+ <h3 class="admin-config-area-card__title">{{yield+ to="header"+ }}</h3>+ {{/if}}+ {{/if}}+ {{#if (has-block "headerAction")}}+ <div class="admin-config-area-card__header-action">+ {{yield to="headerAction"}}+ </div>+ {{/if}}++ {{#if @collapsable}}+ <DButton+ @title="sidebar.toggle_section"+ @action={{this.toggleCardDisplay}}+ class="admin-config-area-card__toggle-button btn-transparent"+ >+ {{icon this.headerCaretIcon}}+ </DButton>+ {{/if}}+ </div>+ {{/if}}+ {{#unless this.collapsed}}+ <div class="admin-config-area-card__content">+ {{#if this.hasDescription}}+ <p class="admin-config-area-card__description">+ {{this.computedDescription}}+ </p>+ {{/if}}+ {{yield to="content"}}+ </div>+ {{/unless}}+ </section>+ </template>+}diff --git a/app/assets/javascripts/admin/addon/components/themes-grid.gjs b/app/assets/javascripts/admin/addon/components/themes-grid.gjsindex 7d52f8ba877..1317016dfd4 100644--- a/app/assets/javascripts/admin/addon/components/themes-grid.gjs+++ b/app/assets/javascripts/admin/addon/components/themes-grid.gjs@@ -1,6 +1,8 @@import Component from "@glimmer/component";import { service } from "@ember/service";-import { getCardsForAdminThemesGrid } from "discourse/lib/admin-custom-themes-grid-cards";+import PluginOutlet from "discourse/components/plugin-outlet";+import lazyHash from "discourse/helpers/lazy-hash";+import AdminConfigAreaCard from "admin/components/admin-config-area-card";import ThemesGridCard from "./themes-grid-card";// NOTE (martin): Much of the JS code in this component is placeholder code. Much@@ -43,9 +45,12 @@ export default class ThemesGrid extends Component {{{#each @themes as |theme|}}<ThemesGridCard @theme={{theme}} @allThemes={{@themes}} />{{/each}}- {{#each (getCardsForAdminThemesGrid) as |Card|}}- <Card />- {{/each}}+ <PluginOutlet+ @name="admin-themes-grid-additional-cards"+ @outletArgs={{lazyHash+ AdminConfigAreaCardComponent=AdminConfigAreaCard+ }}+ /></div></template>}diff --git a/app/assets/javascripts/discourse/app/components/admin-config-area-card.gjs b/app/assets/javascripts/discourse/app/components/admin-config-area-card.gjsdeleted file mode 100644index 3bf1f45629b..00000000000--- a/app/assets/javascripts/discourse/app/components/admin-config-area-card.gjs+++ /dev/null@@ -1,94 +0,0 @@-import Component from "@glimmer/component";-import { tracked } from "@glimmer/tracking";-import { action } from "@ember/object";-import { or } from "truth-helpers";-import DButton from "discourse/components/d-button";-import icon from "discourse/helpers/d-icon";-import { i18n } from "discourse-i18n";--export default class AdminConfigAreaCard extends Component {- @tracked collapsed = this.args.collapsed;-- get computedHeading() {- if (this.args.heading) {- return i18n(this.args.heading);- }- return this.args.translatedHeading;- }-- get hasHeading() {- return this.args.heading || this.args.translatedHeading;- }-- get computedDescription() {- if (this.args.description) {- return i18n(this.args.description);- }- return this.args.translatedDescription;- }-- get hasDescription() {- return this.args.description || this.args.translatedDescription;- }-- get headerCaretIcon() {- return this.collapsed ? "angle-right" : "angle-down";- }-- @action- toggleCardDisplay() {- this.collapsed = !this.collapsed;- }-- <template>- <section class="admin-config-area-card" ...attributes>- {{#if- (or- this.hasHeading- (has-block "header")- (has-block "headerAction")- @collapsable- )- }}- <div class="admin-config-area-card__header-wrapper">- {{#if this.hasHeading}}- <h3- class="admin-config-area-card__title"- >{{this.computedHeading}}</h3>- {{else}}- {{#if (has-block "header")}}- <h3 class="admin-config-area-card__title">{{yield- to="header"- }}</h3>- {{/if}}- {{/if}}- {{#if (has-block "headerAction")}}- <div class="admin-config-area-card__header-action">- {{yield to="headerAction"}}- </div>- {{/if}}-- {{#if @collapsable}}- <DButton- @title="sidebar.toggle_section"- @action={{this.toggleCardDisplay}}- class="admin-config-area-card__toggle-button btn-transparent"- >- {{icon this.headerCaretIcon}}- </DButton>- {{/if}}- </div>- {{/if}}- {{#unless this.collapsed}}- <div class="admin-config-area-card__content">- {{#if this.hasDescription}}- <p class="admin-config-area-card__description">- {{this.computedDescription}}- </p>- {{/if}}- {{yield to="content"}}- </div>- {{/unless}}- </section>- </template>-}diff --git a/app/assets/javascripts/discourse/app/lib/admin-custom-themes-grid-cards.js b/app/assets/javascripts/discourse/app/lib/admin-custom-themes-grid-cards.jsdeleted file mode 100644index ee42b736fdb..00000000000--- a/app/assets/javascripts/discourse/app/lib/admin-custom-themes-grid-cards.js+++ /dev/null@@ -1,15 +0,0 @@-import AdminConfigAreaCard from "discourse/components/admin-config-area-card";--const COMPONENTS_FOR_CUSTOM_CARDS = [];--export function addCardToAdminThemesGrid(func) {- COMPONENTS_FOR_CUSTOM_CARDS.push(func(AdminConfigAreaCard));-}--export function resetCardsForAdminThemesGrid() {- COMPONENTS_FOR_CUSTOM_CARDS.length = 0;-}--export function getCardsForAdminThemesGrid() {- return COMPONENTS_FOR_CUSTOM_CARDS;-}diff --git a/app/assets/javascripts/discourse/app/lib/plugin-api.gjs b/app/assets/javascripts/discourse/app/lib/plugin-api.gjsindex 7abe9e7fb3d..2db3deb595f 100644--- a/app/assets/javascripts/discourse/app/lib/plugin-api.gjs+++ b/app/assets/javascripts/discourse/app/lib/plugin-api.gjs@@ -58,7 +58,6 @@ import {import { addUsernameSelectorDecorator } from "discourse/helpers/decorate-username-selector";import { registerCustomAvatarHelper } from "discourse/helpers/user-avatar";import { addBeforeAuthCompleteCallback } from "discourse/instance-initializers/auth-complete";-import { addCardToAdminThemesGrid } from "discourse/lib/admin-custom-themes-grid-cards";import { registerAdminPluginConfigNav } from "discourse/lib/admin-plugin-config-nav";import { registerPluginHeaderActionComponent } from "discourse/lib/admin-plugin-header-actions";import { registerReportModeComponent } from "discourse/lib/admin-report-additional-modes";@@ -3421,36 +3420,6 @@ class PluginApi {registerRichEditorExtension(extension);}- /**- * Adds a card to the admin themes grid.- *- * ```js- * import Component from "@glimmer/component";- *- * api.addCardToAdminThemesGrid((adminConfigAreaCardComponent) => {- * return <template>- * <adminConfigAreaCardComponent class="my-custom-card">- * <:content>- * <!-- your custom card content goes here -->- * </:content>- * </adminConfigAreaCardComponent>- * </template>;- * });- * ```- *- * @param {Function} func - A function that returns a card component class.- *- * @callback func- * @param {AdminConfigAreaCard} adminConfigAreaCardComponent - The- * `AdminConfigAreaCard` class from core to be optionally used as a container- * for the card content.- * @returns {Component} - A Glimmer component class for the card to be added- * to the grid.- */- addCardToAdminThemesGrid(func) {- addCardToAdminThemesGrid(func);- }-#deprecatedWidgetOverride(widgetName, override) {// insert here the code to handle widget deprecations, e.g. for the header widgets we used:// if (DEPRECATED_HEADER_WIDGETS.includes(widgetName)) {diff --git a/app/assets/javascripts/discourse/tests/acceptance/admin-customize-themes-config-area-test.gjs b/app/assets/javascripts/discourse/tests/acceptance/admin-customize-themes-config-area-test.gjsindex 5d11a11b0f6..7fe687a24dc 100644--- a/app/assets/javascripts/discourse/tests/acceptance/admin-customize-themes-config-area-test.gjs+++ b/app/assets/javascripts/discourse/tests/acceptance/admin-customize-themes-config-area-test.gjs@@ -12,17 +12,18 @@ acceptance("Admin - Config areas - Themes", function (needs) {});});- test("custom cards in themes grid", async function (assert) {+ test("admin-themes-grid-additional-cards plugin outlet", async function (assert) {withPluginApi("0.1", (api) => {- api.addCardToAdminThemesGrid((AdminConfigAreaCardComponent) => {- return <template>- <AdminConfigAreaCardComponent class="my-test-card">+ api.renderInOutlet(+ "admin-themes-grid-additional-cards",+ <template>+ <@AdminConfigAreaCardComponent class="my-test-card"><:content>Hello, this is a test card.</:content>- </AdminConfigAreaCardComponent>- </template>;- });+ </@AdminConfigAreaCardComponent>+ </template>+ );});await visit("/admin/config/customize/themes");diff --git a/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js b/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.jsindex 77236410062..ebcaa91cfd4 100644--- a/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js+++ b/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js@@ -35,7 +35,6 @@ import { resetCustomPostMessageCallbacks } from "discourse/controllers/topic";import { clearHTMLCache } from "discourse/helpers/custom-html";import { resetUsernameDecorators } from "discourse/helpers/decorate-username-selector";import { resetBeforeAuthCompleteCallbacks } from "discourse/instance-initializers/auth-complete";-import { resetCardsForAdminThemesGrid } from "discourse/lib/admin-custom-themes-grid-cards";import { resetAdminPluginConfigNav } from "discourse/lib/admin-plugin-config-nav";import { clearPluginHeaderActionComponents } from "discourse/lib/admin-plugin-header-actions";import { resetAdditionalReportModes } from "discourse/lib/admin-report-additional-modes";@@ -272,7 +271,6 @@ export function testCleanup(container, app) {resetGroupPostSmallActionCodes();resetPostSmallActionClassesCallbacks();resetPostClassesCallback();- resetCardsForAdminThemesGrid();}function cleanupCssGeneratorTags() {