DEV: Plugin API addQuickAccessProfileItem adds to revamped user menu (#21084)
This commit is contained in:
parent
2535381f44
commit
ae5aa0c79f
|
@ -120,6 +120,19 @@
|
||||||
</li>
|
</li>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
{{#each this.extraItems as |item|}}
|
||||||
|
<li class={{item.className}}>
|
||||||
|
<a href={{item.href}}>
|
||||||
|
{{#if item.icon}}
|
||||||
|
{{d-icon item.icon}}
|
||||||
|
{{/if}}
|
||||||
|
<span class="item-label">
|
||||||
|
{{item.content}}
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/each}}
|
||||||
|
|
||||||
<li class="logout">
|
<li class="logout">
|
||||||
<DButton
|
<DButton
|
||||||
@class="btn-flat profile-tab-btn"
|
@class="btn-flat profile-tab-btn"
|
||||||
|
|
|
@ -4,6 +4,16 @@ import { action } from "@ember/object";
|
||||||
import showModal from "discourse/lib/show-modal";
|
import showModal from "discourse/lib/show-modal";
|
||||||
import DoNotDisturb from "discourse/lib/do-not-disturb";
|
import DoNotDisturb from "discourse/lib/do-not-disturb";
|
||||||
|
|
||||||
|
const _extraItems = [];
|
||||||
|
|
||||||
|
export function addUserMenuProfileTabItem(item) {
|
||||||
|
_extraItems.push(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resetUserMenuProfileTabItems() {
|
||||||
|
_extraItems.clear();
|
||||||
|
}
|
||||||
|
|
||||||
export default class UserMenuProfileTabContent extends Component {
|
export default class UserMenuProfileTabContent extends Component {
|
||||||
@service currentUser;
|
@service currentUser;
|
||||||
@service siteSettings;
|
@service siteSettings;
|
||||||
|
@ -34,6 +44,10 @@ export default class UserMenuProfileTabContent extends Component {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get extraItems() {
|
||||||
|
return _extraItems;
|
||||||
|
}
|
||||||
|
|
||||||
get #doNotDisturbUntilDate() {
|
get #doNotDisturbUntilDate() {
|
||||||
if (!this.currentUser.get("do_not_disturb_until")) {
|
if (!this.currentUser.get("do_not_disturb_until")) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -72,6 +72,7 @@ import { addTopicParticipantClassesCallback } from "discourse/widgets/topic-map"
|
||||||
import { addTopicSummaryCallback } from "discourse/widgets/toggle-topic-summary";
|
import { addTopicSummaryCallback } from "discourse/widgets/toggle-topic-summary";
|
||||||
import { addTopicTitleDecorator } from "discourse/components/topic-title";
|
import { addTopicTitleDecorator } from "discourse/components/topic-title";
|
||||||
import { addUserMenuGlyph } from "discourse/widgets/user-menu";
|
import { addUserMenuGlyph } from "discourse/widgets/user-menu";
|
||||||
|
import { addUserMenuProfileTabItem } from "discourse/components/user-menu/profile-tab-content";
|
||||||
import { addUsernameSelectorDecorator } from "discourse/helpers/decorate-username-selector";
|
import { addUsernameSelectorDecorator } from "discourse/helpers/decorate-username-selector";
|
||||||
import { addWidgetCleanCallback } from "discourse/components/mount-widget";
|
import { addWidgetCleanCallback } from "discourse/components/mount-widget";
|
||||||
import deprecated from "discourse-common/lib/deprecated";
|
import deprecated from "discourse-common/lib/deprecated";
|
||||||
|
@ -1585,6 +1586,7 @@ class PluginApi {
|
||||||
**/
|
**/
|
||||||
addQuickAccessProfileItem(item) {
|
addQuickAccessProfileItem(item) {
|
||||||
addQuickAccessProfileItem(item);
|
addQuickAccessProfileItem(item);
|
||||||
|
addUserMenuProfileTabItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
addFeaturedLinkMetaDecorator(decorator) {
|
addFeaturedLinkMetaDecorator(decorator) {
|
||||||
|
|
|
@ -12,6 +12,10 @@ export function addQuickAccessProfileItem(item) {
|
||||||
_extraItems.push(item);
|
_extraItems.push(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function resetQuickAccessProfileItems() {
|
||||||
|
_extraItems.clear();
|
||||||
|
}
|
||||||
|
|
||||||
createWidgetFrom(QuickAccessItem, "logout-item", {
|
createWidgetFrom(QuickAccessItem, "logout-item", {
|
||||||
tagName: "li.logout",
|
tagName: "li.logout",
|
||||||
|
|
||||||
|
|
|
@ -667,6 +667,49 @@ acceptance("User menu", function (needs) {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("Extra items added to profile tab via plugin API are rendered properly", async function (assert) {
|
||||||
|
withPluginApi("0.1", (api) => {
|
||||||
|
api.addQuickAccessProfileItem({
|
||||||
|
className: "test-1-item",
|
||||||
|
icon: "wrench",
|
||||||
|
content: "test 1",
|
||||||
|
href: "/test_1_path",
|
||||||
|
});
|
||||||
|
|
||||||
|
api.addQuickAccessProfileItem({
|
||||||
|
className: "test-2-item",
|
||||||
|
content: "test 2",
|
||||||
|
href: "/test_2_path",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
await visit("/");
|
||||||
|
await click(".d-header-icons .current-user");
|
||||||
|
await click("#user-menu-button-profile");
|
||||||
|
|
||||||
|
const item1 = query("#quick-access-profile ul li.test-1-item");
|
||||||
|
|
||||||
|
assert.ok(
|
||||||
|
item1.querySelector(".d-icon-wrench"),
|
||||||
|
"The first item's icon is rendered"
|
||||||
|
);
|
||||||
|
assert.ok(
|
||||||
|
item1.querySelector("a").href.endsWith("/test_1_path"),
|
||||||
|
"The first item's link is present with correct href"
|
||||||
|
);
|
||||||
|
|
||||||
|
const item2 = query("#quick-access-profile ul li.test-2-item");
|
||||||
|
|
||||||
|
assert.notOk(
|
||||||
|
item2.querySelector(".d-icon"),
|
||||||
|
"The second item doesn't have an icon"
|
||||||
|
);
|
||||||
|
assert.ok(
|
||||||
|
item2.querySelector("a").href.endsWith("/test_2_path"),
|
||||||
|
"The second item's link is present with correct href"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test("the active tab can be clicked again to navigate to a page", async function (assert) {
|
test("the active tab can be clicked again to navigate to a page", async function (assert) {
|
||||||
updateCurrentUser({ reviewable_count: 1 });
|
updateCurrentUser({ reviewable_count: 1 });
|
||||||
withPluginApi("0.1", (api) => {
|
withPluginApi("0.1", (api) => {
|
||||||
|
|
|
@ -35,7 +35,9 @@ import { resetWidgetCleanCallbacks } from "discourse/components/mount-widget";
|
||||||
import { resetUserSearchCache } from "discourse/lib/user-search";
|
import { resetUserSearchCache } from "discourse/lib/user-search";
|
||||||
import { resetCardClickListenerSelector } from "discourse/mixins/card-contents-base";
|
import { resetCardClickListenerSelector } from "discourse/mixins/card-contents-base";
|
||||||
import { resetComposerCustomizations } from "discourse/models/composer";
|
import { resetComposerCustomizations } from "discourse/models/composer";
|
||||||
|
import { resetQuickAccessProfileItems } from "discourse/widgets/quick-access-profile";
|
||||||
import { resetQuickSearchRandomTips } from "discourse/widgets/search-menu-results";
|
import { resetQuickSearchRandomTips } from "discourse/widgets/search-menu-results";
|
||||||
|
import { resetUserMenuProfileTabItems } from "discourse/components/user-menu/profile-tab-content";
|
||||||
import sessionFixtures from "discourse/tests/fixtures/session-fixtures";
|
import sessionFixtures from "discourse/tests/fixtures/session-fixtures";
|
||||||
import {
|
import {
|
||||||
resetHighestReadCache,
|
resetHighestReadCache,
|
||||||
|
@ -179,8 +181,10 @@ export function testCleanup(container, app) {
|
||||||
resetHighestReadCache();
|
resetHighestReadCache();
|
||||||
resetCardClickListenerSelector();
|
resetCardClickListenerSelector();
|
||||||
resetComposerCustomizations();
|
resetComposerCustomizations();
|
||||||
|
resetQuickAccessProfileItems();
|
||||||
resetQuickSearchRandomTips();
|
resetQuickSearchRandomTips();
|
||||||
resetPostMenuExtraButtons();
|
resetPostMenuExtraButtons();
|
||||||
|
resetUserMenuProfileTabItems();
|
||||||
clearExtraKeyboardShortcutHelp();
|
clearExtraKeyboardShortcutHelp();
|
||||||
clearNavItems();
|
clearNavItems();
|
||||||
setTopicList(null);
|
setTopicList(null);
|
||||||
|
|
Loading…
Reference in New Issue