Skip to content

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

DEV: Add default keywords getter to `BaseCustomSidebarSectionLink` (#38302)

Isaac Janzenbbcc52f8a19e
diff --git a/frontend/discourse/app/lib/sidebar/base-custom-sidebar-section-link.js b/frontend/discourse/app/lib/sidebar/base-custom-sidebar-section-link.js
index 876bf24ca14..bf796cbf658 100644
--- a/frontend/discourse/app/lib/sidebar/base-custom-sidebar-section-link.js
+++ b/frontend/discourse/app/lib/sidebar/base-custom-sidebar-section-link.js
@@ -150,6 +150,13 @@ export default class BaseCustomSidebarSectionLink {
*/
get hoverTitle() {}
+ /**
+ * @returns {{ navigation: string[] }} Keywords for the sidebar section link used for filtering
+ */
+ get keywords() {
+ return { navigation: [] };
+ }
+
_notImplemented() {
throw "not implemented";
}
diff --git a/frontend/discourse/tests/acceptance/sidebar-plugin-api-test.gjs b/frontend/discourse/tests/acceptance/sidebar-plugin-api-test.gjs
index 20806f4d128..37d541419cd 100644
--- a/frontend/discourse/tests/acceptance/sidebar-plugin-api-test.gjs
+++ b/frontend/discourse/tests/acceptance/sidebar-plugin-api-test.gjs
@@ -1,5 +1,5 @@
import Component from "@glimmer/component";
-import { click, settled, visit } from "@ember/test-helpers";
+import { click, fillIn, settled, visit } from "@ember/test-helpers";
import { test } from "qunit";
import { withPluginApi } from "discourse/lib/plugin-api";
import {
@@ -948,4 +948,58 @@ acceptance("Sidebar - Plugin API", function (needs) {
"the link is into view"
);
});
+
+ test("filtering does not crash when a custom sidebar section link has no keywords getter", async function (assert) {
+ withPluginApi((api) => {
+ api.addSidebarPanel((BaseCustomSidebarPanel) => {
+ return class extends BaseCustomSidebarPanel {
+ key = "filterable-panel";
+ switchButtonLabel = "Filterable panel";
+ switchButtonIcon = "d-chat";
+ switchButtonDefaultUrl = "/";
+ displayHeader = true;
+
+ get filterable() {
+ return true;
+ }
+ };
+ });
+
+ api.addSidebarSection(
+ (BaseCustomSidebarSection, BaseCustomSidebarSectionLink) => {
+ return class extends BaseCustomSidebarSection {
+ name = "test-section";
+ text = "test section text";
+ links = [
+ new (class extends BaseCustomSidebarSectionLink {
+ name = "test-link";
+ href = "/";
+ title = "Test Link";
+ text = "Test Link Text";
+ })(),
+ ];
+ };
+ },
+ "filterable-panel"
+ );
+
+ api.setSeparatedSidebarMode();
+ api.setSidebarPanel("filterable-panel");
+ });
+
+ await visit("/");
+
+ assert
+ .dom(".sidebar-filter__input")
+ .exists("filter input is visible for filterable panel");
+
+ // Use a filter that doesn't match the link text so keywords.navigation is accessed
+ await fillIn(".sidebar-filter__input", "nomatch");
+
+ assert
+ .dom(".sidebar-section-link-wrapper[data-list-item-name='test-link']")
+ .doesNotExist(
+ "section link is filtered out (no crash accessing keywords)"
+ );
+ });
});