Skip to content

DEV: Remove the legacy widget post menu code #650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .discourse-compatibility
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
< 3.5.0.beta2-dev: bf2a4bdb3ea4e26ec493d8dbc1f4cc8680f6c543
< 3.5.0.beta1-dev: 698b5be85cc1a31707d528fe0d3c3c07c939c1df
< 3.4.0.beta4-dev: 654f197003f9cdf1926b07137fc2214b21c91a79
< 3.4.0.beta3-dev: 6472f4593e1a4abbb457288db012ddb10f0b16f5
Expand Down
25 changes: 9 additions & 16 deletions assets/javascripts/discourse/components/assign-button.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ export default class AssignButton extends Component {
}

@action
acceptAnswer() {
async acceptAnswer() {
if (this.isAssigned) {
unassignPost(this.args.post, this.taskActions);
const post = this.args.post;

await this.taskActions.unassign(post.id, "Post");
delete post.topic.indirectly_assigned_to[post.id];
} else {
assignPost(this.args.post, this.taskActions);
this.taskActions.showAssignModal(this.args.post, {
isAssigned: false,
targetType: "Post",
});
}
}

Expand All @@ -51,16 +57,3 @@ export default class AssignButton extends Component {
/>
</template>
}

// TODO (glimmer-post-menu): Remove these exported functions and move the code into the button action after the widget code is removed
export function assignPost(post, taskActions) {
taskActions.showAssignModal(post, {
isAssigned: false,
targetType: "Post",
});
}

export async function unassignPost(post, taskActions) {
await taskActions.unassign(post.id, "Post");
delete post.topic.indirectly_assigned_to[post.id];
}
49 changes: 2 additions & 47 deletions assets/javascripts/discourse/initializers/extend-for-assigns.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { hbs } from "ember-cli-htmlbars";
import { h } from "virtual-dom";
import { renderAvatar } from "discourse/helpers/user-avatar";
import discourseComputed from "discourse/lib/decorators";
import { withSilencedDeprecations } from "discourse/lib/deprecated";
import getURL from "discourse/lib/get-url";
import { iconHTML, iconNode } from "discourse/lib/icon-library";
import { withPluginApi } from "discourse/lib/plugin-api";
Expand All @@ -16,10 +15,7 @@ import { escapeExpression } from "discourse/lib/utilities";
import RawHtml from "discourse/widgets/raw-html";
import RenderGlimmer from "discourse/widgets/render-glimmer";
import { i18n } from "discourse-i18n";
import AssignButton, {
assignPost,
unassignPost,
} from "../components/assign-button";
import AssignButton from "../components/assign-button";
import BulkActionsAssignUser from "../components/bulk-actions/bulk-assign-user";
import EditTopicAssignments from "../components/modal/edit-topic-assignments";
import TopicLevelAssignMenu from "../components/topic-level-assign-menu";
Expand Down Expand Up @@ -778,7 +774,7 @@ function initialize(api) {
}

function customizePostMenu(api) {
const transformerRegistered = api.registerValueTransformer(
api.registerValueTransformer(
"post-menu-buttons",
({
value: dag,
Expand All @@ -804,47 +800,6 @@ function customizePostMenu(api) {
);
}
);

const silencedKey =
transformerRegistered && "discourse.post-menu-widget-overrides";

withSilencedDeprecations(silencedKey, () => customizeWidgetPostMenu(api));
}

function customizeWidgetPostMenu(api) {
api.addPostMenuButton("assign", (post) => {
if (post.firstPost) {
return;
}
if (post.assigned_to_user || post.assigned_to_group) {
return {
action: "unassignPost",
icon: "user-xmark",
className: "unassign-post",
title: "discourse_assign.unassign_post.title",
position:
post.assigned_to_user?.id === api.getCurrentUser().id
? "first"
: "second-last-hidden",
};
} else {
return {
action: "assignPost",
icon: "user-plus",
className: "assign-post",
title: "discourse_assign.assign_post.title",
position: "second-last-hidden",
};
}
});

api.attachWidgetAction("post", "assignPost", function () {
assignPost(this.model, getOwner(this).lookup("service:task-actions"));
});

api.attachWidgetAction("post", "unassignPost", function () {
unassignPost(this.model, getOwner(this).lookup("service:task-actions"));
});
}

const REGEXP_USERNAME_PREFIX = /^(assigned:)/gi;
Expand Down
8 changes: 2 additions & 6 deletions test/javascripts/acceptance/assign-enabled-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import selectKit from "discourse/tests/helpers/select-kit-helper";
acceptance("Discourse Assign | Assign mobile", function (needs) {
needs.user();
needs.mobileView();
needs.settings({ glimmer_post_menu_mode: "enabled", assign_enabled: true });
needs.settings({ assign_enabled: true });

needs.pretender((server, helper) => {
server.get("/assign/suggestions", () => {
Expand Down Expand Up @@ -47,7 +47,7 @@ acceptance("Discourse Assign | Assign mobile", function (needs) {

acceptance("Discourse Assign | Assign desktop", function (needs) {
needs.user({ can_assign: true });
needs.settings({ glimmer_post_menu_mode: "enabled", assign_enabled: true });
needs.settings({ assign_enabled: true });

needs.pretender((server, helper) => {
server.get("/assign/suggestions", () => {
Expand Down Expand Up @@ -121,7 +121,6 @@ acceptance("Discourse Assign | Assign Status enabled", function (needs) {
can_assign: true,
});
needs.settings({
glimmer_post_menu_mode: "enabled",
assign_enabled: true,
enable_assign_status: true,
assign_statuses: "New|In Progress|Done",
Expand Down Expand Up @@ -184,7 +183,6 @@ acceptance("Discourse Assign | Assign Status disabled", function (needs) {
can_assign: true,
});
needs.settings({
glimmer_post_menu_mode: "enabled",
assign_enabled: true,
enable_assign_status: false,
});
Expand Down Expand Up @@ -245,7 +243,6 @@ const remindersFrequency = [
acceptance("Discourse Assign | User preferences", function (needs) {
needs.user({ can_assign: true, reminders_frequency: remindersFrequency });
needs.settings({
glimmer_post_menu_mode: "enabled",
assign_enabled: true,
remind_assigns_frequency: 43200,
});
Expand Down Expand Up @@ -292,7 +289,6 @@ acceptance(
function (needs) {
needs.user({ can_assign: true, reminders_frequency: remindersFrequency });
needs.settings({
glimmer_post_menu_mode: "enabled",
assign_enabled: true,
remind_assigns_frequency: 43200,
});
Expand Down
Loading