DEV: Use `modifyClass` instead of `reopen` (#615)

This commit is contained in:
Jarek Radosz 2025-01-21 11:37:29 +01:00 committed by GitHub
parent 8c52b9a31c
commit 3f3b602cea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 32 additions and 29 deletions

View File

@ -4,7 +4,6 @@ import { htmlSafe } from "@ember/template";
import { isEmpty } from "@ember/utils";
import { hbs } from "ember-cli-htmlbars";
import { h } from "virtual-dom";
import SearchAdvancedOptions from "discourse/components/search-advanced-options";
import { renderAvatar } from "discourse/helpers/user-avatar";
import { withPluginApi } from "discourse/lib/plugin-api";
import { registerTopicFooterDropdown } from "discourse/lib/register-topic-footer-dropdown";
@ -816,35 +815,39 @@ export default {
return;
}
const currentUser = container.lookup("service:current-user");
if (currentUser?.can_assign) {
SearchAdvancedOptions.reopen({
updateSearchTermForAssignedUsername() {
const match = this.filterBlocks(REGEXP_USERNAME_PREFIX);
const userFilter = this.searchedTerms?.assigned;
let searchTerm = this.searchTerm || "";
let keyword = "assigned";
if (userFilter?.length !== 0) {
if (match.length !== 0) {
searchTerm = searchTerm.replace(
match[0],
`${keyword}:${userFilter}`
);
} else {
searchTerm += ` ${keyword}:${userFilter}`;
}
this._updateSearchTerm(searchTerm);
} else if (match.length !== 0) {
searchTerm = searchTerm.replace(match[0], "");
this._updateSearchTerm(searchTerm);
}
},
});
}
withPluginApi("1.34.0", (api) => {
const currentUser = container.lookup("service:current-user");
if (currentUser?.can_assign) {
api.modifyClass(
"component:search-advanced-options",
(Superclass) =>
class extends Superclass {
updateSearchTermForAssignedUsername() {
const match = this.filterBlocks(REGEXP_USERNAME_PREFIX);
const userFilter = this.searchedTerms?.assigned;
let searchTerm = this.searchTerm || "";
let keyword = "assigned";
if (userFilter?.length !== 0) {
if (match.length !== 0) {
searchTerm = searchTerm.replace(
match[0],
`${keyword}:${userFilter}`
);
} else {
searchTerm += ` ${keyword}:${userFilter}`;
}
this._updateSearchTerm(searchTerm);
} else if (match.length !== 0) {
searchTerm = searchTerm.replace(match[0], "");
this._updateSearchTerm(searchTerm);
}
}
}
);
}
extendTopicModel(api);
initialize(api);
registerTopicFooterButtons(api);