DEV: Make the Glimmer Search Menu the new default (#25092)

- Convert group based `experimental_search_menu_groups_enabled` site setting to be a _hidden_ boolean `experimental_search_menu` setting.
- Make default `true`
- Remove widget search menu tests

Discourse Encrypt Test Failure Fix - https://github.com/discourse/discourse-encrypt/pull/301
This commit is contained in:
Isaac Janzen 2024-01-03 09:07:27 -07:00 committed by GitHub
parent 117611ea82
commit 1f94da349b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 12 additions and 1643 deletions

View File

@ -521,7 +521,7 @@ export default createWidget("header", {
const panels = [this.attach("header-buttons", attrs), headerIcons];
if (state.searchVisible || this.search.visible) {
if (this.currentUser?.experimental_search_menu_groups_enabled) {
if (this.siteSettings.experimental_search_menu) {
this.search.inTopicContext =
this.search.inTopicContext && inTopicRoute;
panels.push(this.attach("glimmer-search-menu-wrapper"));
@ -731,7 +731,7 @@ export default createWidget("header", {
focusSearchInput() {
if (
this.state.searchVisible &&
!this.currentUser?.experimental_search_menu_groups_enabled
!this.siteSettings.experimental_search_menu
) {
schedule("afterRender", () => {
const searchInput = document.querySelector("#search-term");

View File

@ -9,9 +9,6 @@ import {
acceptance("Search - Glimmer - Mobile", function (needs) {
needs.mobileView();
needs.user({
experimental_search_menu_groups_enabled: true,
});
test("search", async function (assert) {
await visit("/");

View File

@ -15,18 +15,11 @@ import {
exists,
query,
queryAll,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import I18n from "discourse-i18n";
acceptance("Search - Glimmer - Anonymous", function (needs) {
needs.user({
experimental_search_menu_groups_enabled: true,
});
needs.hooks.beforeEach(() => {
updateCurrentUser({ is_anonymous: true });
});
needs.pretender((server, helper) => {
server.get("/search/query", (request) => {
if (request.queryParams.type_filter === DEFAULT_TYPE_FILTER) {
@ -439,9 +432,7 @@ acceptance("Search - Glimmer - Anonymous", function (needs) {
});
acceptance("Search - Glimmer - Authenticated", function (needs) {
needs.user({
experimental_search_menu_groups_enabled: true,
});
needs.user();
needs.settings({
log_search_queries: true,
allow_uncategorized_topics: true,
@ -742,9 +733,7 @@ acceptance("Search - Glimmer - Authenticated", function (needs) {
});
acceptance("Search - Glimmer - with tagging enabled", function (needs) {
needs.user({
experimental_search_menu_groups_enabled: true,
});
needs.user();
needs.settings({ tagging_enabled: true });
needs.pretender((server, helper) => {
server.get("/tag/dev/notifications", () => {
@ -912,10 +901,7 @@ acceptance("Search - Glimmer - with tagging enabled", function (needs) {
});
acceptance("Search - Glimmer - assistant", function (needs) {
needs.user({
experimental_search_menu_groups_enabled: true,
});
needs.user();
needs.pretender((server, helper) => {
server.get("/search/query", (request) => {
if (request.queryParams["search_context[type]"] === "private_messages") {

View File

@ -1,567 +0,0 @@
import { setupTest } from "ember-qunit";
import { module, test } from "qunit";
import {
reciprocallyRankedList,
searchContextDescription,
translateResults,
} from "discourse/lib/search";
import I18n from "discourse-i18n";
module("Unit | Utility | search", function (hooks) {
setupTest(hooks);
test("unescapesEmojisInBlurbs", async function (assert) {
const source = {
posts: [
{
id: 160,
username: "pmusaraj",
avatar_template: "/user_avatar/localhost/pmusaraj/{size}/3_2.png",
created_at: "2019-07-22T03:47:04.864Z",
like_count: 1,
blurb: ":thinking: This here is a test of emojis in search blurbs.",
post_number: 1,
topic_id: 41,
},
],
topics: [],
users: [],
categories: [],
tags: [],
groups: [],
grouped_search_result: false,
};
const results = await translateResults(source);
const blurb = results.posts[0].get("blurb");
assert.ok(blurb.includes("thinking.png"));
assert.ok(blurb.startsWith('<img width="20" height="20" src'));
assert.ok(!blurb.includes(":thinking:"));
});
test("searchContextDescription", function (assert) {
assert.strictEqual(
searchContextDescription("topic"),
I18n.t("search.context.topic")
);
assert.strictEqual(
searchContextDescription("user", "silvio.dante"),
I18n.t("search.context.user", { username: "silvio.dante" })
);
assert.strictEqual(
searchContextDescription("category", "staff"),
I18n.t("search.context.category", { category: "staff" })
);
assert.strictEqual(
searchContextDescription("tag", "important"),
I18n.t("search.context.tag", { tag: "important" })
);
assert.strictEqual(
searchContextDescription("private_messages"),
I18n.t("search.context.private_messages")
);
assert.strictEqual(searchContextDescription("bad_type"), undefined);
});
test("reciprocallyRankedList", async function (assert) {
const sourceA = [
{
id: 250,
name: "Bruce Wayne",
username: "batman",
topic_id: 96,
topic: {
id: 96,
title: "I like to fight crime",
},
},
{
id: 104,
name: "Steve Rogers",
username: "captain_america",
topic_id: 2,
topic: {
id: 2,
title: "What its like being frozen...",
},
},
{
id: 202,
name: "Peter Parker",
username: "spidey",
topic_id: 32,
topic: {
id: 32,
title: "My experience meeting the Avengers",
},
},
{
id: 290,
name: "Clark Kent",
username: "superman",
topic_id: 111,
topic: {
id: 111,
title: "My fear of Kryptonite",
},
},
];
const sourceB = [
{
id: 104,
name: "Tony Stark",
username: "ironman",
topic_id: 95,
topic: {
id: 95,
title: "What I learned from my father",
},
},
{
id: 246,
name: "The Joker",
username: "joker",
topic_id: 93,
topic: {
id: 93,
title: "Why don't you put a smile on that face...",
},
},
{
id: 104,
name: "Steve Rogers",
username: "captain_america",
topic_id: 2,
topic: {
id: 2,
title: "What its like being frozen...",
},
},
{
id: 245,
name: "Loki",
username: "loki",
topic_id: 92,
topic: {
id: 92,
title: "There is only one person you can trust",
},
},
];
const desiredMixedResults = [
{
id: 104,
itemKey: "2_2",
name: "Steve Rogers",
reciprocalRank: 0.30952380952380953,
topic: {
id: 2,
title: "What its like being frozen...",
},
topic_id: 2,
username: "captain_america",
},
{
id: 250,
itemKey: "96_96",
name: "Bruce Wayne",
reciprocalRank: 0.2,
topic: {
id: 96,
title: "I like to fight crime",
},
topic_id: 96,
username: "batman",
},
{
id: 104,
itemKey: "95_95",
name: "Tony Stark",
reciprocalRank: 0.2,
topic: {
id: 95,
title: "What I learned from my father",
},
topic_id: 95,
username: "ironman",
},
{
id: 246,
itemKey: "93_93",
name: "The Joker",
reciprocalRank: 0.16666666666666666,
topic: {
id: 93,
title: "Why don't you put a smile on that face...",
},
topic_id: 93,
username: "joker",
},
{
id: 202,
itemKey: "32_32",
name: "Peter Parker",
reciprocalRank: 0.14285714285714285,
topic: {
id: 32,
title: "My experience meeting the Avengers",
},
topic_id: 32,
username: "spidey",
},
{
id: 290,
itemKey: "111_111",
name: "Clark Kent",
reciprocalRank: 0.125,
topic: {
id: 111,
title: "My fear of Kryptonite",
},
topic_id: 111,
username: "superman",
},
{
id: 245,
itemKey: "92_92",
name: "Loki",
reciprocalRank: 0.125,
topic: {
id: 92,
title: "There is only one person you can trust",
},
topic_id: 92,
username: "loki",
},
];
const rankedList = reciprocallyRankedList(
[sourceA, sourceB],
["topic_id", "topic_id"]
);
assert.deepEqual(
rankedList,
desiredMixedResults,
"it correctly ranks the results using the reciprocal ranking algorithm"
);
});
test("reciprocallyRankedList (varied lists with more sources)", async function (assert) {
const sourceA = [
{
id: 1,
name: "Tony Stark",
username: "ironman",
topic_id: 21,
topic: {
id: 21,
title: "I am iron man",
},
},
{
id: 2,
name: "Steve Rogers",
username: "captain_america",
topic_id: 22,
topic: {
id: 22,
title: "What its like being frozen...",
},
},
{
id: 3,
name: "Peter Parker",
username: "spidey",
topic_id: 23,
topic: {
id: 23,
title: "My experience meeting the Avengers",
},
},
{
id: 4,
name: "Stephen Strange",
username: "doctor_strange",
topic_id: 24,
topic: {
id: 24,
title: "14 mil different possible futures",
},
},
];
const sourceB = [
{
id: 5,
name: "Clark Kent",
username: "superman",
tid: 90,
topic: {
id: 90,
title: "I am not from this planet.",
fancy_title: "I am not from this planet.",
},
},
{
id: 6,
name: "Bruce Wayne",
username: "batman",
tid: 91,
topic: {
id: 91,
title: "It's not who I am underneath, but what I do that defines me.",
fancy_title: "It's what I do that defines me.",
},
},
{
id: 7,
name: "Steve Rogers",
username: "captain_america",
tid: 22,
topic: {
id: 22,
title: "What its like being frozen...",
fancy_title: "What its like being frozen...",
},
},
{
id: 8,
name: "Barry Allen",
username: "the_flash",
tid: 93,
topic: {
id: 93,
title: "Run Barry run!",
fancy_title: "Run barry run!",
},
},
];
const sourceC = [
{
id: 41,
tuid: 906,
name: "The Joker",
username: "joker",
user_id: 81,
flair_name: "DC",
topic: {
title: "I am not from this planet.",
can_edit: true,
},
},
{
id: 91,
tuid: 23,
name: "Peter Parker",
username: "spidey",
user_id: 80,
flair_name: "Marvel",
topic: {
title: "My experience meeting the Avengers.",
can_edit: false,
},
},
{
id: 42,
tuid: 96,
name: "Thanos",
username: "thanos",
user_id: 82,
flair_name: "Marvel",
topic: {
title: "Fine, I'll do it myself",
can_edit: true,
},
},
{
id: 43,
tuid: 97,
name: "Lex Luthor",
username: "lex",
user_id: 83,
flair_name: "DC",
topic: {
title:
"Devils don't come from the hell beneath us, they come from the sky",
can_edit: true,
},
},
];
const desiredMixedResults = [
{
id: 1,
itemKey: "21__",
name: "Tony Stark",
reciprocalRank: 0.2,
topic: {
id: 21,
title: "I am iron man",
},
topic_id: 21,
username: "ironman",
},
{
id: 5,
itemKey: "_90_",
name: "Clark Kent",
reciprocalRank: 0.2,
tid: 90,
topic: {
fancy_title: "I am not from this planet.",
id: 90,
title: "I am not from this planet.",
},
username: "superman",
},
{
flair_name: "DC",
id: 41,
itemKey: "__906",
name: "The Joker",
reciprocalRank: 0.2,
topic: {
can_edit: true,
title: "I am not from this planet.",
},
tuid: 906,
user_id: 81,
username: "joker",
},
{
id: 2,
itemKey: "22__",
name: "Steve Rogers",
reciprocalRank: 0.16666666666666666,
topic: {
id: 22,
title: "What its like being frozen...",
},
topic_id: 22,
username: "captain_america",
},
{
id: 6,
itemKey: "_91_",
name: "Bruce Wayne",
reciprocalRank: 0.16666666666666666,
tid: 91,
topic: {
fancy_title: "It's what I do that defines me.",
id: 91,
title: "It's not who I am underneath, but what I do that defines me.",
},
username: "batman",
},
{
flair_name: "Marvel",
id: 91,
itemKey: "__23",
name: "Peter Parker",
reciprocalRank: 0.16666666666666666,
topic: {
can_edit: false,
title: "My experience meeting the Avengers.",
},
tuid: 23,
user_id: 80,
username: "spidey",
},
{
id: 3,
itemKey: "23__",
name: "Peter Parker",
reciprocalRank: 0.14285714285714285,
topic: {
id: 23,
title: "My experience meeting the Avengers",
},
topic_id: 23,
username: "spidey",
},
{
id: 7,
itemKey: "_22_",
name: "Steve Rogers",
reciprocalRank: 0.14285714285714285,
tid: 22,
topic: {
fancy_title: "What its like being frozen...",
id: 22,
title: "What its like being frozen...",
},
username: "captain_america",
},
{
flair_name: "Marvel",
id: 42,
itemKey: "__96",
name: "Thanos",
reciprocalRank: 0.14285714285714285,
topic: {
can_edit: true,
title: "Fine, I'll do it myself",
},
tuid: 96,
user_id: 82,
username: "thanos",
},
{
id: 4,
itemKey: "24__",
name: "Stephen Strange",
reciprocalRank: 0.125,
topic: {
id: 24,
title: "14 mil different possible futures",
},
topic_id: 24,
username: "doctor_strange",
},
{
id: 8,
itemKey: "_93_",
name: "Barry Allen",
reciprocalRank: 0.125,
tid: 93,
topic: {
fancy_title: "Run barry run!",
id: 93,
title: "Run Barry run!",
},
username: "the_flash",
},
{
flair_name: "DC",
id: 43,
itemKey: "__97",
name: "Lex Luthor",
reciprocalRank: 0.125,
topic: {
can_edit: true,
title:
"Devils don't come from the hell beneath us, they come from the sky",
},
tuid: 97,
user_id: 83,
username: "lex",
},
];
const rankedList = reciprocallyRankedList(
[sourceA, sourceB, sourceC],
["topic_id", "tid", "tuid"]
);
assert.deepEqual(
rankedList,
desiredMixedResults,
"it correctly ranks the results using the reciprocal ranking algorithm"
);
});
});

View File

@ -1807,10 +1807,6 @@ class User < ActiveRecord::Base
in_any_groups?(SiteSetting.experimental_new_new_view_groups_map)
end
def experimental_search_menu_groups_enabled?
in_any_groups?(SiteSetting.experimental_search_menu_groups_map)
end
def watched_precedence_over_muted
if user_option.watched_precedence_over_muted.nil?
SiteSetting.watched_precedence_over_muted

View File

@ -66,8 +66,7 @@ class CurrentUserSerializer < BasicUserSerializer
:sidebar_tags,
:sidebar_category_ids,
:sidebar_sections,
:new_new_view_enabled?,
:experimental_search_menu_groups_enabled?
:new_new_view_enabled?
delegate :user_stat, to: :object, private: true
delegate :any_posts, :draft_count, :pending_posts_count, :read_faq?, to: :user_stat

View File

@ -2490,7 +2490,6 @@ en:
experimental_new_new_view_groups: 'EXPERIMENTAL: Enable a new topics list that combines unread and new topics and make the "Everything" link in the sidebar link to it.'
enable_custom_sidebar_sections: "EXPERIMENTAL: Enable custom sidebar sections"
experimental_topics_filter: "EXPERIMENTAL: Enables the experimental topics filter route at /filter"
experimental_search_menu_groups: "EXPERIMENTAL: Enables the new search menu that has been upgraded to use glimmer"
enable_experimental_lightbox: "EXPERIMENTAL: Replace the default image lightbox with the revamped design."
experimental_form_templates: "EXPERIMENTAL: Enable the form templates feature. <b>After enabled,</b> manage the templates at <a href='%{base_path}/admin/customize/form-templates'>Customize / Templates</a>."

View File

@ -2281,12 +2281,10 @@ developer:
experimental_topics_filter:
client: true
default: false
experimental_search_menu_groups:
type: group_list
list_type: compact
default: ""
allow_any: false
refresh: true
experimental_search_menu:
client: true
hidden: true
default: true
max_sidebar_section_links:
default: 50
hidden: true