Skip to content

A platform for community discussion. Free, open, simple.

DEV: Port install theme button modal to new themes page (#32834)

Ted Johansson1fcb3a8b33e4
diff --git a/app/assets/javascripts/admin/addon/components/admin-config-areas/themes.gjs b/app/assets/javascripts/admin/addon/components/admin-config-areas/themes.gjs
index 020076e1e8c..1556c6d2d8b 100644
--- a/app/assets/javascripts/admin/addon/components/admin-config-areas/themes.gjs
+++ b/app/assets/javascripts/admin/addon/components/admin-config-areas/themes.gjs
@@ -1,6 +1,8 @@
import Component from "@glimmer/component";
import { action } from "@ember/object";
+import { next } from "@ember/runloop";
import { service } from "@ember/service";
+import { isPresent } from "@ember/utils";
import { i18n } from "discourse-i18n";
import InstallThemeCard from "admin/components/admin-config-area-cards/install-theme-card";
import InstallThemeModal from "admin/components/modal/install-theme";
@@ -12,6 +14,24 @@ export default class AdminConfigAreasThemes extends Component {
@service router;
@service toasts;
+ constructor() {
+ super(...arguments);
+
+ if (isPresent(this.args.repoName) && isPresent(this.args.repoUrl)) {
+ next(() => {
+ this.modal.show(InstallThemeModal, {
+ model: {
+ uploadUrl: this.args.repoUrl,
+ uploadName: this.args.repoName,
+ selection: "directRepoInstall",
+ clearParams: this.clearParams,
+ ...this.installThemeOptions(),
+ },
+ });
+ });
+ }
+ }
+
@action
installModal() {
this.modal.show(InstallThemeModal, {
@@ -27,7 +47,7 @@ export default class AdminConfigAreasThemes extends Component {
return {
selectedType: THEMES,
userId: null,
- content: [],
+ content: this.args.themes,
installedThemes: this.args.themes,
addTheme: this.addTheme,
updateSelectedType: () => {},
@@ -45,9 +65,17 @@ export default class AdminConfigAreasThemes extends Component {
},
duration: "short",
});
+ this.clearParams(theme.component ? "components" : "themes");
this.router.refresh();
}
+ @action
+ clearParams(type) {
+ this.router.transitionTo(`adminConfig.customize.${type ?? "themes"}`, {
+ queryParams: { repoUrl: null, repoName: null },
+ });
+ }
+
<template>
<div class="admin-detail">
<ThemesGrid @themes={{@themes}}>
diff --git a/app/assets/javascripts/admin/addon/routes/admin-config-customize-themes.js b/app/assets/javascripts/admin/addon/routes/admin-config-customize-themes.js
index 70af357842f..5b72a69f008 100644
--- a/app/assets/javascripts/admin/addon/routes/admin-config-customize-themes.js
+++ b/app/assets/javascripts/admin/addon/routes/admin-config-customize-themes.js
@@ -2,15 +2,24 @@ import DiscourseRoute from "discourse/routes/discourse";
import { i18n } from "discourse-i18n";
export default class AdminConfigThemesAndComponentsThemesRoute extends DiscourseRoute {
- async model() {
- return (
- await this.store.findAll("theme", {
- useConfigAreaEndpoint: true,
- })
- ).content;
- }
+ queryParams = {
+ repoUrl: { replace: true },
+ repoName: { replace: true },
+ };
titleToken() {
return i18n("admin.config_areas.themes_and_components.themes.title");
}
+
+ async model(params) {
+ return {
+ themes: (
+ await this.store.findAll("theme", {
+ useConfigAreaEndpoint: true,
+ })
+ ).content,
+ repoUrl: params.repoUrl,
+ repoName: params.repoName,
+ };
+ }
}
diff --git a/app/assets/javascripts/admin/addon/templates/config-customize-themes.gjs b/app/assets/javascripts/admin/addon/templates/config-customize-themes.gjs
index 1a4e41f6a90..547a87e4c7d 100644
--- a/app/assets/javascripts/admin/addon/templates/config-customize-themes.gjs
+++ b/app/assets/javascripts/admin/addon/templates/config-customize-themes.gjs
@@ -10,6 +10,11 @@ export default RouteTemplate(
@label={{i18n "admin.config_areas.themes_and_components.themes.title"}}
/>
- <Themes @themes={{@controller.model}} />
+ <Themes
+ @repoUrl={{@controller.model.repoUrl}}
+ @repoName={{@controller.model.repoName}}
+ @themes={{@controller.model.themes}}
+ @clearParams={{this.clearParams}}
+ />
</template>
);
diff --git a/app/assets/javascripts/discourse/app/instance-initializers/live-development.js b/app/assets/javascripts/discourse/app/instance-initializers/live-development.js
index 186a8a52934..4a0c3424457 100644
--- a/app/assets/javascripts/discourse/app/instance-initializers/live-development.js
+++ b/app/assets/javascripts/discourse/app/instance-initializers/live-development.js
@@ -53,6 +53,9 @@ class LiveDevelopmentInit {
} else if (me === "development-mode-theme-changed") {
if (
window.location.pathname.startsWith("/admin/customize/themes") ||
+ window.location.pathname.startsWith(
+ "/admin/config/customize/themes"
+ ) ||
window.location.pathname.startsWith("/admin/config/look-and-feel")
) {
// Don't refresh users on routes which make theme changes - would be very inconvenient.
diff --git a/spec/system/admin_customize_themes_config_area_spec.rb b/spec/system/admin_customize_themes_config_area_spec.rb
index 886768a4f42..6a8c6e38926 100644
--- a/spec/system/admin_customize_themes_config_area_spec.rb
+++ b/spec/system/admin_customize_themes_config_area_spec.rb
@@ -23,6 +23,19 @@ describe "Admin Customize Themes Config Area Page", type: :system do
expect(install_modal.popular_options.first).to have_text("Air")
end
+ it "opens an install modal when coming from the install theme button on Meta" do
+ config_area.visit(
+ { "repoName" => "discourse-air", "repoUrl" => "https://github.com/discourse/discourse-air" },
+ )
+
+ expect(install_modal).to be_open
+ expect(install_modal).to have_content("github.com/discourse/discourse-air")
+
+ install_modal.close
+
+ expect(page).to have_current_path("/admin/config/customize/themes")
+ end
+
it "allows to mark theme as active" do
config_area.visit
expect(config_area).to have_badge(theme, "--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.rb
index d7930c99028..c21df919c6b 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
@@ -3,8 +3,8 @@
module PageObjects
module Pages
class AdminCustomizeThemesConfigArea < PageObjects::Pages::Base
- def visit
- page.visit("/admin/config/customize")
+ def visit(query_params = {})
+ page.visit("/admin/config/customize?#{query_params.to_query}")
end
def find_theme_card(theme)