Skip to content

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

UX: Show the components installed when finishing a theme placeholder

Régis Hanoleededdb04990
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 7d6cc4347f4..5106ea2928f 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -9226,6 +9226,7 @@ en:
force_install: "The theme cannot be installed because the Git repository is inaccessible. Are you sure you want to continue installing it?"
create_placeholder: "Create placeholder"
placeholder_type_tip: "Once the installation is finished, the type from the repository's about.json is used."
+ skipped_components: "%{name} is installed, but these components couldn't be installed. Install them from the Components tab, then add them to this theme:"
about_theme: "About"
license: "License"
version: "Version:"
diff --git a/frontend/discourse/admin/components/modal/change-theme-source.gjs b/frontend/discourse/admin/components/modal/change-theme-source.gjs
index eaab5381ac2..6ff0c8ff0e3 100644
--- a/frontend/discourse/admin/components/modal/change-theme-source.gjs
+++ b/frontend/discourse/admin/components/modal/change-theme-source.gjs
@@ -95,7 +95,7 @@ export default class ChangeThemeSourceModal extends Component {
}
);
- this.args.model.onSuccess?.(result.theme);
+ this.args.model.onSuccess?.(result);
this.args.closeModal();
} catch (err) {
popupAjaxError(err);
diff --git a/frontend/discourse/admin/components/skipped-theme-components.gjs b/frontend/discourse/admin/components/skipped-theme-components.gjs
new file mode 100644
index 00000000000..3a0fff53f23
--- /dev/null
+++ b/frontend/discourse/admin/components/skipped-theme-components.gjs
@@ -0,0 +1,29 @@
+import { i18n } from "discourse-i18n";
+
+const SkippedThemeComponents = <template>
+ <div class="skipped-theme-components">
+ <p>{{i18n "admin.customize.theme.skipped_components" [email protected]}}</p>
+ <ul class="skipped-theme-components__list">
+ {{#each @model.components as |skipped|}}
+ <li class="skipped-theme-components__item">
+ <code>{{skipped.url}}</code>
+ {{skipped.error}}
+ </li>
+ {{/each}}
+ </ul>
+ </div>
+</template>;
+
+export function alertSkippedComponents(dialog, json) {
+ if (!json.skipped_components?.length) {
+ return;
+ }
+
+ dialog.alert({
+ bodyComponent: SkippedThemeComponents,
+ bodyComponentModel: {
+ name: json.theme.name,
+ components: json.skipped_components,
+ },
+ });
+}
diff --git a/frontend/discourse/admin/controllers/admin-customize-themes/show.js b/frontend/discourse/admin/controllers/admin-customize-themes/show.js
index 92a15b27ee5..7093025b32b 100644
--- a/frontend/discourse/admin/controllers/admin-customize-themes/show.js
+++ b/frontend/discourse/admin/controllers/admin-customize-themes/show.js
@@ -1,6 +1,7 @@
import Controller from "@ember/controller";
import { action, computed } from "@ember/object";
import { service } from "@ember/service";
+import { alertSkippedComponents } from "discourse/admin/components/skipped-theme-components";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { removeValueFromArray } from "discourse/lib/array-tools";
import { i18n } from "discourse-i18n";
@@ -73,6 +74,10 @@ export default class AdminCustomizeThemesShowController extends Controller {
this.set("updatingRemote", true);
this.model
.updateToLatest()
+ .then((result) => {
+ this.send("routeRefreshModel");
+ alertSkippedComponents(this.dialog, result.responseJson);
+ })
.catch(popupAjaxError)
.finally(() => {
this.set("updatingRemote", false);
diff --git a/frontend/discourse/admin/controllers/admin-customize-themes/show/index.js b/frontend/discourse/admin/controllers/admin-customize-themes/show/index.js
index 1663f665ec1..f67d180ce79 100644
--- a/frontend/discourse/admin/controllers/admin-customize-themes/show/index.js
+++ b/frontend/discourse/admin/controllers/admin-customize-themes/show/index.js
@@ -3,6 +3,7 @@ import { action, computed } from "@ember/object";
import { service } from "@ember/service";
import { isEmpty } from "@ember/utils";
import ChangeThemeSourceModal from "discourse/admin/components/modal/change-theme-source";
+import { alertSkippedComponents } from "discourse/admin/components/skipped-theme-components";
import ThemeSettingsEditor from "discourse/admin/components/theme-settings-editor";
import SiteSetting from "discourse/admin/models/site-setting";
import { COMPONENTS, THEMES } from "discourse/admin/models/theme";
@@ -246,7 +247,7 @@ export default class AdminCustomizeThemesShowIndexController extends Controller
});
}
- @computed("model.childThemesNames.[]")
+ @computed("model.childThemes.[]")
get relativesSelectorSettingsForTheme() {
return SiteSetting.create({
list_type: "compact",
@@ -431,8 +432,9 @@ export default class AdminCustomizeThemesShowIndexController extends Controller
this.modal.show(ChangeThemeSourceModal, {
model: {
theme: this.model,
- onSuccess: () => {
+ onSuccess: (result) => {
this.send("routeRefreshModel");
+ alertSkippedComponents(this.dialog, result);
},
},
});
diff --git a/frontend/discourse/admin/models/theme.ts b/frontend/discourse/admin/models/theme.ts
index ae6500cb6b9..5c5370c3401 100644
--- a/frontend/discourse/admin/models/theme.ts
+++ b/frontend/discourse/admin/models/theme.ts
@@ -514,9 +514,10 @@ class Theme extends RestModel {
}
updateToLatest() {
- return this.save({ remote_update: true }).then(() =>
- this.set("changed", false)
- );
+ return this.save({ remote_update: true }).then((result) => {
+ this.set("changed", false);
+ return result;
+ });
}
/** Saves the named properties; the implementation intentionally has zero formal parameters. */
diff --git a/frontend/discourse/tests/acceptance/themes-test.js b/frontend/discourse/tests/acceptance/themes-test.js
index 3540984640e..018292ff7d5 100644
--- a/frontend/discourse/tests/acceptance/themes-test.js
+++ b/frontend/discourse/tests/acceptance/themes-test.js
@@ -7,7 +7,7 @@ acceptance("Theme", function (needs) {
needs.user();
needs.pretender((server, helper) => {
- const themes = [
+ let themes = [
{
id: 42,
name: "discourse-incomplete-theme",
@@ -113,55 +113,75 @@ acceptance("Theme", function (needs) {
});
});
+ const childComponent = {
+ id: 43,
+ name: "discourse-child-component",
+ created_at: "2022-01-01T12:00:30.000Z",
+ updated_at: "2022-01-01T12:00:30.000Z",
+ component: true,
+ user_selectable: false,
+ supported: true,
+ enabled: true,
+ child_themes: [],
+ parent_themes: [{ id: 42, name: "discourse-complete-theme" }],
+ };
+
server.put("/admin/themes/42", () => {
- return helper.response(200, {
- theme: {
+ const finished = {
+ id: 42,
+ name: "discourse-complete-theme",
+ created_at: "2022-01-01T12:00:00.000Z",
+ updated_at: "2022-01-01T12:00:00.000Z",
+ component: false,
+ color_scheme: null,
+ color_scheme_id: null,
+ user_selectable: false,
+ auto_update: true,
+ remote_theme_id: 42,
+ settings: [],
+ supported: true,
+ description: null,
+ enabled: true,
+ user: {
+ id: 1,
+ username: "foo",
+ name: null,
+ avatar_template: "/letter_avatar_proxy/v4/letter/f/3be4f8/{size}.png",
+ },
+ theme_fields: [],
+ child_themes: [{ id: 43, name: "discourse-child-component" }],
+ parent_themes: [],
+ remote_theme: {
id: 42,
- name: "discourse-complete-theme",
- created_at: "2022-01-01T12:00:00.000Z",
- updated_at: "2022-01-01T12:00:00.000Z",
- component: false,
- color_scheme: null,
- color_scheme_id: null,
- user_selectable: false,
- auto_update: true,
- remote_theme_id: 42,
- settings: [],
- supported: true,
- description: null,
- enabled: true,
- user: {
- id: 1,
- username: "foo",
- name: null,
- avatar_template:
- "/letter_avatar_proxy/v4/letter/f/3be4f8/{size}.png",
- },
- theme_fields: [],
- child_themes: [],
- parent_themes: [],
- remote_theme: {
- id: 42,
- remote_url:
- "[email protected]:discourse-org/discourse-incomplete-theme.git",
- remote_version: "0000000000000000000000000000000000000000",
- local_version: "0000000000000000000000000000000000000000",
- commits_behind: 0,
- branch: null,
- remote_updated_at: "2022-01-01T12:00:30.000Z",
- updated_at: "2022-01-01T12:00:30.000Z",
- last_error_text: null,
- is_git: true,
- placeholder: false,
- license_url: "URL",
- about_url: "URL",
- authors: null,
- theme_version: null,
- minimum_discourse_version: null,
- maximum_discourse_version: null,
- },
- translations: [],
+ remote_url:
+ "[email protected]:discourse-org/discourse-incomplete-theme.git",
+ remote_version: "0000000000000000000000000000000000000000",
+ local_version: "0000000000000000000000000000000000000000",
+ commits_behind: 0,
+ branch: null,
+ remote_updated_at: "2022-01-01T12:00:30.000Z",
+ updated_at: "2022-01-01T12:00:30.000Z",
+ last_error_text: null,
+ is_git: true,
+ placeholder: false,
+ license_url: "URL",
+ about_url: "URL",
+ authors: null,
+ theme_version: null,
+ minimum_discourse_version: null,
+ maximum_discourse_version: null,
},
+ translations: [],
+ };
+ themes = [finished, childComponent];
+ return helper.response(200, {
+ theme: finished,
+ skipped_components: [
+ {
+ url: "https://github.com/discourse/private-child.git",
+ error: "Error cloning git repository",
+ },
+ ],
});
});
});
@@ -218,5 +238,19 @@ acceptance("Theme", function (needs) {
assert
.dom(".control-unit .btn-primary.finish-install")
.doesNotExist("does not show finish install button");
+
+ assert
+ .dom(".included-components-setting")
+ .includesText(
+ "discourse-child-component",
+ "shows the components installed while finishing"
+ );
+
+ assert
+ .dom(".dialog-body .skipped-theme-components__item")
+ .includesText(
+ "https://github.com/discourse/private-child.git",
+ "lists the components that couldn't be installed"
+ );
});
});