From 0410c07342a14c693472e782572cb81a83cc1c72 Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Tue, 17 Dec 2024 11:47:23 +1100 Subject: [PATCH] UX: the ability to collapse AdminConfigAreaCard (#30310) Additional `collapsable` argument which makes area cards collapsible. --- .../components/admin-config-area-card.gjs | 38 +++++++++++--- .../components/admin-config-areas/about.gjs | 3 ++ .../admin-config-area-card-test.gjs | 52 +++++++++++++++++++ .../common/admin/admin_config_area.scss | 9 ++-- 4 files changed, 92 insertions(+), 10 deletions(-) create mode 100644 app/assets/javascripts/discourse/tests/integration/components/admin-config-area-card-test.gjs 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.gjs index abe34fb4bca..85b5541f654 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,5 +1,8 @@ import Component from "@glimmer/component"; import { tracked } from "@glimmer/tracking"; +import { action } from "@ember/object"; +import DButton from "discourse/components/d-button"; +import icon from "discourse-common/helpers/d-icon"; import { i18n } from "discourse-i18n"; export default class AdminConfigAreaCard extends Component { @@ -27,6 +30,15 @@ export default class AdminConfigAreaCard extends Component { return this.args.description || this.args.translatedDescription; } + get headerCaretIcon() { + return this.collapsed ? "angle-right" : "angle-down"; + } + + @action + toggleCardDisplay() { + this.collapsed = !this.collapsed; + } + } diff --git a/app/assets/javascripts/admin/addon/components/admin-config-areas/about.gjs b/app/assets/javascripts/admin/addon/components/admin-config-areas/about.gjs index 5c724b2c6b6..02be84f8da1 100644 --- a/app/assets/javascripts/admin/addon/components/admin-config-areas/about.gjs +++ b/app/assets/javascripts/admin/addon/components/admin-config-areas/about.gjs @@ -53,6 +53,7 @@ export default class AdminConfigAreasAbout extends Component {
<:content> @@ -65,6 +66,7 @@ export default class AdminConfigAreasAbout extends Component { <:content> @@ -78,6 +80,7 @@ export default class AdminConfigAreasAbout extends Component { <:content> diff --git a/app/assets/javascripts/discourse/tests/integration/components/admin-config-area-card-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/admin-config-area-card-test.gjs new file mode 100644 index 00000000000..408d7862fab --- /dev/null +++ b/app/assets/javascripts/discourse/tests/integration/components/admin-config-area-card-test.gjs @@ -0,0 +1,52 @@ +import { click, render } from "@ember/test-helpers"; +import { module, test } from "qunit"; +import { setupRenderingTest } from "discourse/tests/helpers/component-test"; +import AdminConfigAreaCard from "admin/components/admin-config-area-card"; + +module("Integration | Component | AdminConfigAreaCard", function (hooks) { + hooks.beforeEach(function () {}); + setupRenderingTest(hooks); + + test("renders admin config area card without toggle button", async function (assert) { + await render(); + + assert.dom(".admin-config-area-card__title").exists(); + assert.dom(".admin-config-area-card__content").exists(); + assert.dom(".admin-config-area-card__toggle-button").doesNotExist(); + }); + + test("renders admin config area card with toggle button", async function (assert) { + await render(); + + assert.dom(".admin-config-area-card__title").exists(); + assert.dom(".admin-config-area-card__content").exists(); + assert.dom(".admin-config-area-card__toggle-button").exists(); + + await click(".admin-config-area-card__toggle-button"); + assert.dom(".admin-config-area-card__content").doesNotExist(); + + await click(".admin-config-area-card__toggle-button"); + assert.dom(".admin-config-area-card__content").exists(); + }); + + test("renders admin config area card with header action", async function (assert) { + await render(); + + assert.dom(".admin-config-area-card__header-action button").exists(); + }); +}); diff --git a/app/assets/stylesheets/common/admin/admin_config_area.scss b/app/assets/stylesheets/common/admin/admin_config_area.scss index 94424363b7f..674c64be9c3 100644 --- a/app/assets/stylesheets/common/admin/admin_config_area.scss +++ b/app/assets/stylesheets/common/admin/admin_config_area.scss @@ -4,7 +4,7 @@ } } .admin-config-area-card { - padding: 20px; + padding: 20px 5px 20px 20px; border: 1px solid var(--primary-low); border-radius: 2px; background-color: var(--secondary); @@ -43,9 +43,12 @@ &__header-wrapper { display: flex; - align-items: baseline; + align-items: center; flex: 1; - margin-bottom: 0.5rem; + } + &__content { + margin-top: 0.5rem; + padding-right: 15px; } }