A platform for community discussion. Free, open, simple.
UX: Add more info to theme cards (#32334)
Ella E.ffa406b0b1a2
diff --git a/app/assets/javascripts/admin/addon/components/themes-grid-card.gjs b/app/assets/javascripts/admin/addon/components/themes-grid-card.gjsindex 8f43214a541..99f92d63d63 100644--- a/app/assets/javascripts/admin/addon/components/themes-grid-card.gjs+++ b/app/assets/javascripts/admin/addon/components/themes-grid-card.gjs@@ -3,6 +3,7 @@ import { tracked } from "@glimmer/tracking";import { array } from "@ember/helper";import { action } from "@ember/object";import { service } from "@ember/service";+import { dasherize } from "@ember/string";import DButton from "discourse/components/d-button";import DropdownMenu from "discourse/components/dropdown-menu";import icon from "discourse/helpers/d-icon";@@ -29,6 +30,7 @@ export default class ThemeCard extends Component {"theme-card",this.args.theme.get("default") ? "-active" : "",this.isUpdating ? "--updating" : "",+ dasherize(this.args.theme.name),].join(" ");}@@ -40,8 +42,9 @@ export default class ThemeCard extends Component {return `/admin/themes/${this.args.theme.id}/preview`;}- get footerActionIcon() {- return this.args.theme.isPendingUpdates ? "arrows-rotate" : "ellipsis";+ @action+ onRegisterApi(api) {+ this.dMenu = api;}// NOTE: inspired by -> https://github.com/discourse/discourse/blob/24caa36eef826bcdaed88aebfa7df154413fb349/app/assets/javascripts/admin/addon/controllers/admin-customize-themes-show.js#L366@@ -52,6 +55,7 @@ export default class ThemeCard extends Component {let oldDefaultThemeId;this.args.theme.set("default", true);+ this.dMenu.close();this.args.allThemes.forEach((theme) => {if (theme.id !== this.args.theme.id) {if (theme.get("default")) {@@ -81,6 +85,27 @@ export default class ThemeCard extends Component {});}+ @action+ async toggleUserSelectable() {+ let oldUserSelectable = this.args.theme.user_selectable;++ this.args.theme.set("user_selectable", !oldUserSelectable);+ this.dMenu.close();++ const changesSaved = await this.args.theme.saveChanges("user_selectable");+ if (!changesSaved) {+ this.args.theme.set("user_selectable", oldUserSelectable);+ return;+ }++ this.toasts.success({+ data: {+ message: i18n("admin.customize.theme.setting_was_saved"),+ },+ duration: 2000,+ });+ }+@actionupdateTheme() {if (this.isUpdating) {@@ -107,17 +132,17 @@ export default class ThemeCard extends Component {}<template>- <AdminConfigAreaCard- class={{this.themeCardClasses}}- @translatedHeading={{@theme.name}}- >+ <AdminConfigAreaCard class={{this.themeCardClasses}}><:content>- {{#if @theme.isPendingUpdates}}+ {{#if @theme.default}}<span- title={{i18n "admin.customize.theme.updates_available_tooltip"}}- class="theme-card__update-available"- >{{icon "circle-info"}}</span>+ class="theme-card__badge --active"+ title={{i18n "admin.customize.theme.default_theme"}}+ >+ {{i18n "admin.customize.theme.default"}}+ </span>{{/if}}+<div class="theme-card__image-wrapper">{{#if @theme.screenshot_url}}<img@@ -130,81 +155,116 @@ export default class ThemeCard extends Component {{{/if}}</div><div class="theme-card__content">+ <div class="theme-card__title">{{@theme.name}}</div>{{#if @theme.description}}<p class="theme-card__description">{{@theme.description}}</p>{{/if}}</div><div class="theme-card__footer">- <DButton- @translatedLabel={{i18n "admin.customize.theme.edit"}}- @route="adminCustomizeThemes.show"- @routeModels={{this.themeRouteModels}}- class="btn-primary theme-card__button"- @preventFocus={{true}}- />-- <div class="theme-card__footer-actions">- <DMenu- @identifier="theme-card__footer-menu"- @triggerClass="theme-card__footer-menu btn-flat"- @modalForMobile={{true}}- @icon={{this.footerActionIcon}}- @label={{if- this.isUpdating- (i18n "admin.customize.theme.updating")- ""- }}- @triggers={{array "click"}}- >- <:content>- <DropdownMenu as |dropdown|>- {{#if @theme.isPendingUpdates}}+ <div class="theme-card__badges">+ {{#if @theme.isPendingUpdates}}+ <span+ title={{i18n "admin.customize.theme.updates_available_tooltip"}}+ class="theme-card__badge"+ >{{icon "arrows-rotate"}}+ {{i18n "admin.customize.theme.update_available"}}</span>+ {{/if}}++ {{#if @theme.user_selectable}}+ <span+ title={{i18n "admin.customize.theme.user_selectable"}}+ class="theme-card__badge --selectable"+ >{{icon "user-check"}}+ {{i18n+ "admin.customize.theme.user_selectable_badge_label"+ }}</span>+ {{/if}}+ </div>++ <div class="theme-card__controls">+ <DButton+ @translatedLabel={{i18n "admin.customize.theme.edit"}}+ @route="adminCustomizeThemes.show"+ @routeModels={{this.themeRouteModels}}+ class="btn-secondary theme-card__button edit"+ @preventFocus={{true}}+ />++ <div class="theme-card__footer-actions">+ <DMenu+ @identifier="theme-card__footer-menu"+ @triggerClass="theme-card__footer-menu btn-flat"+ @onRegisterApi={{this.onRegisterApi}}+ @modalForMobile={{true}}+ @icon="ellipsis"+ @triggers={{array "click"}}+ >+ <:content>+ <DropdownMenu as |dropdown|>+ {{! TODO: Jordan+ solutions for broken, disabled states }}<dropdown.item><DButton- @action={{this.updateTheme}}- @icon="download"- class="theme-card__button -update"+ @action={{this.setDefault}}@preventFocus={{true}}+ @icon={{if @theme.default "star" "far-star"}}+ class="theme-card__button set-active"@translatedLabel={{i18n- "admin.customize.theme.update_to_latest"+ (if+ @theme.default+ "admin.customize.theme.default_theme"+ "admin.customize.theme.set_default_theme"+ )}}+ @disabled={{@theme.default}}/></dropdown.item>- {{/if}}- {{! TODO: Jordan- solutions for broken, disabled states }}- <dropdown.item>- <DButton- @action={{this.setDefault}}- @preventFocus={{true}}- @icon={{if- @theme.default- "far-square-check"- "far-square"- }}- class="theme-card__button"- @translatedLabel={{i18n- (if- @theme.default- "admin.customize.theme.default_theme"- "admin.customize.theme.set_default_theme"- )- }}- @disabled={{@theme.default}}- />- </dropdown.item>- <dropdown.item>- <a- href={{this.themePreviewUrl}}- title={{i18n "admin.customize.explain_preview"}}- rel="noopener noreferrer"- target="_blank"- class="btn btn-transparent theme-card__button"- >{{icon "eye"}} {{i18n "admin.customize.theme.preview"}}</a>- </dropdown.item>- </DropdownMenu>- </:content>- </DMenu>+ {{#if @theme.isPendingUpdates}}+ <dropdown.item>+ <DButton+ @action={{this.updateTheme}}+ @icon="download"+ class="theme-card__button update"+ @preventFocus={{true}}+ @translatedLabel={{i18n+ "admin.customize.theme.update_to_latest"+ }}+ />+ </dropdown.item>+ {{/if}}+ <dropdown.item>+ <DButton+ @action={{this.toggleUserSelectable}}+ @preventFocus={{true}}+ @icon={{if+ @theme.user_selectable+ "user-xmark"+ "user-check"+ }}+ class="theme-card__button set-selectable"+ @translatedLabel={{i18n+ (if+ @theme.user_selectable+ "admin.customize.theme.user_selectable_unavailable_button_label"+ "admin.customize.theme.user_selectable_button_label"+ )+ }}+ />+ </dropdown.item>+ <dropdown.item>+ <a+ href={{this.themePreviewUrl}}+ title={{i18n "admin.customize.explain_preview"}}+ rel="noopener noreferrer"+ target="_blank"+ class="btn btn-transparent theme-card__button preview"+ >{{icon "eye"}}+ {{i18n "admin.customize.theme.preview"}}</a>+ </dropdown.item>+ </DropdownMenu>+ </:content>+ </DMenu>+ </div></div></div></:content>diff --git a/app/assets/javascripts/admin/addon/components/themes-grid-placeholder.gjs b/app/assets/javascripts/admin/addon/components/themes-grid-placeholder.gjsindex 6404ddb4f11..046661c50e0 100644--- a/app/assets/javascripts/admin/addon/components/themes-grid-placeholder.gjs+++ b/app/assets/javascripts/admin/addon/components/themes-grid-placeholder.gjs@@ -60,7 +60,7 @@ export default class ThemesGridPlaceholder extends Component {preserveAspectRatio="xMidYMid slice"><rect fill={{this.safeThemeColors.tertiary}} width="800" height="200" />- <g transform="translate(280, -100) scale(0.4)">+ <g transform="translate(250, -120) scale(0.45)"><gfill="none"stroke={{this.safeThemeColors.secondary}}diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/admin-nav-map.js b/app/assets/javascripts/discourse/app/lib/sidebar/admin-nav-map.jsindex ddc9508647d..311d565e1a0 100644--- a/app/assets/javascripts/discourse/app/lib/sidebar/admin-nav-map.js+++ b/app/assets/javascripts/discourse/app/lib/sidebar/admin-nav-map.js@@ -284,9 +284,7 @@ export const ADMIN_NAV_MAP = [},{name: "admin_themes_and_components",- route: "adminCustomizeThemes",- routeModels: ["themes"],- currentWhen: "adminCustomizeThemes",+ route: "adminConfig.customize.themes",label: "admin.config.themes_and_components.title",description: "admin.config.themes_and_components.header_description",icon: "paintbrush",diff --git a/app/assets/javascripts/discourse/tests/acceptance/themes-test.js b/app/assets/javascripts/discourse/tests/acceptance/themes-test.jsindex 162bcb58313..6c47911a602 100644--- a/app/assets/javascripts/discourse/tests/acceptance/themes-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/themes-test.js@@ -202,7 +202,7 @@ acceptance("Theme", function (needs) {test("can continue installation", async function (assert) {await visit("/admin/config/customize/themes");- await click(".theme-card .btn-primary");+ await click(".theme-card .btn-secondary");assert.dom(".control-unit .status-message").includesText(diff --git a/app/assets/stylesheets/common/components/theme-card.scss b/app/assets/stylesheets/common/components/theme-card.scssindex 78ffe3e3826..af7039de2d2 100644--- a/app/assets/stylesheets/common/components/theme-card.scss+++ b/app/assets/stylesheets/common/components/theme-card.scss@@ -7,6 +7,7 @@display: grid;grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));gap: 1em;+ align-items: stretch;}.theme-card {@@ -15,6 +16,7 @@position: relative;box-shadow: 0 0 0 3px transparent;transition: box-shadow 0.3s ease-in-out;+ height: 100%;&.--updating {animation:@@ -81,16 +83,6 @@@include theme-card-border(tertiary);}- &__update-available {- position: absolute;- right: -9px;- top: -9px;- color: var(--success);- font-size: var(--font-up-1);- background: var(--secondary);- display: flex;- }-&__icons {display: flex;}@@ -99,6 +91,10 @@width: 100%;height: 160px;overflow: hidden;+ display: flex;+ align-items: center;+ justify-content: center;+ border-bottom: 1px solid var(--primary-low);svg {width: 100%;@@ -125,7 +121,18 @@}&__content {- padding: 10px 0;+ padding: 1rem;+ display: flex;+ flex-direction: column;+ flex-grow: 1;+ }++ &__title {+ font-size: var(--font-up-0);+ font-weight: 700;+ display: flex;+ gap: 0.5rem;+ align-items: center;}&__description {@@ -145,15 +152,65 @@margin-top: auto;}+ &__button.--set-default {+ position: absolute;+ top: 4px;+ right: 4px;+ }+&__footer {margin-top: auto;+ flex-direction: column;+ padding: 1rem;+ gap: 0.75rem;+ }++ &__controls {display: flex;+ justify-content: space-between;+ align-items: center;+ margin-top: 0.5rem;}&__footer-actions {margin-left: auto;}+ &__badges {+ display: flex;+ flex-wrap: wrap;+ gap: 0.5rem;+ align-items: flex-start;+ min-height: 3rem;+ }++ &__badge {+ font-size: var(--font-down-2);+ padding: 0.15rem 0.3rem;+ border-radius: 4px;+ color: var(--primary-very-high);+ background: var(--tertiary-low);+ letter-spacing: 0.25px;+ align-items: center;+ display: inline-flex;+ gap: 0.25rem;++ svg {+ height: 0.75em;+ color: var(--primary-high);+ }++ &.--active {+ background-color: var(--tertiary);+ color: var(--secondary);+ position: absolute;+ right: 8px;+ top: 8px;+ font-size: var(--font-down-3);+ text-transform: uppercase;+ }+ }+.admin-config-area-card__header-action {display: flex;justify-content: center;@@ -180,9 +237,27 @@}}-.theme-card .admin-config-area-card {- &__title {- display: flex;- align-items: center;+.admin-config-area-card.theme-card {+ padding: 0;+ height: 100%;+ display: flex;+ flex-direction: column;++ .admin-config-area-card__content {+ margin: 0;+ padding-right: 0;+ }++ .admin-config-area-card__header-wrapper {+ flex: none;+ }+}++.admin-config-area-card.theme-install-card {+ .theme-install-card__external-links {+ svg {+ font-size: var(--font-down-3);+ margin-bottom: 0.1em;+ }}}diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex e47158236c6..3dd21bba807 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -6516,10 +6516,15 @@ en:extra_files_upload: "Export theme to view these files."extra_files_remote: "Export theme or check the git repository to view these files."preview: "Preview"+ default: "Active"settings_editor: "Settings Editor"show_advanced: "Show advanced"is_default: "Theme is enabled by default"user_selectable: "Theme can be selected by users"+ user_selectable_badge_label: "User selectable"+ user_selectable_button_label: "Allow users to select"+ user_selectable_unavailable_button_label: "Make unavailable to users"+ broken_badge_label: "Broken theme"color_scheme_user_selectable: "Color palette can be selected by users"auto_update: "Auto update when Discourse is updated"color_scheme: "Color Palette"@@ -6537,9 +6542,10 @@ en:convert_theme_alert_generic: "Are you sure you want to convert this theme to component?"convert_theme_tooltip: "Convert this theme to component"inactive_themes: "Inactive themes:"- set_default_theme: "Set default"- default_theme: "Default theme"+ set_default_theme: "Set as active"+ default_theme: "Active theme"set_default_success: "Default theme set to %{theme}"+ setting_was_saved: "Theme setting was saved"install_success: "%{theme} installed successfully!"inactive_components: "Unused components:"selected:@@ -6551,6 +6557,7 @@ en:disabled_component_tooltip: "This component has been disabled"default_theme_tooltip: "This theme is the site's default theme"updates_available_tooltip: "Updates are available for this theme"+ update_available: "Needs update"and_x_more:one: "and %{count} more."other: "and %{count} more."@@ -6612,8 +6619,8 @@ en:error: "This theme has been automatically disabled because it is not compatible with this version of Discourse."minimum: "Requires Discourse version %{version} or above."maximum: "Requires Discourse version %{version} or below."- update_to_latest: "Update to Latest"- check_for_updates: "Check for Updates"+ update_to_latest: "Update to latest"+ check_for_updates: "Check for updates"updating: "Updating…"update_success: "%{theme} Update complete"up_to_date: "Theme is up-to-date, last checked:"diff --git a/docs/ADMIN-QUICK-START-GUIDE.md b/docs/ADMIN-QUICK-START-GUIDE.mdindex f4df912910d..600b91ef39a 100644--- a/docs/ADMIN-QUICK-START-GUIDE.md+++ b/docs/ADMIN-QUICK-START-GUIDE.md@@ -49,4 +49,4 @@ Welcome a few people in - the more, the merrier!* Join the [Discourse community](https://meta.discourse.org/).* Take inspiration from [other Discourse communities](https://discover.discourse.com/).-* Read the [Discourse blog](https://blog.discourse.org/).+* Read the [Discourse blog](https://blog.discourse.org/).\ No newline at end of filediff --git a/lib/svg_sprite.rb b/lib/svg_sprite.rbindex 7b0e948608f..e0e46660680 100644--- a/lib/svg_sprite.rb+++ b/lib/svg_sprite.rb@@ -249,6 +249,7 @@ module SvgSpriteup-right-from-squareuploaduser+ user-checkuser-gearuser-groupuser-pendiff --git a/spec/system/admin_customize_themes_config_area_spec.rb b/spec/system/admin_customize_themes_config_area_spec.rbindex aaaaac7b843..4ee7714dec6 100644--- a/spec/system/admin_customize_themes_config_area_spec.rb+++ b/spec/system/admin_customize_themes_config_area_spec.rb@@ -2,6 +2,8 @@describe "Admin Customize Themes Config Area Page", type: :system dofab!(:admin)+ fab!(:theme) { Theme.where(component: false).first }+ fab!(:theme_2) { Fabricate(:theme, name: "Second theme") }let(:config_area) { PageObjects::Pages::AdminCustomizeThemesConfigArea.new }let(:install_modal) { PageObjects::Modals::InstallTheme.new }@@ -19,4 +21,28 @@ describe "Admin Customize Themes Config Area Page", type: :system doexpect(install_modal).to be_openexpect(install_modal.popular_options.first).to have_text("Air")end++ it "allows to mark theme as active" do+ config_area.visit+ expect(config_area).to have_badge(theme, "--active")+ expect(config_area).to have_no_badge(theme_2, "--active")+ config_area.mark_as_active(theme_2)+ expect(config_area).to have_badge(theme_2, "--active")+ expect(config_area).to have_no_badge(theme, "--active")+ end++ it "allows to make theme selectable by users" do+ config_area.visit+ expect(config_area).to have_no_badge(theme, "--selectable")+ config_area.toggle_selectable(theme)+ expect(config_area).to have_badge(theme, "--selectable")+ config_area.toggle_selectable(theme)+ expect(config_area).to have_no_badge(theme, "--selectable")+ end++ it "allows to edit theme" do+ config_area.visit+ config_area.click_edit(theme)+ expect(page).to have_current_path("/admin/customize/themes/#{theme.id}")+ endenddiff --git a/spec/system/admin_sidebar_navigation_spec.rb b/spec/system/admin_sidebar_navigation_spec.rbindex d0e0f820dff..7f8bde374d0 100644--- a/spec/system/admin_sidebar_navigation_spec.rb+++ b/spec/system/admin_sidebar_navigation_spec.rb@@ -116,7 +116,7 @@ describe "Admin | Sidebar Navigation", type: :system doendit "highlights the 'Themes and components' link when the themes page is visited" do- visit("/admin/customize/themes")+ visit("/admin/config/customize/themes")expect(page).to have_css('.sidebar-section-link-wrapper[data-list-item-name="admin_themes_and_components"] a.active',)diff --git a/spec/system/page_objects/pages/admin_customize_themes_config_area.rb b/spec/system/page_objects/pages/admin_customize_themes_config_area.rbindex 9213bc71767..d7930c99028 100644--- a/spec/system/page_objects/pages/admin_customize_themes_config_area.rb+++ b/spec/system/page_objects/pages/admin_customize_themes_config_area.rb@@ -7,9 +7,39 @@ module PageObjectspage.visit("/admin/config/customize")end+ def find_theme_card(theme)+ find(".theme-card.#{theme.name.parameterize}")+ end+def install_cardfind(".theme-install-card")end++ def open_theme_menu(theme)+ find_theme_card(theme).find(".theme-card__footer-menu-trigger").click+ end++ def mark_as_active(theme)+ open_theme_menu(theme)+ find(".set-active").click+ end++ def has_badge?(theme, badge)+ find_theme_card(theme).has_css?(".theme-card__badge.#{badge}")+ end++ def has_no_badge?(theme, badge)+ find_theme_card(theme).has_no_css?(".theme-card__badge.#{badge}")+ end++ def toggle_selectable(theme)+ open_theme_menu(theme)+ find(".set-selectable").click+ end++ def click_edit(theme)+ find_theme_card(theme).find(".edit").click+ endendendend