Skip to content

Commit

Permalink
DEV: Use modifyClass instead of reopen (#615)
Browse files Browse the repository at this point in the history
  • Loading branch information
CvX authored Jan 21, 2025
1 parent 8c52b9a commit 3f3b602
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions assets/javascripts/discourse/initializers/extend-for-assigns.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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}`;
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);
}
}
}
);
}

this._updateSearchTerm(searchTerm);
} else if (match.length !== 0) {
searchTerm = searchTerm.replace(match[0], "");
this._updateSearchTerm(searchTerm);
}
},
});
}

withPluginApi("1.34.0", (api) => {
extendTopicModel(api);
initialize(api);
registerTopicFooterButtons(api);
Expand Down

0 comments on commit 3f3b602

Please sign in to comment.