From 0cd4d7ddd18cbdb77481b9910a85c9a68f29dbe7 Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Wed, 24 Apr 2024 12:34:38 +1000 Subject: [PATCH] FEATURE: include themes and components keywords to the admin sidebar (#26708) Include themes and component keywords to make the filter more accurate. --- .../services/admin-sidebar-state-manager.js | 10 +++++++--- .../app/lib/sidebar/admin-sidebar.js | 20 ++++++++++++++++++- spec/system/admin_sidebar_navigation_spec.rb | 18 +++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/admin/addon/services/admin-sidebar-state-manager.js b/app/assets/javascripts/admin/addon/services/admin-sidebar-state-manager.js index fb69abcca1d..950ee17e9a1 100644 --- a/app/assets/javascripts/admin/addon/services/admin-sidebar-state-manager.js +++ b/app/assets/javascripts/admin/addon/services/admin-sidebar-state-manager.js @@ -20,9 +20,13 @@ export default class AdminSidebarStateManager extends Service { return; } - this.keywords[link_name].navigation = keywords.map((keyword) => - keyword.toLowerCase() - ); + this.keywords[link_name].navigation = [ + ...new Set( + this.keywords[link_name].navigation.concat( + keywords.map((keyword) => keyword.toLowerCase()) + ) + ), + ]; } get navConfig() { diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js b/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js index e6b0a6213af..148baa8dfcf 100644 --- a/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js +++ b/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js @@ -255,6 +255,7 @@ export default class AdminSidebarPanel extends BaseCustomSidebarPanel { const siteSettings = getOwnerWithFallback(this).lookup( "service:site-settings" ); + const store = getOwnerWithFallback(this).lookup("service:store"); const router = getOwnerWithFallback(this).lookup("service:router"); const session = getOwnerWithFallback(this).lookup("service:session"); if (!currentUser.use_admin_sidebar) { @@ -269,13 +270,30 @@ export default class AdminSidebarPanel extends BaseCustomSidebarPanel { const navMap = savedConfig || ADMIN_NAV_MAP; if (!session.get("safe_mode")) { - navMap.findBy("name", "plugins").links.push(...pluginAdminRouteLinks()); + const pluginLinks = navMap.findBy("name", "plugins").links; + pluginAdminRouteLinks().forEach((pluginLink) => { + if (!pluginLinks.mapBy("name").includes(pluginLink.name)) { + pluginLinks.push(pluginLink); + } + }); + this.adminSidebarStateManager.setLinkKeywords( "admin_installed_plugins", installedPluginsLinkKeywords() ); } + store.findAll("theme").then((themes) => { + this.adminSidebarStateManager.setLinkKeywords( + "admin_themes", + themes.content.rejectBy("component").mapBy("name") + ); + this.adminSidebarStateManager.setLinkKeywords( + "admin_components", + themes.content.filterBy("component").mapBy("name") + ); + }); + if (siteSettings.experimental_form_templates) { navMap.findBy("name", "appearance").links.push({ name: "admin_customize_form_templates", diff --git a/spec/system/admin_sidebar_navigation_spec.rb b/spec/system/admin_sidebar_navigation_spec.rb index fc89f0dd7e1..a733f5079e2 100644 --- a/spec/system/admin_sidebar_navigation_spec.rb +++ b/spec/system/admin_sidebar_navigation_spec.rb @@ -160,6 +160,24 @@ describe "Admin Revamp | Sidebar Navigation", type: :system do expect(links.map(&:text)).to eq(["Installed"]) end + it "accepts components and themes keywords for filter" do + Fabricate(:theme, name: "Air theme", component: false) + Fabricate(:theme, name: "Kanban", component: true) + + visit("/admin") + sidebar.toggle_all_sections + + filter.filter("air") + links = page.all(".sidebar-section-link-content-text") + expect(links.count).to eq(1) + expect(links.map(&:text)).to eq(["Themes"]) + + filter.filter("kanban") + links = page.all(".sidebar-section-link-content-text") + expect(links.count).to eq(1) + expect(links.map(&:text)).to eq(["Components"]) + end + it "does not show the button to customize sidebar sections, that is only supported in the main panel" do visit("/") expect(sidebar).to have_add_section_button