Files
discourse/app/assets/javascripts/admin/addon/controllers/admin-site-settings.js
Martin Brennan e26a1175d7 FEATURE: Initial version of experimental admin search (#31299)
This feature allows admins to find what they are
looking for in the admin interface via a search modal.
This replaces the admin sidebar filter
as the focus of the Ctrl+/ command, but the sidebar
filter can also still be used. Perhaps at some point
we may remove it or change the shortcut.

The search modal presents the following data for filtering:

* A list of all admin pages, the same as the sidebar,
   except also showing "third level" pages like
   "Email > Skipped"
* All site settings
* Themes
* Components
* Reports

Admins can also filter which types of items are shown in the modal,
for example hiding Settings if they know they are looking for a Page.

In this PR, I also have the following fixes:

* Site setting filters now clear when moving between
   filtered site setting pages, previously it was super
   sticky from Ember
* Many translations were moved around, instead of being
   in various namespaces for the sidebar links and the admin
   page titles and descriptions, now everything is under
   `admin.config` namespace, this makes it way easier to reuse
   this text for pages, search, and sidebar, and if you change it
   in one place then it is changed everywhere.

---------

Co-authored-by: Ella <ella.estigoy@gmail.com>
2025-02-21 11:59:24 +10:00

81 lines
2.1 KiB
JavaScript

import Controller from "@ember/controller";
import { action } from "@ember/object";
import { alias } from "@ember/object/computed";
import { service } from "@ember/service";
import { isEmpty } from "@ember/utils";
import { debounce } from "discourse/lib/decorators";
import { INPUT_DELAY } from "discourse/lib/environment";
import SiteSettingFilter from "discourse/lib/site-setting-filter";
export default class AdminSiteSettingsController extends Controller {
@service router;
@alias("model") allSiteSettings;
filter = "";
visibleSiteSettings = null;
siteSettingFilter = null;
filterContentNow(filterData, category) {
this.siteSettingFilter ??= new SiteSettingFilter(this.allSiteSettings);
if (isEmpty(this.allSiteSettings)) {
return;
}
this.set("filter", filterData.filter);
if (isEmpty(filterData.filter) && !filterData.onlyOverridden) {
this.set("visibleSiteSettings", this.allSiteSettings);
if (this.categoryNameKey === "all_results") {
this.router.transitionTo("adminSiteSettings");
}
return;
}
const matchesGroupedByCategory = this.siteSettingFilter.filterSettings(
filterData.filter,
{ onlyOverridden: filterData.onlyOverridden }
);
const categoryMatches = matchesGroupedByCategory.findBy(
"nameKey",
category
);
if (!categoryMatches || categoryMatches.count === 0) {
category = "all_results";
}
this.set("visibleSiteSettings", matchesGroupedByCategory);
this.router.transitionTo(
"adminSiteSettingsCategory",
category || "all_results"
);
}
@debounce(INPUT_DELAY)
filterContent(filterData) {
if (this._skipBounce) {
this.set("_skipBounce", false);
} else {
if (!this.isDestroyed) {
this.filterContentNow(filterData, this.categoryNameKey);
}
}
}
@action
filterChanged(filterData) {
this.filterContent(filterData);
}
@action
toggleMenu() {
const adminDetail = document.querySelector(".admin-detail");
["mobile-closed", "mobile-open"].forEach((state) => {
adminDetail.classList.toggle(state);
});
}
}