FEATURE: include themes and components keywords to the admin sidebar (#26708)

Include themes and component keywords to make the filter more accurate.
This commit is contained in:
Krzysztof Kotlarek 2024-04-24 12:34:38 +10:00 committed by GitHub
parent c791346088
commit 0cd4d7ddd1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 44 additions and 4 deletions

View File

@ -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() {

View File

@ -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",

View File

@ -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