DEV: Remove old user menu related code (#464)

This commit is contained in:
Keegan George 2023-05-10 15:34:08 -07:00 committed by GitHub
parent afb54c7c1e
commit 310fb80e54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 230 deletions

View File

@ -4,7 +4,6 @@ import discourseComputed from "discourse-common/utils/decorators";
import { iconHTML, iconNode } from "discourse-common/lib/icon-library";
import { escapeExpression } from "discourse/lib/utilities";
import { h } from "virtual-dom";
import { queryRegistry } from "discourse/widgets/widget";
import { getOwner } from "discourse-common/lib/get-owner";
import { htmlSafe } from "@ember/template";
import getURL from "discourse-common/lib/get-url";
@ -658,24 +657,6 @@ function initialize(api) {
}
});
api.addUserMenuGlyph((widget) => {
if (widget.currentUser && widget.currentUser.can_assign) {
const glyph = {
label: "discourse_assign.assigned",
className: "assigned",
icon: "user-plus",
href: `${widget.currentUser.path}/activity/assigned`,
};
if (queryRegistry("quick-access-panel")) {
glyph["action"] = "quickAccess";
glyph["actionParam"] = "assignments";
}
return glyph;
}
});
api.createWidget("assigned-to", {
html(attrs) {
let { assignedToUser, assignedToGroup, href } = attrs;

View File

@ -1,15 +0,0 @@
import { iconNode } from "discourse-common/lib/icon-library";
import { DefaultNotificationItem } from "discourse/widgets/default-notification-item";
import { createWidgetFrom } from "discourse/widgets/widget";
createWidgetFrom(DefaultNotificationItem, "assigned-notification-item", {
icon(notificationName, data) {
if (data.message === "discourse_assign.assign_group_notification") {
return iconNode(
`notification.discourse_assign.assign_group_notification`
);
}
return iconNode(`notification.${notificationName}`);
},
});

View File

@ -1,75 +0,0 @@
import RawHtml from "discourse/widgets/raw-html";
import { iconHTML } from "discourse-common/lib/icon-library";
import {
createWidget,
createWidgetFrom,
queryRegistry,
} from "discourse/widgets/widget";
import getURL from "discourse-common/lib/get-url";
import { postUrl } from "discourse/lib/utilities";
import { h } from "virtual-dom";
import I18n from "I18n";
import { htmlSafe } from "@ember/template";
const ICON = "user-plus";
const GROUP_ICON = "group-plus";
createWidget("no-quick-access-assignments", {
html() {
return h("div.empty-state", [
h("span.empty-state-title", I18n.t("user.no_assignments_title")),
h(
"div.empty-state-body",
new RawHtml({
html:
"<p>" +
htmlSafe(
I18n.t("user.no_assignments_body", {
preferencesUrl: getURL("/my/preferences/notifications"),
icon: iconHTML(ICON),
})
) +
"</p>",
})
),
]);
},
});
const QuickAccessPanel = queryRegistry("quick-access-panel");
if (QuickAccessPanel) {
createWidgetFrom(QuickAccessPanel, "quick-access-assignments", {
buildKey: () => "quick-access-assignments",
emptyStateWidget: "no-quick-access-assignments",
showAllHref() {
return `${this.attrs.path}/activity/assigned`;
},
findNewItems() {
return this.store
.findFiltered("topicList", {
filter: `topics/messages-assigned/${this.currentUser.username_lower}`,
params: {
exclude_category_ids: [-1],
},
})
.then(({ topic_list }) => {
return topic_list.topics;
});
},
itemHtml(assignedTopic) {
return this.attach("quick-access-item", {
icon: assignedTopic.assigned_to_group ? GROUP_ICON : ICON,
href: postUrl(
assignedTopic.slug,
assignedTopic.id,
assignedTopic.last_read_post_number + 1
),
escapedContent: assignedTopic.fancy_title,
});
},
});
}

View File

@ -1,73 +0,0 @@
import { click, visit } from "@ember/test-helpers";
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
acceptance("Discourse Assign | Assignment notifications", function (needs) {
needs.user();
needs.settings({ assign_enabled: true, assigns_user_url_path: "/" });
needs.pretender((server, helper) => {
server.get("/notifications", () =>
helper.response({
notifications: [
{
id: 43,
user_id: 2,
notification_type: 34,
read: false,
high_priority: true,
created_at: "2022-01-01T12:00:00.000Z",
post_number: 1,
topic_id: 43,
fancy_title: "An assigned topic",
slug: "user-assigned-topic",
data: {
message: "discourse_assign.assign_notification",
display_username: "Username",
topic_title: "An assigned topic",
assignment_id: 4,
},
},
{
id: 42,
user_id: 2,
notification_type: 34,
read: false,
high_priority: true,
created_at: "2022-01-01T12:00:00.000Z",
post_number: 1,
topic_id: 42,
fancy_title: "A group assigned topic",
slug: "group-assigned-topic",
data: {
message: "discourse_assign.assign_group_notification",
display_username: "Groupname",
topic_title: "A group assigned topic",
assignment_id: 3,
},
},
],
seen_notification_id: 43,
})
);
});
test("Shows the right icons", async function (assert) {
await visit("/");
await click("#current-user.header-dropdown-toggle");
const userAssignment = query(".quick-access-panel li:nth-child(1) a");
assert.ok(
userAssignment
.querySelector(".d-icon")
.classList.contains("d-icon-user-plus")
);
const groupAssignment = query(".quick-access-panel li:nth-child(2) a");
assert.ok(
groupAssignment
.querySelector(".d-icon")
.classList.contains("d-icon-group-plus")
);
});
});

View File

@ -199,9 +199,12 @@ const USER_MENU_ASSIGN_RESPONSE = {
};
acceptance(
"Discourse Assign | experimental user menu | user cannot assign",
"Discourse Assign | user menu | user cannot assign",
function (needs) {
needs.user({ redesigned_user_menu_enabled: true, can_assign: false });
needs.user({
redesigned_user_menu_enabled: true, // TODO(@keegan): Remove after site setting is removed in core
can_assign: false,
});
needs.settings({
assign_enabled: true,
});
@ -215,9 +218,12 @@ acceptance(
);
acceptance(
"Discourse Assign | experimental user menu | assign_enabled setting is disabled",
"Discourse Assign | user menu | assign_enabled setting is disabled",
function (needs) {
needs.user({ redesigned_user_menu_enabled: true, can_assign: true });
needs.user({
redesigned_user_menu_enabled: true, // TODO(@keegan): Remove after site setting is removed in core
can_assign: false,
});
needs.settings({
assign_enabled: false,
});
@ -230,9 +236,9 @@ acceptance(
}
);
acceptance("Discourse Assign | experimental user menu", function (needs) {
acceptance("Discourse Assign | user menu", function (needs) {
needs.user({
redesigned_user_menu_enabled: true,
redesigned_user_menu_enabled: true, // TODO(@keegan): Remove after site setting is removed in core
can_assign: true,
grouped_unread_notifications: {
34: 173, // assigned notification type

View File

@ -1,42 +0,0 @@
import {
acceptance,
query,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
import { click, currentURL, visit } from "@ember/test-helpers";
import AssignedTopics from "../fixtures/assigned-topics-fixtures";
import { test } from "qunit";
acceptance(
"Discourse Assign | Quick access assignments panel",
function (needs) {
needs.user();
needs.settings({ assign_enabled: true, assigns_user_url_path: "/" });
needs.pretender((server, helper) => {
const messagesPath = "/topics/messages-assigned/eviltrout.json";
const assigns = AssignedTopics[messagesPath];
server.get(messagesPath, () => helper.response(assigns));
});
test("Quick access assignments panel", async function (assert) {
updateCurrentUser({ can_assign: true });
await visit("/");
await click("#current-user.header-dropdown-toggle");
await click(".widget-button.assigned");
const assignment = query(".quick-access-panel li a");
assert.ok(assignment.innerText.includes("Greetings!"));
assert.ok(assignment.href.includes("/t/greetings/10/5"));
await click(".widget-button.assigned");
assert.strictEqual(
currentURL(),
"/u/eviltrout/activity/assigned",
"a second click should redirect to the full assignments page"
);
});
}
);