Skip to content

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

DEV: remove old themes/components code (#32875)

Krzysztof Kotlarekc4ff6bd40e70
diff --git a/app/assets/javascripts/admin/addon/components/themes-list.gjs b/app/assets/javascripts/admin/addon/components/themes-list.gjs
deleted file mode 100644
index 33fed56b321..00000000000
--- a/app/assets/javascripts/admin/addon/components/themes-list.gjs
+++ /dev/null
@@ -1,418 +0,0 @@
-import Component, { Input } from "@ember/component";
-import { fn } from "@ember/helper";
-import { on } from "@ember/modifier";
-import { action } from "@ember/object";
-import { equal, gt, gte } from "@ember/object/computed";
-import { service } from "@ember/service";
-import { classNames } from "@ember-decorators/component";
-import { and, eq, not, or } from "truth-helpers";
-import DButton from "discourse/components/d-button";
-import DeleteThemesConfirm from "discourse/components/modal/delete-themes-confirm";
-import concatClass from "discourse/helpers/concat-class";
-import icon from "discourse/helpers/d-icon";
-import discourseComputed, { bind } from "discourse/lib/decorators";
-import { i18n } from "discourse-i18n";
-import ThemesListItem from "admin/components/themes-list-item";
-import { COMPONENTS, THEMES } from "admin/models/theme";
-import ComboBox from "select-kit/components/combo-box";
-
-const ALL_FILTER = "all";
-const ACTIVE_FILTER = "active";
-const INACTIVE_FILTER = "inactive";
-const ENABLED_FILTER = "enabled";
-const DISABLED_FILTER = "disabled";
-const UPDATES_AVAILABLE_FILTER = "updates_available";
-
-const THEMES_FILTERS = [
- { name: i18n("admin.customize.theme.all_filter"), id: ALL_FILTER },
- { name: i18n("admin.customize.theme.active_filter"), id: ACTIVE_FILTER },
- {
- name: i18n("admin.customize.theme.inactive_filter"),
- id: INACTIVE_FILTER,
- },
- {
- name: i18n("admin.customize.theme.updates_available_filter"),
- id: UPDATES_AVAILABLE_FILTER,
- },
-];
-const COMPONENTS_FILTERS = [
- { name: i18n("admin.customize.component.all_filter"), id: ALL_FILTER },
- {
- name: i18n("admin.customize.component.used_filter"),
- id: ACTIVE_FILTER,
- },
- {
- name: i18n("admin.customize.component.unused_filter"),
- id: INACTIVE_FILTER,
- },
- {
- name: i18n("admin.customize.component.enabled_filter"),
- id: ENABLED_FILTER,
- },
- {
- name: i18n("admin.customize.component.disabled_filter"),
- id: DISABLED_FILTER,
- },
- {
- name: i18n("admin.customize.component.updates_available_filter"),
- id: UPDATES_AVAILABLE_FILTER,
- },
-];
-
-@classNames("themes-list")
-export default class ThemesList extends Component {
- @service router;
- @service modal;
-
- THEMES = THEMES;
- COMPONENTS = COMPONENTS;
- searchTerm = null;
- filter = ALL_FILTER;
- selectInactiveMode = false;
-
- @gt("themesList.length", 0) hasThemes;
-
- @gt("activeThemes.length", 0) hasActiveThemes;
-
- @gt("inactiveThemes.length", 0) hasInactiveThemes;
-
- @gte("themesList.length", 10) showSearchAndFilter;
-
- @equal("currentTab", THEMES) themesTabActive;
-
- @equal("currentTab", COMPONENTS) componentsTabActive;
-
- @equal("filter", ACTIVE_FILTER) activeFilter;
- @equal("filter", INACTIVE_FILTER) inactiveFilter;
-
- willRender() {
- super.willRender(...arguments);
- if (!this.showSearchAndFilter) {
- this.set("searchTerm", null);
- }
- }
-
- @discourseComputed("themes", "components", "currentTab")
- themesList(themes, components) {
- if (this.themesTabActive) {
- return themes;
- } else {
- return components;
- }
- }
-
- @discourseComputed("currentTab")
- selectableFilters() {
- if (this.themesTabActive) {
- return THEMES_FILTERS;
- } else {
- return COMPONENTS_FILTERS;
- }
- }
-
- @discourseComputed(
- "themesList",
- "currentTab",
- "[email protected]_selectable",
- "searchTerm",
- "filter"
- )
- inactiveThemes(themes) {
- let results;
- if (this.componentsTabActive) {
- results = themes.filter(
- (theme) => theme.get("parent_themes.length") <= 0
- );
- } else {
- results = themes.filter(
- (theme) => !theme.get("user_selectable") && !theme.get("default")
- );
- }
- results = this._applyFilter(results);
- return this._searchThemes(results, this.searchTerm);
- }
-
- @discourseComputed("[email protected]")
- selectedThemesOrComponents() {
- return this.themesList.filter((theme) => theme.markedToDelete);
- }
-
- @discourseComputed("[email protected]")
- selectedCount() {
- return this.selectedThemesOrComponents.length;
- }
-
- @discourseComputed(
- "themesList",
- "currentTab",
- "[email protected]_selectable",
- "searchTerm",
- "filter"
- )
- activeThemes(themes) {
- let results;
- if (this.componentsTabActive) {
- results = themes.filter((theme) => theme.get("parent_themes.length") > 0);
- } else {
- results = themes
- .filter((theme) => theme.get("user_selectable") || theme.get("default"))
- .sort((a, b) => {
- if (a.get("default") && !b.get("default")) {
- return -1;
- } else if (b.get("default")) {
- return 1;
- }
- return a
- .get("name")
- .toLowerCase()
- .localeCompare(b.get("name").toLowerCase());
- });
- }
- results = this._applyFilter(results);
- return this._searchThemes(results, this.searchTerm);
- }
-
- @discourseComputed("[email protected]")
- someInactiveSelected() {
- return (
- this.selectedCount > 0 &&
- this.selectedCount !== this.inactiveThemes.length
- );
- }
-
- @discourseComputed("[email protected]")
- allInactiveSelected() {
- return this.selectedCount === this.inactiveThemes.length;
- }
-
- _searchThemes(themes, term) {
- term = term?.trim()?.toLowerCase();
- if (!term) {
- return themes;
- }
- return themes.filter(({ name }) => name.toLowerCase().includes(term));
- }
-
- _applyFilter(results) {
- switch (this.filter) {
- case UPDATES_AVAILABLE_FILTER: {
- return results.filterBy("isPendingUpdates");
- }
- case ENABLED_FILTER: {
- return results.filterBy("enabled");
- }
- case DISABLED_FILTER: {
- return results.filterBy("enabled", false);
- }
- default: {
- return results;
- }
- }
- }
-
- @bind
- toggleInactiveMode(event) {
- event?.preventDefault();
- this.inactiveThemes.forEach((theme) => theme.set("markedToDelete", false));
- this.toggleProperty("selectInactiveMode");
- }
-
- @action
- changeView(newTab) {
- if (newTab !== this.currentTab) {
- this.set("selectInactiveMode", false);
- this.set("filter", ALL_FILTER);
- this.router.transitionTo("adminCustomizeThemes", newTab);
- }
- }
-
- @action
- navigateToTheme(theme) {
- this.router.transitionTo("adminCustomizeThemes.show", theme);
- }
-
- @action
- toggleAllInactive() {
- const markedToDelete = this.selectedCount === 0;
- this.inactiveThemes.forEach((theme) =>
- theme.set("markedToDelete", markedToDelete)
- );
- }
-
- @action
- deleteConfirmation() {
- this.modal.show(DeleteThemesConfirm, {
- model: {
- selectedThemesOrComponents: this.selectedThemesOrComponents,
- type: this.themesTabActive ? "themes" : "components",
- refreshAfterDelete: () => {
- this.set("selectInactiveMode", false);
- if (this.themesTabActive) {
- this.set(
- "themes",
- this.themes.filter(
- (theme) => !this.selectedThemesOrComponents.includes(theme)
- )
- );
- } else {
- this.set(
- "components",
- this.components.filter(
- (component) =>
- !this.selectedThemesOrComponents.includes(component)
- )
- );
- }
- },
- },
- });
- }
-
- <template>
- <div class="themes-list-header">
- <DButton
- @action={{fn this.changeView this.THEMES}}
- @label="admin.customize.theme.title"
- class={{concatClass
- "themes-tab"
- "tab"
- (if this.themesTabActive "active")
- }}
- />
- <DButton
- @action={{fn this.changeView this.COMPONENTS}}
- @label="admin.customize.theme.components"
- @icon="puzzle-piece"
- class={{concatClass
- "components-tab"
- "tab"
- (if this.componentsTabActive "active")
- }}
- />
- </div>
-
- {{#if this.showSearchAndFilter}}
- <div class="themes-list-search">
- <Input
- class="themes-list-search__input"
- placeholder={{i18n "admin.customize.theme.search_placeholder"}}
- autocomplete="off"
- @type="search"
- @value={{mut this.searchTerm}}
- />
- {{icon "magnifying-glass"}}
- </div>
- <div class="themes-list-filter">
- <div class="themes-list-filter__label">
- {{i18n "admin.customize.theme.filter_by"}}
- </div>
- <ComboBox
- @content={{this.selectableFilters}}
- @value={{this.filter}}
- class="themes-list-filter__input"
- />
- </div>
- {{/if}}
- <div class="themes-list-container">
- {{#if this.hasThemes}}
- {{#if (and this.hasActiveThemes (not this.inactiveFilter))}}
- {{#each this.activeThemes as |theme|}}
- <ThemesListItem
- @theme={{theme}}
- @navigateToTheme={{fn this.navigateToTheme theme}}
- />
- {{/each}}
-
- {{#if (and this.hasInactiveThemes (not this.activeFilter))}}
- <div class="themes-list-container__item inactive-indicator">
- <span class="empty">
- <div class="info">
- {{#if this.selectInactiveMode}}
- <Input
- @type="checkbox"
- @checked={{or
- (eq this.allInactiveSelected true)
- (eq this.someInactiveSelected true)
- }}
- class="toggle-all-inactive"
- indeterminate={{this.someInactiveSelected}}
- {{on "click" this.toggleAllInactive}}
- />
- {{else}}
- <DButton
- class="btn-transparent select-inactive-mode"
- @action={{this.toggleInactiveMode}}
- >
- {{icon "list"}}
- </DButton>
- {{/if}}
- {{#if this.selectInactiveMode}}
- <span class="select-inactive-mode-label">
- {{i18n
- "admin.customize.theme.selected"
- count=this.selectedCount
- }}
- </span>
- {{else if this.themesTabActive}}
- <span class="header">
- {{i18n "admin.customize.theme.inactive_themes"}}
- </span>
- {{else}}
- <span class="header">
- {{i18n "admin.customize.theme.inactive_components"}}
- </span>
- {{/if}}
-
- {{#if this.selectInactiveMode}}
- <a
- href
- {{on "click" this.toggleInactiveMode}}
- class="cancel-select-inactive-mode"
- >
- {{i18n "admin.customize.theme.cancel"}}
- </a>
- <DButton
- class="btn btn-delete"
- @action={{this.deleteConfirmation}}
- @disabled={{eq this.selectedCount 0}}
- >
- {{icon "trash-can"}}
- Delete
- </DButton>
- {{/if}}
- </div>
- </span>
- </div>
- {{/if}}
- {{/if}}
-
- {{#if (and this.hasInactiveThemes (not this.activeFilter))}}
- {{#each this.inactiveThemes as |theme|}}
- <ThemesListItem
- class="inactive-theme"
- @theme={{theme}}
- @navigateToTheme={{fn this.navigateToTheme theme}}
- @selectInactiveMode={{this.selectInactiveMode}}
- />
- {{/each}}
- {{/if}}
- {{else}}
- <div class="themes-list-container__item">
- <span class="empty">{{i18n "admin.customize.theme.empty"}}</span>
- </div>
- {{/if}}
- </div>
-
- <div class="create-actions">
- <DButton
- @action={{this.installModal}}
- @icon="upload"
- @label="admin.customize.install"
- class="btn-primary"
- />
- </div>
- </template>
-}
diff --git a/app/assets/javascripts/admin/addon/controllers/admin-customize-themes.js b/app/assets/javascripts/admin/addon/controllers/admin-customize-themes.js
index 73a2ab41082..5e9a9881fee 100644
--- a/app/assets/javascripts/admin/addon/controllers/admin-customize-themes.js
+++ b/app/assets/javascripts/admin/addon/controllers/admin-customize-themes.js
@@ -1,10 +1,8 @@
-import { tracked } from "@glimmer/tracking";
import Controller from "@ember/controller";
import discourseComputed from "discourse/lib/decorators";
import { THEMES } from "admin/models/theme";
export default class AdminCustomizeThemesController extends Controller {
- @tracked fromNewConfigPage = false;
currentTab = THEMES;
@discourseComputed("model", "[email protected]")
diff --git a/app/assets/javascripts/admin/addon/routes/admin-customize-themes-index.js b/app/assets/javascripts/admin/addon/routes/admin-customize-themes-index.js
index cb8dbd620bb..4bc1a5cd15c 100644
--- a/app/assets/javascripts/admin/addon/routes/admin-customize-themes-index.js
+++ b/app/assets/javascripts/admin/addon/routes/admin-customize-themes-index.js
@@ -1,31 +1,10 @@
import Route from "@ember/routing/route";
-import { emojiUrlFor } from "discourse/lib/text";
-
-const externalResources = [
- {
- key: "admin.customize.theme.beginners_guide_title",
- link: "https://meta.discourse.org/t/91966",
- icon: "book",
- },
- {
- key: "admin.customize.theme.developers_guide_title",
- link: "https://meta.discourse.org/t/93648",
- icon: "book",
- },
- {
- key: "admin.customize.theme.browse_themes",
- link: "https://meta.discourse.org/c/theme",
- icon: "paintbrush",
- },
-];
+import { service } from "@ember/service";
export default class AdminCustomizeThemesIndexRoute extends Route {
- setupController(controller) {
- super.setupController(...arguments);
- this.controllerFor("adminCustomizeThemes").set("editingTheme", false);
- controller.setProperties({
- externalResources,
- womanArtistEmojiURL: emojiUrlFor("woman_artist:t5"),
- });
+ @service router;
+
+ beforeModel() {
+ this.router.transitionTo("adminConfig.customize.themes");
}
}
diff --git a/app/assets/javascripts/admin/addon/routes/admin-customize-themes-show.js b/app/assets/javascripts/admin/addon/routes/admin-customize-themes-show.js
index dcf5cb46ff1..6514fab974e 100644
--- a/app/assets/javascripts/admin/addon/routes/admin-customize-themes-show.js
+++ b/app/assets/javascripts/admin/addon/routes/admin-customize-themes-show.js
@@ -23,22 +23,14 @@ export default class AdminCustomizeThemesShowRoute extends Route {
}
}
- setupController(controller, model, transition) {
+ setupController(controller, model) {
super.setupController(...arguments);
const parentController = this.controllerFor("adminCustomizeThemes");
- const fromNewConfigPage =
- !transition.from ||
- [
- "adminConfig.customize.themes",
- "adminConfig.customize.components",
- ].includes(transition.from.name);
-
parentController.setProperties({
editingTheme: false,
currentTab: model.get("component") ? COMPONENTS : THEMES,
- fromNewConfigPage,
});
controller.setProperties({
@@ -50,7 +42,6 @@ export default class AdminCustomizeThemesShowRoute extends Route {
editingName: false,
editingThemeSetting: false,
userLocale: parentController.get("model.extras.locale"),
- fromNewConfigPage,
});
this.handleHighlight(model);
diff --git a/app/assets/javascripts/admin/addon/routes/admin-customize-themes.js b/app/assets/javascripts/admin/addon/routes/admin-customize-themes.js
index 007702625ab..ab90373e271 100644
--- a/app/assets/javascripts/admin/addon/routes/admin-customize-themes.js
+++ b/app/assets/javascripts/admin/addon/routes/admin-customize-themes.js
@@ -1,108 +1,13 @@
import { action } from "@ember/object";
import Route from "@ember/routing/route";
-import { next } from "@ember/runloop";
-import { service } from "@ember/service";
-import { i18n } from "discourse-i18n";
-import InstallThemeModal from "../components/modal/install-theme";
export default class AdminCustomizeThemesRoute extends Route {
- @service dialog;
- @service router;
- @service modal;
-
- queryParams = {
- repoUrl: null,
- repoName: null,
- };
-
- model(params) {
- this.currentTab = params.type;
+ model() {
return this.store.findAll("theme");
}
- setupController(controller, model) {
- super.setupController(controller, model);
-
- if (this.currentTab) {
- controller.setProperties({
- editingTheme: false,
- currentTab: this.currentTab,
- });
- }
-
- if (controller.repoUrl) {
- next(() => {
- this.modal.show(InstallThemeModal, {
- model: {
- uploadUrl: controller.repoUrl,
- uploadName: controller.repoName,
- selection: "directRepoInstall",
- clearParams: this.clearParams,
- ...this.installThemeOptions(model),
- },
- });
- });
- }
- }
-
- installThemeOptions(model) {
- return {
- selectedType: this.controller.currentTab,
- userId: model.userId,
- content: model.content,
- installedThemes: this.controller.installedThemes,
- addTheme: this.addTheme,
- updateSelectedType: this.updateSelectedType,
- };
- }
-
@action
routeRefreshModel() {
this.refresh();
}
-
- @action
- installModal() {
- const currentTheme = this.modelFor("adminCustomizeThemes");
- if (this.currentModel?.warnUnassignedComponent) {
- this.dialog.yesNoConfirm({
- message: i18n("admin.customize.theme.unsaved_parent_themes"),
- didConfirm: () => {
- currentTheme.set("recentlyInstalled", false);
- this.modal.show(InstallThemeModal, {
- model: { ...this.installThemeOptions(currentTheme) },
- });
- },
- });
- } else {
- this.modal.show(InstallThemeModal, {
- model: { ...this.installThemeOptions(currentTheme) },
- });
- }
- }
-
- @action
- updateSelectedType(type) {
- this.controller.set("currentTab", type);
- }
-
- @action
- clearParams() {
- this.controller.setProperties({
- repoUrl: null,
- repoName: null,
- });
- }
-
- @action
- addTheme(theme) {
- this.refresh();
- theme.setProperties({ recentlyInstalled: true });
- this.router.transitionTo("adminCustomizeThemes.show", theme.get("id"), {
- queryParams: {
- repoName: null,
- repoUrl: null,
- },
- });
- }
}
diff --git a/app/assets/javascripts/admin/addon/templates/customize-themes-index.gjs b/app/assets/javascripts/admin/addon/templates/customize-themes-index.gjs
deleted file mode 100644
index 85f1c77077f..00000000000
--- a/app/assets/javascripts/admin/addon/templates/customize-themes-index.gjs
+++ /dev/null
@@ -1,37 +0,0 @@
-import RouteTemplate from "ember-route-template";
-import DButton from "discourse/components/d-button";
-import icon from "discourse/helpers/d-icon";
-import routeAction from "discourse/helpers/route-action";
-import { i18n } from "discourse-i18n";
-
-export default RouteTemplate(
- <template>
- <div class="themes-intro admin-intro">
- <img src={{@controller.womanArtistEmojiURL}} alt />
- <div class="content-wrapper">
- <h1>{{i18n "admin.customize.theme.themes_intro"}}</h1>
- <div class="create-actions">
- <DButton
- @action={{routeAction "installModal"}}
- @icon="upload"
- @label="admin.customize.install"
- class="btn-primary"
- />
- </div>
- <div class="external-resources">
- {{#each @controller.externalResources as |resource|}}
- <a
- href={{resource.link}}
- class="external-link"
- rel="noopener noreferrer"
- target="_blank"
- >
- {{icon resource.icon}}
- {{i18n resource.key}}
- </a>
- {{/each}}
- </div>
- </div>
- </div>
- </template>
-);
diff --git a/app/assets/javascripts/admin/addon/templates/customize-themes-show.gjs b/app/assets/javascripts/admin/addon/templates/customize-themes-show.gjs
index caeec2b6e93..0ec1131ab33 100644
--- a/app/assets/javascripts/admin/addon/templates/customize-themes-show.gjs
+++ b/app/assets/javascripts/admin/addon/templates/customize-themes-show.gjs
@@ -7,7 +7,6 @@ import PluginOutlet from "discourse/components/plugin-outlet";
import TextField from "discourse/components/text-field";
import UserLink from "discourse/components/user-link";
import avatar from "discourse/helpers/avatar";
-import concatClass from "discourse/helpers/concat-class";
import icon from "discourse/helpers/d-icon";
import formatDate from "discourse/helpers/format-date";
import formatUsername from "discourse/helpers/format-username";
@@ -26,32 +25,25 @@ export default RouteTemplate(
{{#if @controller.editingThemeSetting}}
{{outlet}}
{{else}}
- {{#if @controller.fromNewConfigPage}}
- <div class="back-to-themes-and-components">
- <LinkTo
- @route={{if
+ <div class="back-to-themes-and-components">
+ <LinkTo
+ @route={{if
+ @controller.model.component
+ "adminConfig.customize.components"
+ "adminConfig.customize.themes"
+ }}
+ >
+ {{icon "angle-left"}}
+ {{i18n
+ (if
@controller.model.component
- "adminConfig.customize.components"
- "adminConfig.customize.themes"
- }}
- >
- {{icon "angle-left"}}
- {{i18n
- (if
- @controller.model.component
- "admin.config_areas.themes_and_components.components.back"
- "admin.config_areas.themes_and_components.themes.back"
- )
- }}
- </LinkTo>
- </div>
- {{/if}}
- <div
- class={{concatClass
- "show-current-style"
- (unless @controller.fromNewConfigPage "legacy")
- }}
- >
+ "admin.config_areas.themes_and_components.components.back"
+ "admin.config_areas.themes_and_components.themes.back"
+ )
+ }}
+ </LinkTo>
+ </div>
+ <div class="show-current-style">
<span>
<PluginOutlet
@name="admin-customize-themes-show-top"
diff --git a/app/assets/javascripts/admin/addon/templates/customize-themes.gjs b/app/assets/javascripts/admin/addon/templates/customize-themes.gjs
deleted file mode 100644
index 1216371a238..00000000000
--- a/app/assets/javascripts/admin/addon/templates/customize-themes.gjs
+++ /dev/null
@@ -1,59 +0,0 @@
-import RouteTemplate from "ember-route-template";
-import { eq, or } from "truth-helpers";
-import DBreadcrumbsItem from "discourse/components/d-breadcrumbs-item";
-import DPageHeader from "discourse/components/d-page-header";
-import PluginOutlet from "discourse/components/plugin-outlet";
-import routeAction from "discourse/helpers/route-action";
-import { i18n } from "discourse-i18n";
-import ThemesList from "admin/components/themes-list";
-
-export default RouteTemplate(
- <template>
- {{#unless @controller.fromNewConfigPage}}
- {{#if (eq @controller.currentTab "themes")}}
- <DPageHeader
- @titleLabel={{i18n "admin.config.themes.title"}}
- @descriptionLabel={{i18n "admin.config.themes.header_description"}}
- @learnMoreUrl="https://meta.discourse.org/t/91966"
- @hideTabs={{true}}
- >
- <:breadcrumbs>
- <DBreadcrumbsItem @path="/admin" @label={{i18n "admin_title"}} />
- <DBreadcrumbsItem
- @path="/admin/customize/themes"
- @label={{i18n "admin.config.themes.title"}}
- />
- </:breadcrumbs>
- </DPageHeader>
- {{else}}
- <DPageHeader
- @titleLabel={{i18n "admin.config.components.title"}}
- @descriptionLabel={{i18n
- "admin.config.components.header_description"
- }}
- @hideTabs={{true}}
- >
- <:breadcrumbs>
- <DBreadcrumbsItem @path="/admin" @label={{i18n "admin_title"}} />
- <DBreadcrumbsItem
- @path="/admin/customize/components"
- @label={{i18n "admin.config.components.title"}}
- />
- </:breadcrumbs>
- </DPageHeader>
- {{/if}}
- {{/unless}}
-
- <PluginOutlet @name="admin-customize-themes">
- {{#unless (or @controller.editingTheme @controller.fromNewConfigPage)}}
- <ThemesList
- @themes={{@controller.fullThemes}}
- @components={{@controller.childThemes}}
- @currentTab={{@controller.currentTab}}
- @installModal={{routeAction "installModal"}}
- />
- {{/unless}}
- {{outlet}}
- </PluginOutlet>
- </template>
-);
diff --git a/app/assets/javascripts/discourse/tests/acceptance/admin-install-theme-modal-test.js b/app/assets/javascripts/discourse/tests/acceptance/admin-install-theme-modal-test.js
index c20a2469e04..8f3ec257941 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/admin-install-theme-modal-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/admin-install-theme-modal-test.js
@@ -5,6 +5,78 @@ import { i18n } from "discourse-i18n";
acceptance("Admin - Themes - Install modal", function (needs) {
needs.user();
+ needs.pretender((server, helper) => {
+ const themes = [
+ {
+ id: 42,
+ name: "discourse-incomplete-theme",
+ created_at: "2022-01-01T12:00:00.000Z",
+ updated_at: "2022-01-01T12:00:00.000Z",
+ component: false,
+ color_scheme: null,
+ user_selectable: false,
+ remote_theme_id: 42,
+ supported: true,
+ description: null,
+ enabled: true,
+ child_themes: [],
+ remote_theme: {
+ id: 42,
+ remote_url: "[email protected]:discourse/discourse-incomplete-theme.git",
+ remote_version: null,
+ local_version: null,
+ commits_behind: null,
+ branch: null,
+ remote_updated_at: null,
+ updated_at: "2022-01-01T12:00:00.000Z",
+ last_error_text: null,
+ is_git: true,
+ license_url: null,
+ about_url: null,
+ authors: null,
+ theme_version: null,
+ minimum_discourse_version: null,
+ maximum_discourse_version: null,
+ },
+ },
+ {
+ id: 43,
+ name: "Graceful",
+ created_at: "2022-01-01T12:00:00.000Z",
+ updated_at: "2022-01-01T12:00:00.000Z",
+ component: false,
+ color_scheme: null,
+ user_selectable: false,
+ remote_theme_id: 43,
+ supported: true,
+ description: null,
+ enabled: true,
+ child_themes: [],
+ remote_theme: {
+ id: 43,
+ remote_url: "https://github.com/discourse/graceful",
+ remote_version: null,
+ local_version: null,
+ commits_behind: null,
+ branch: null,
+ remote_updated_at: null,
+ updated_at: "2022-01-01T12:00:00.000Z",
+ last_error_text: null,
+ is_git: true,
+ license_url: null,
+ about_url: null,
+ authors: null,
+ theme_version: null,
+ minimum_discourse_version: null,
+ maximum_discourse_version: null,
+ },
+ },
+ ];
+
+ server.get("/admin/config/customize/themes", () => {
+ return helper.response(200, { themes });
+ });
+ });
test("closing the modal resets the modal inputs", async function (assert) {
const urlInput = ".install-theme-content .repo input";
@@ -12,9 +84,9 @@ acceptance("Admin - Themes - Install modal", function (needs) {
const publicKey = ".install-theme-content .public-key textarea";
const themeUrl = "[email protected]:discourse/discourse.git";
- await visit("/admin/customize/themes");
+ await visit("/admin/config/customize/themes");
- await click(".create-actions .btn-primary");
+ await click(".theme-install-card__install-button");
await click("#remote");
await fillIn(urlInput, themeUrl);
await click(".install-theme-content .inputs .advanced-repo");
@@ -25,7 +97,7 @@ acceptance("Admin - Themes - Install modal", function (needs) {
await click(".d-modal__footer .d-modal-cancel");
- await click(".create-actions .btn-primary");
+ await click(".theme-install-card__install-button");
await click("#remote");
await click(".install-theme-content .inputs .advanced-repo");
assert.dom(urlInput).hasValue("", "url input is reset");
@@ -42,7 +114,7 @@ acceptance("Admin - Themes - Install modal", function (needs) {
"[email protected]:/TEST_THEME/test-theme.git";
await visit("/admin/customize/themes");
- await click(".create-actions .btn-primary");
+ await click(".theme-install-card__install-button");
await click("#remote");
await fillIn(urlInput, themeUrl);
await click(".install-theme-content .inputs .advanced-repo");
@@ -74,21 +146,23 @@ acceptance("Admin - Themes - Install modal", function (needs) {
});
test("modal can be auto-opened with the right query params", async function (assert) {
- await visit("/admin/customize/themes?repoUrl=testUrl&repoName=testName");
+ await visit(
+ "/admin/config/customize/themes?repoUrl=testUrl&repoName=testName"
+ );
assert.dom(".admin-install-theme-modal").exists("modal is visible");
assert.dom(".install-theme code").hasText("testUrl", "repo url is visible");
await click(".d-modal-cancel");
assert.strictEqual(
currentURL(),
- "/admin/customize/themes",
+ "/admin/config/customize/themes",
"query params are cleared after dismissing the modal"
);
});
test("installed themes are matched with the popular list by URL", async function (assert) {
- await visit("/admin/customize/themes");
- await click(".create-actions .btn-primary");
+ await visit("/admin/config/customize/themes");
+ await click(".theme-install-card__install-button");
assert
.dom(
diff --git a/app/assets/javascripts/discourse/tests/integration/components/themes-list-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/themes-list-test.gjs
deleted file mode 100644
index 138898d2203..00000000000
--- a/app/assets/javascripts/discourse/tests/integration/components/themes-list-test.gjs
+++ /dev/null
@@ -1,405 +0,0 @@
-import { array } from "@ember/helper";
-import { fillIn, render } from "@ember/test-helpers";
-import { module, test } from "qunit";
-import { setupRenderingTest } from "discourse/tests/helpers/component-test";
-import { queryAll } from "discourse/tests/helpers/qunit-helpers";
-import selectKit from "discourse/tests/helpers/select-kit-helper";
-import { i18n } from "discourse-i18n";
-import ThemesList from "admin/components/themes-list";
-import Theme, { COMPONENTS, THEMES } from "admin/models/theme";
-
-function createThemes(itemsCount, customAttributesCallback) {
- return [...Array(itemsCount)].map((_, i) => {
- const attrs = { name: `Theme ${i + 1}` };
- if (customAttributesCallback) {
- Object.assign(attrs, customAttributesCallback(i + 1));
- }
- return Theme.create(attrs);
- });
-}
-
-module("Integration | Component | themes-list", function (hooks) {
- setupRenderingTest(hooks);
-
- test("current tab is themes", async function (assert) {
- const self = this;
-
- this.themes = createThemes(5);
- this.components = createThemes(5, (n) => {
- return {
- name: `Child ${n}`,
- component: true,
- parentThemes: [this.themes[n - 1]],
- parent_themes: [1, 2, 3, 4, 5],
- };
- });
- this.setProperties({
- themes: this.themes,
- components: this.components,
- currentTab: THEMES,
- });
-
- await render(
- <template>
- <ThemesList
- @themes={{self.themes}}
- @components={{self.components}}
- @currentTab={{self.currentTab}}
- />
- </template>
- );
-
- assert.dom(".themes-tab").hasClass("active", "themes tab is active");
- assert
- .dom(".components-tab")
- .doesNotHaveClass("active", "components tab is not active");
-
- assert
- .dom(".inactive-indicator")
- .doesNotExist(
- "there is no inactive themes separator when all themes are inactive"
- );
- assert
- .dom(".themes-list-container__item .info")
- .exists({ count: 5 }, "displays all themes");
-
- [2, 3].forEach((num) => this.themes[num].set("user_selectable", true));
- this.themes[4].set("default", true);
- this.set("themes", this.themes);
- const names = [4, 2, 3, 0, 1].map((num) => this.themes[num].get("name")); // default theme always on top, followed by user-selectable ones and then the rest
- assert.deepEqual(
- [...queryAll(".themes-list-container__item .info .name")].map((node) =>
- node.innerText.trim()
- ),
- names,
- "sorts themes correctly"
- );
- assert.strictEqual(
- queryAll(".inactive-indicator").index(),
- 3,
- "the separator is in the right location"
- );
-
- this.themes.forEach((theme) => theme.set("user_selectable", true));
- this.set("themes", this.themes);
- assert
- .dom(".inactive-indicator")
- .doesNotExist(
- "there is no inactive themes separator when all themes are user-selectable"
- );
-
- this.set("themes", []);
- assert
- .dom(".themes-list-container__item .empty")
- .exists(
- { count: 1 },
- "shows one entry with a message when there is nothing to display"
- );
- assert
- .dom(".themes-list-container__item span.empty")
- .hasText(
- i18n("admin.customize.theme.empty"),
- "displays the right message"
- );
- });
-
- test("current tab is components", async function (assert) {
- const self = this;
-
- this.themes = createThemes(5);
- this.components = createThemes(5, (n) => {
- return {
- name: `Child ${n}`,
- component: true,
- parentThemes: [this.themes[n - 1]],
- parent_themes: [1, 2, 3, 4, 5],
- };
- });
- this.setProperties({
- themes: this.themes,
- components: this.components,
- currentTab: COMPONENTS,
- });
-
- await render(
- <template>
- <ThemesList
- @themes={{self.themes}}
- @components={{self.components}}
- @currentTab={{self.currentTab}}
- />
- </template>
- );
-
- assert
- .dom(".components-tab")
- .hasClass("active", "components tab is active");
- assert
- .dom(".themes-tab")
- .doesNotHaveClass("active", "themes tab is not active");
-
- assert.dom(".inactive-indicator").doesNotExist("there is no separator");
- assert
- .dom(".themes-list-container__item .info")
- .exists({ count: 5 }, "displays all components");
-
- this.set("components", []);
- assert
- .dom(".themes-list-container__item .empty")
- .exists(
- { count: 1 },
- "shows one entry with a message when there is nothing to display"
- );
- assert
- .dom(".themes-list-container__item span.empty")
- .hasText(
- i18n("admin.customize.theme.empty"),
- "displays the right message"
- );
- });
-
- test("themes search is not visible when there are less than 10 themes", async function (assert) {
- const self = this;
-
- const themes = createThemes(9);
- this.setProperties({
- themes,
- currentTab: THEMES,
- });
-
- await render(
- <template>
- <ThemesList
- @themes={{self.themes}}
- @components={{(array)}}
- @currentTab={{self.currentTab}}
- />
- </template>
- );
-
- assert
- .dom(".themes-list-search")
- .doesNotExist("search input not shown when we have fewer than 10 themes");
- });
-
- test("themes search keeps themes whose names include the search term", async function (assert) {
- const self = this;
-
- const themes = ["osama", "OsAmaa", "osAMA 1234"]
- .map((name) => Theme.create({ name: `Theme ${name}` }))
- .concat(createThemes(7));
- this.setProperties({
- themes,
- currentTab: THEMES,
- });
-
- await render(
- <template>
- <ThemesList
- @themes={{self.themes}}
- @components={{(array)}}
- @currentTab={{self.currentTab}}
- />
- </template>
- );
-
- assert.dom(".themes-list-search__input").exists();
- await fillIn(".themes-list-search__input", " oSAma ");
- assert.deepEqual(
- [...queryAll(".themes-list-container__item .info .name")].map((node) =>
- node.textContent.trim()
- ),
- ["Theme osama", "Theme OsAmaa", "Theme osAMA 1234"],
- "only themes whose names include the search term are shown"
- );
- });
-
- test("themes filter", async function (assert) {
- const self = this;
-
- const themes = [
- Theme.create({ name: "Theme enabled 1", user_selectable: true }),
- Theme.create({ name: "Theme enabled 2", user_selectable: true }),
- Theme.create({ name: "Theme disabled 1", user_selectable: false }),
- Theme.create({
- name: "Theme disabled 2",
- user_selectable: false,
- remote_theme: {
- id: 42,
- remote_url:
- "[email protected]:discourse-org/discourse-incomplete-theme.git",
- commits_behind: 1,
- },
- }),
- ];
-
- // This is to make the filter show, it only shows if there are 10+ themes or components.
- const otherThemes = createThemes(8, (n) => {
- return {
- name: `OtherTheme ${n}${n}`,
- component: true,
- parent_themes: [1],
- enabled: true,
- };
- });
-
- this.setProperties({
- themes: themes.concat(otherThemes),
- currentTab: THEMES,
- });
-
- function themeNames() {
- return [...queryAll(".themes-list-container__item .info .name")]
- .map((node) => node.textContent.trim())
- .filter((name) => !name.includes("OtherTheme"));
- }
-
- await render(
- <template>
- <ThemesList
- @themes={{self.themes}}
- @components={{(array)}}
- @currentTab={{self.currentTab}}
- />
- </template>
- );
-
- assert.dom(".themes-list-filter__input").exists();
- assert.deepEqual(themeNames(), [
- "Theme enabled 1",
- "Theme enabled 2",
- "Theme disabled 1",
- "Theme disabled 2",
- ]);
-
- await selectKit(".themes-list-filter__input").expand();
- await selectKit(".themes-list-filter__input").selectRowByValue("active");
- assert.deepEqual(
- themeNames(),
-
- ["Theme enabled 1", "Theme enabled 2"]
- );
-
- await selectKit(".themes-list-filter__input").expand();
- await selectKit(".themes-list-filter__input").selectRowByValue("inactive");
- assert.deepEqual(themeNames(), ["Theme disabled 1", "Theme disabled 2"]);
-
- await selectKit(".themes-list-filter__input").expand();
- await selectKit(".themes-list-filter__input").selectRowByValue(
- "updates_available"
- );
- assert.deepEqual(themeNames(), ["Theme disabled 2"]);
- });
-
- test("components filter", async function (assert) {
- const self = this;
-
- const components = [
- Theme.create({
- name: "Component used 1",
- component: true,
- user_selectable: true,
- parent_themes: [1],
- enabled: true,
- }),
- Theme.create({
- name: "Component used 2",
- component: true,
- user_selectable: true,
- parent_themes: [1],
- enabled: true,
- }),
- Theme.create({
- name: "Component unused 1",
- component: true,
- user_selectable: false,
- parent_themes: [],
- enabled: true,
- }),
- Theme.create({
- name: "Component unused and disabled 1",
- component: true,
- user_selectable: false,
- parent_themes: [],
- enabled: false,
- remote_theme: {
- id: 42,
- remote_url:
- "[email protected]:discourse-org/discourse-incomplete-theme.git",
- commits_behind: 1,
- },
- }),
- ];
-
- // This is to make the filter show, it only shows if there are 10+ themes or components.
- const otherComponents = createThemes(8, (n) => {
- return {
- name: `OtherComponent ${n}${n}`,
- component: true,
- parent_themes: [1],
- enabled: true,
- };
- });
-
- this.setProperties({
- components: components.concat(otherComponents),
- currentTab: COMPONENTS,
- });
-
- await render(
- <template>
- <ThemesList
- @themes={{(array)}}
- @components={{self.components}}
- @currentTab={{self.currentTab}}
- />
- </template>
- );
-
- function componentNames() {
- return [...queryAll(".themes-list-container__item .info .name")]
- .map((node) => node.textContent.trim())
- .filter((name) => !name.includes("OtherComponent"));
- }
-
- assert.dom(".themes-list-filter__input").exists();
- assert.deepEqual(componentNames(), [
- "Component used 1",
- "Component used 2",
- "Component unused 1",
- "Component unused and disabled 1",
- ]);
-
- await selectKit(".themes-list-filter__input").expand();
- await selectKit(".themes-list-filter__input").selectRowByValue("active");
- assert.deepEqual(componentNames(), [
- "Component used 1",
- "Component used 2",
- ]);
-
- await selectKit(".themes-list-filter__input").expand();
- await selectKit(".themes-list-filter__input").selectRowByValue("inactive");
- assert.deepEqual(componentNames(), [
- "Component unused 1",
- "Component unused and disabled 1",
- ]);
-
- await selectKit(".themes-list-filter__input").expand();
- await selectKit(".themes-list-filter__input").selectRowByValue("enabled");
- assert.deepEqual(componentNames(), [
- "Component used 1",
- "Component used 2",
- "Component unused 1",
- ]);
-
- await selectKit(".themes-list-filter__input").expand();
- await selectKit(".themes-list-filter__input").selectRowByValue("disabled");
- assert.deepEqual(componentNames(), ["Component unused and disabled 1"]);
-
- await selectKit(".themes-list-filter__input").expand();
- await selectKit(".themes-list-filter__input").selectRowByValue(
- "updates_available"
- );
- assert.deepEqual(componentNames(), ["Component unused and disabled 1"]);
- });
-});
diff --git a/app/assets/stylesheets/admin/customize.scss b/app/assets/stylesheets/admin/customize.scss
index 6f154ec31d0..47cde8edb09 100644
--- a/app/assets/stylesheets/admin/customize.scss
+++ b/app/assets/stylesheets/admin/customize.scss
@@ -276,289 +276,6 @@
}
}
- .themes-list-header {
- width: 100%;
- display: flex;
- border: 1px solid var(--primary-low);
- border-top-right-radius: var(--d-border-radius);
- border-top-left-radius: var(--d-border-radius);
-
- // gap: 0.25em;
- .tab {
- border: none;
- padding: 1em;
- width: 50%;
- box-sizing: border-box;
- text-align: center;
- background: var(--d-nav-bg-color);
-
- &.themes-tab {
- border-top-right-radius: 0;
- border-bottom-left-radius: 0;
- border-bottom-right-radius: 0;
- }
-
- &.components-tab {
- border-top-left-radius: 0;
- border-bottom-left-radius: 0;
- border-bottom-right-radius: 0;
- }
-
- .discourse-no-touch & {
- &:focus,
- &:hover {
- color: var(--d-nav-color--hover);
- position: relative;
-
- @include nav-active;
-
- &.active {
- color: var(--d-nav-color--active);
- }
-
- .d-icon {
- color: inherit;
- }
- }
- }
-
- &.active {
- position: relative;
-
- @include nav-active;
- }
- }
-
- .d-button-label {
- @include ellipsis;
- }
- }
-
- .themes-list-search {
- display: flex;
- align-items: center;
- position: sticky;
- top: 0;
- z-index: z("base");
- height: 3em;
- background: var(--primary-very-low);
-
- .d-icon {
- position: absolute;
- padding-left: 0.5em;
- }
-
- &__input {
- width: 100%;
- height: 100%;
- margin: 0;
- border: 0;
- padding-left: 2em;
- background-color: var(--primary-very-low);
-
- &:focus {
- outline: 0;
-
- ~ .d-icon {
- color: var(--tertiary-hover);
- }
- }
- }
- }
-
- .themes-list-filter {
- padding-left: 0.67em;
- display: flex;
- height: 3em;
- align-items: center;
- background-color: var(--primary-very-low);
-
- &__label {
- white-space: nowrap;
- margin-right: 1em;
- }
-
- &__input {
- margin-right: 0.5em;
-
- summary {
- width: auto;
- }
- }
- }
-
- .themes-list-filter,
- .themes-list-search {
- color: var(--primary);
- display: flex;
- border-right: 1px solid var(--primary-low);
- border-bottom: 1px solid var(--primary-low);
- border-left: 1px solid var(--primary-low);
- }
-
- .themes-list-container {
- overflow-y: auto;
- max-height: 60vh;
- border-bottom-right-radius: var(--d-border-radius);
- border-bottom-left-radius: var(--d-border-radius);
- border-right: 1px solid var(--primary-low);
- border-bottom: 1px solid var(--primary-low);
- border-left: 1px solid var(--primary-low);
- width: 100%;
-
- @media screen and (height <= 1000px) {
- max-height: 50vh;
- }
-
- @media screen and (height <= 800px) {
- max-height: 40vh;
- }
-
- &__item:last-child {
- border-bottom: none;
- }
-
- &__item {
- color: var(--primary);
- border-bottom: 1px solid var(--primary-low);
- display: flex;
-
- .select-inactive-mode-label {
- color: var(--tertiary);
- font-weight: bold;
- }
-
- &.inactive-theme {
- color: var(--primary-high);
- background: var(--primary-very-low);
-
- &:not(.selected):hover {
- color: var(--primary);
- }
- }
-
- &.inactive-indicator {
- border-right: 0;
- border-left: 0;
- margin-top: 1em;
- padding-left: 0.33em;
-
- span.empty {
- padding-left: 0.33em;
- padding-top: 1em;
- }
-
- .btn.select-inactive-mode {
- padding-left: 0;
- padding-top: 0;
- padding-bottom: 0;
- }
- }
-
- &:not(.inactive-indicator, .selected):hover {
- background-color: var(--primary-very-low);
-
- .component {
- border-color: var(--primary-low-mid);
- }
- }
-
- &.selected {
- color: var(--secondary);
- background-color: var(--tertiary);
-
- .components-list {
- color: var(--secondary);
- }
- }
-
- &:not(.selected) {
- .broken-indicator {
- color: var(--danger);
- }
-
- .fa {
- opacity: 0.7;
- }
-
- .default-indicator {
- color: var(--success);
- }
- }
-
- .light-grey-icon {
- color: var(--primary-medium);
- }
-
- .info {
- overflow: hidden;
- display: flex;
- align-items: center;
-
- @include line-clamp(4);
-
- .icons {
- margin-left: auto;
- }
-
- .cancel-select-inactive-mode {
- margin-left: auto;
- }
-
- .btn-delete {
- font-size: var(--font-down-1);
- margin-left: 0.5em;
-
- svg {
- margin-right: 0.5em;
- }
- }
-
- input {
- margin-top: 0;
- }
- }
-
- .components-list {
- margin-top: 5px;
- display: inline-block;
- font-size: var(--font-down-1);
- align-items: baseline;
- color: var(--primary-high);
-
- .others-count,
- .others-count:hover {
- color: inherit;
- text-decoration: underline;
- }
-
- .d-icon {
- color: inherit;
- }
- }
-
- .components {
- overflow-wrap: anywhere;
- }
-
- .inner-wrapper {
- box-sizing: border-box;
- padding: 0.67em;
- cursor: pointer;
- }
-
- span.empty {
- padding: 3px 10px 3px 10px;
- }
-
- .inner-wrapper,
- span.empty {
- color: inherit;
- width: 100%;
- }
- }
- }
-
.theme.settings {
.theme-setting {
min-height: 35px;