Skip to content

A platform for community discussion. Free, open, simple.

UX: add submenu for post bookmarks (#39172)

Same019b9784062
diff --git a/app/assets/stylesheets/common/base/topic-footer.scss b/app/assets/stylesheets/common/base/topic-footer.scss
index 11e4e40765c..d28b1d56faf 100644
--- a/app/assets/stylesheets/common/base/topic-footer.scss
+++ b/app/assets/stylesheets/common/base/topic-footer.scss
@@ -52,10 +52,15 @@
}
.bookmark.bookmarked {
- .d-icon-discourse-bookmark-clock,
- .d-icon-bookmark {
+ .d-icon-discourse-bookmark-clock {
color: var(--tertiary);
}
+
+ &:not(.--post-bookmarked-only) {
+ .d-icon-bookmark {
+ color: var(--tertiary);
+ }
+ }
}
.create {
diff --git a/app/assets/stylesheets/common/components/bookmark-menu.scss b/app/assets/stylesheets/common/components/bookmark-menu.scss
index db29a222a58..4c8617f6f9e 100644
--- a/app/assets/stylesheets/common/components/bookmark-menu.scss
+++ b/app/assets/stylesheets/common/components/bookmark-menu.scss
@@ -71,6 +71,13 @@
max-width: 35ch;
}
+ .--post-bookmark {
+ .d-button__suffix-icon {
+ margin-left: auto;
+ color: var(--primary-medium);
+ }
+ }
+
.bookmark-menu__section-title {
display: flex;
align-items: center;
diff --git a/frontend/discourse/app/components/topic-bookmark-post-submenu.gjs b/frontend/discourse/app/components/topic-bookmark-post-submenu.gjs
new file mode 100644
index 00000000000..a1438e55f0c
--- /dev/null
+++ b/frontend/discourse/app/components/topic-bookmark-post-submenu.gjs
@@ -0,0 +1,73 @@
+import Component from "@glimmer/component";
+import { action } from "@ember/object";
+import DButton from "discourse/components/d-button";
+import DropdownMenu from "discourse/components/dropdown-menu";
+import { i18n } from "discourse-i18n";
+
+export default class TopicBookmarkPostSubmenu extends Component {
+ get bookmark() {
+ return this.args.data.bookmark;
+ }
+
+ @action
+ jumpToPost() {
+ this.args.close();
+ this.args.data.onJumpToPost(this.bookmark);
+ }
+
+ @action
+ editBookmark() {
+ this.args.close();
+ this.args.data.onEditPostBookmark(this.bookmark);
+ }
+
+ @action
+ deleteBookmark() {
+ this.args.close();
+ this.args.data.onRemoveBookmark(this.bookmark);
+ }
+
+ <template>
+ <DropdownMenu class="topic-bookmark-post-submenu" as |dropdown|>
+ <dropdown.item
+ class="bookmark-menu__row --jump"
+ data-menu-option-id="jump"
+ >
+ <DButton
+ @icon="arrow-right"
+ @action={{this.jumpToPost}}
+ class="bookmark-menu__row-btn"
+ >
+ <span class="bookmark-menu__row-label">
+ {{i18n
+ "bookmarks.jump_to_post"
+ post_number=this.bookmark.post_number
+ }}
+ </span>
+ </DButton>
+ </dropdown.item>
+ <dropdown.item
+ class="bookmark-menu__row --edit"
+ data-menu-option-id="edit"
+ >
+ <DButton
+ @icon="pencil"
+ @label="edit"
+ @action={{this.editBookmark}}
+ class="bookmark-menu__row-btn"
+ />
+ </dropdown.item>
+ <dropdown.item
+ class="bookmark-menu__row --remove"
+ data-menu-option-id="delete"
+ >
+ <DButton
+ @icon="trash-can"
+ @label="delete"
+ @action={{this.deleteBookmark}}
+ class="bookmark-menu__row-btn --danger"
+ />
+ </dropdown.item>
+ </DropdownMenu>
+ </template>
+}
diff --git a/frontend/discourse/app/components/topic-bookmarks-menu.gjs b/frontend/discourse/app/components/topic-bookmarks-menu.gjs
index 669e48415d7..df2217dc3e1 100644
--- a/frontend/discourse/app/components/topic-bookmarks-menu.gjs
+++ b/frontend/discourse/app/components/topic-bookmarks-menu.gjs
@@ -1,5 +1,4 @@
import Component from "@glimmer/component";
-import { fn } from "@ember/helper";
import { action } from "@ember/object";
import { getOwner } from "@ember/owner";
import { service } from "@ember/service";
@@ -7,6 +6,7 @@ import BookmarkMenu from "discourse/components/bookmark-menu";
import DButton from "discourse/components/d-button";
import DropdownMenu from "discourse/components/dropdown-menu";
import BookmarkModal from "discourse/components/modal/bookmark";
+import TopicBookmarkPostSubmenu from "discourse/components/topic-bookmark-post-submenu";
import DMenu from "discourse/float-kit/components/d-menu";
import concatClass from "discourse/helpers/concat-class";
import { popupAjaxError } from "discourse/lib/ajax-error";
@@ -22,6 +22,7 @@ import { i18n } from "discourse-i18n";
export default class TopicBookmarksMenu extends Component {
@service modal;
+ @service menu;
@service dialog;
@service bookmarkApi;
@service toasts;
@@ -53,16 +54,6 @@ export default class TopicBookmarksMenu extends Component {
return this.hasPostBookmarks;
}
- get singlePostBookmark() {
- if (
- this.allBookmarks.length === 1 &&
- this.allBookmarks[0].bookmarkable_type === "Post"
- ) {
- return this.allBookmarks[0];
- }
- return null;
- }
-
get isMultipleBookmarks() {
return this.allBookmarks.length > 1;
}
@@ -90,6 +81,8 @@ export default class TopicBookmarksMenu extends Component {
return WITH_REMINDER_ICON;
} else if (this.topicBookmark) {
return NO_REMINDER_ICON;
+ } else if (this.hasPostBookmarks) {
+ return NO_REMINDER_ICON;
} else {
return NOT_BOOKMARKED;
}
@@ -134,6 +127,9 @@ export default class TopicBookmarksMenu extends Component {
if (this.allBookmarks.some((b) => b.reminder_at)) {
classes.push("with-reminder");
}
+ if (!this.topicBookmark) {
+ classes.push("--post-bookmarked-only");
+ }
}
return classes.join(" ");
@@ -144,6 +140,24 @@ export default class TopicBookmarksMenu extends Component {
this.dMenu = api;
}
+ @action
+ openPostBookmarkSubmenu(bookmark, event) {
+ this.menu.show(event.target.closest(".bookmark-menu__row-btn"), {
+ identifier: "topic-bookmark-post-submenu",
+ component: TopicBookmarkPostSubmenu,
+ modalForMobile: true,
+ placement: "right-start",
+ offset: { mainAxis: 10, crossAxis: -5 },
+ data: {
+ bookmark,
+ onJumpToPost: this.onJumpToPost,
+ onEditPostBookmark: this.onEditPostBookmark,
+ onRemoveBookmark: this.onRemoveBookmark,
+ },
+ onClose: () => this.dMenu.close(),
+ });
+ }
+
@action
async onJumpToPost(bookmark) {
await this.dMenu.close();
@@ -329,28 +343,31 @@ export default class TopicBookmarksMenu extends Component {
>
<:content>
<DropdownMenu as |dropdown|>
- {{! Post bookmark jump links }}
+ {{! Post bookmark submenu triggers }}
{{#each this.postBookmarks as |bookmark|}}
<dropdown.item
class={{concatClass
- "bookmark-menu__row --jump"
+ "bookmark-menu__row --post-bookmark"
(if bookmark.name "--has-name")
}}
- data-menu-option-id="jump"
+ data-menu-option-id="post-{{bookmark.post_number}}"
>
<DButton
@icon="bookmark"
+ @suffixIcon="angle-right"
@translatedAriaLabel={{i18n
- "bookmarks.jump_to_post"
+ "bookmarks.post_bookmark"
post_number=bookmark.post_number
}}
- @action={{fn this.onJumpToPost bookmark}}
- class="bookmark-menu__row-btn btn-transparent"
+ @actionParam={{bookmark}}
+ @action={{this.openPostBookmarkSubmenu}}
+ @forwardEvent={{true}}
+ class="bookmark-menu__row-btn"
>
<span class="bookmark-menu__row-texts">
<span class="bookmark-menu__row-label">
{{i18n
- "bookmarks.jump_to_post"
+ "bookmarks.post_bookmark"
post_number=bookmark.post_number
}}
</span>
@@ -364,30 +381,45 @@ export default class TopicBookmarksMenu extends Component {
</dropdown.item>
{{/each}}
- {{#if this.singlePostBookmark}}
- {{! Single post bookmark: edit + delete }}
+ {{! Topic bookmark actions }}
+ {{#if this.topicBookmark}}
+ <dropdown.divider />
<dropdown.item
- class="bookmark-menu__row -edit"
- data-menu-option-id="edit"
+ class={{concatClass
+ "bookmark-menu__row --edit"
+ (if this.topicBookmark.name "--has-name")
+ }}
+ data-menu-option-id="edit-topic-bookmark"
>
<DButton
@icon="pencil"
- @label="edit"
- @action={{fn this.onEditPostBookmark this.singlePostBookmark}}
- class="bookmark-menu__row-btn btn-transparent"
- />
+ @action={{this.onEditTopicBookmark}}
+ class="bookmark-menu__row-btn"
+ >
+ <span class="bookmark-menu__row-texts">
+ <span class="bookmark-menu__row-label">
+ {{i18n "bookmarks.edit_topic_bookmark"}}
+ </span>
+ {{#if this.topicBookmark.name}}
+ <span class="bookmark-menu__row-description">
+ {{this.topicBookmark.name}}
+ </span>
+ {{/if}}
+ </span>
+ </DButton>
</dropdown.item>
<dropdown.item
class="bookmark-menu__row --remove"
- data-menu-option-id="delete"
+ data-menu-option-id="delete-topic-bookmark"
>
<DButton
@icon="trash-can"
- @label="delete"
- @action={{fn this.onRemoveBookmark this.singlePostBookmark}}
+ @action={{this.onRemoveTopicBookmark}}
+ @label="bookmarks.delete_topic_bookmark"
class="bookmark-menu__row-btn --danger"
/>
</dropdown.item>
+ {{else}}
<dropdown.divider />
<dropdown.item
class="bookmark-menu__row --bookmark-topic"
@@ -397,62 +429,13 @@ export default class TopicBookmarksMenu extends Component {
@icon="bookmark"
@label="bookmarks.bookmark_topic"
@action={{this.onBookmarkTopic}}
- class="bookmark-menu__row-btn btn-transparent"
+ class="bookmark-menu__row-btn"
/>
</dropdown.item>
- {{else if this.isMultipleBookmarks}}
- {{! Multiple bookmarks: topic bookmark actions + delete all }}
- {{#if this.topicBookmark}}
- <dropdown.divider />
- <dropdown.item
- class={{concatClass
- "bookmark-menu__row -edit"
- (if this.topicBookmark.name "--has-name")
- }}
- data-menu-option-id="edit-topic-bookmark"
- >
- <DButton
- @icon="pencil"
- @action={{this.onEditTopicBookmark}}
- class="bookmark-menu__row-btn btn-transparent"
- >
- <span class="bookmark-menu__row-texts">
- <span class="bookmark-menu__row-label">
- {{i18n "bookmarks.edit_topic_bookmark"}}
- </span>
- {{#if this.topicBookmark.name}}
- <span class="bookmark-menu__row-description">
- {{this.topicBookmark.name}}
- </span>
- {{/if}}
- </span>
- </DButton>
- </dropdown.item>
- <dropdown.item
- class="bookmark-menu__row --remove"
- data-menu-option-id="delete-topic-bookmark"
- >
- <DButton
- @icon="trash-can"
- @action={{this.onRemoveTopicBookmark}}
- @label="bookmarks.delete_topic_bookmark"
- class="bookmark-menu__row-btn --danger"
- />
- </dropdown.item>
- {{else}}
- <dropdown.divider />
- <dropdown.item
- class="bookmark-menu__row --bookmark-topic"
- data-menu-option-id="bookmark-topic"
- >
- <DButton
- @icon="bookmark"
- @label="bookmarks.bookmark_topic"
- @action={{this.onBookmarkTopic}}
- class="bookmark-menu__row-btn btn-transparent"
- />
- </dropdown.item>
- {{/if}}
+ {{/if}}
+
+ {{! Delete all bookmarks }}
+ {{#if this.isMultipleBookmarks}}
<dropdown.divider />
<dropdown.item
class="bookmark-menu__row --remove"
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel-sidebar-context-menu.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-channel-sidebar-context-menu.gjs
index da299fc04e2..7640bf1ea7c 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-channel-sidebar-context-menu.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel-sidebar-context-menu.gjs
@@ -116,6 +116,7 @@ export default class ChatChannelSidebarContextMenu extends Component {
component: ChatChannelSidebarContextNotificationSubmenu,
modalForMobile: true,
placement: "right-start",
+ offset: { mainAxis: 10, crossAxis: -5 },
data: { channel: this.channel },
onClose: () => this.args.close(),
});
diff --git a/spec/system/bookmarks_spec.rb b/spec/system/bookmarks_spec.rb
index 5b46efd35fe..3c048ceaafc 100644
--- a/spec/system/bookmarks_spec.rb
+++ b/spec/system/bookmarks_spec.rb
@@ -146,7 +146,7 @@ describe "Bookmarking posts and topics" do
end
describe "topic footer bookmark button with post bookmarks" do
- it "shows jump/edit/delete for a single post bookmark" do
+ it "shows post bookmark with submenu for a single post bookmark" do
Fabricate(:bookmark, bookmarkable: post_2, user: current_user)
topic_page.visit_topic(topic)
@@ -155,9 +155,8 @@ describe "Bookmarking posts and topics" do
)
bookmark_menu.click_topic_bookmark_button
- expect(bookmark_menu).to have_jump_to_post_option(post_2.post_number)
- expect(page).to have_css(".topic-bookmarks-menu-content [data-menu-option-id='edit']")
- expect(page).to have_css(".topic-bookmarks-menu-content [data-menu-option-id='delete']")
+ expect(bookmark_menu).to have_post_bookmark_option(post_2.post_number)
+ expect(bookmark_menu).to have_bookmark_topic_option
end
it "shows plural label, correct tooltip, and grouped menu for multiple bookmarks" do
@@ -173,28 +172,32 @@ describe "Bookmarking posts and topics" do
)
bookmark_menu.click_topic_bookmark_button
- expect(bookmark_menu).to have_jump_to_post_option(post_2.post_number)
+ expect(bookmark_menu).to have_post_bookmark_option(post_2.post_number)
expect(bookmark_menu).to have_edit_topic_bookmark_option
expect(bookmark_menu).to have_delete_topic_bookmark_option
expect(bookmark_menu).to have_clear_all_option
end
- it "navigates to the bookmarked post when clicking jump" do
+ it "navigates to the bookmarked post via submenu" do
Fabricate(:bookmark, bookmarkable: post_2, user: current_user)
topic_page.visit_topic(topic)
bookmark_menu.click_topic_bookmark_button
- bookmark_menu.click_jump_to_post(post_2.post_number)
+ bookmark_menu.click_post_bookmark(post_2.post_number)
+ expect(bookmark_menu).to have_post_submenu
+ bookmark_menu.click_post_submenu_option("jump")
expect(page).to have_current_path(%r{/t/.*#{topic.id}/#{post_2.post_number}})
end
- it "deletes a single post bookmark from the footer menu" do
+ it "deletes a single post bookmark via submenu" do
Fabricate(:bookmark, bookmarkable: post_2, user: current_user)
topic_page.visit_topic(topic)
bookmark_menu.click_topic_bookmark_button
- bookmark_menu.click_menu_option("delete")
+ bookmark_menu.click_post_bookmark(post_2.post_number)
+ expect(bookmark_menu).to have_post_submenu
+ bookmark_menu.click_post_submenu_option("delete")
expect(topic_page).to have_no_bookmarks(topic)
expect(Bookmark.where(user: current_user, bookmarkable: post_2)).not_to exist
diff --git a/spec/system/page_objects/components/bookmark_menu.rb b/spec/system/page_objects/components/bookmark_menu.rb
index f713c41d1bc..9cddba6221c 100644
--- a/spec/system/page_objects/components/bookmark_menu.rb
+++ b/spec/system/page_objects/components/bookmark_menu.rb
@@ -31,20 +31,34 @@ module PageObjects
has_css?(".topic-bookmarks-menu-content")
end
- def has_jump_to_post_option?(post_number)
+ def has_post_bookmark_option?(post_number)
has_css?(
- ".topic-bookmarks-menu-content .bookmark-menu__row[data-menu-option-id='jump']",
- text: "##{post_number}",
+ ".topic-bookmarks-menu-content .bookmark-menu__row[data-menu-option-id='post-#{post_number}']",
)
end
- def click_jump_to_post(post_number)
+ def click_post_bookmark(post_number)
find(
- ".topic-bookmarks-menu-content .bookmark-menu__row[data-menu-option-id='jump']",
- text: "##{post_number}",
+ ".topic-bookmarks-menu-content .bookmark-menu__row[data-menu-option-id='post-#{post_number}']",
).click
end
+ def has_post_submenu?
+ has_css?(".topic-bookmark-post-submenu")
+ end
+
+ def click_post_submenu_option(option_id)
+ find(
+ ".topic-bookmark-post-submenu .bookmark-menu__row[data-menu-option-id='#{option_id}'] .btn",
+ ).click
+ end
+
+ def has_bookmark_topic_option?
+ has_css?(
+ ".topic-bookmarks-menu-content .bookmark-menu__row[data-menu-option-id='bookmark-topic']",
+ )
+ end
+
def has_clear_all_option?
has_css?(
".topic-bookmarks-menu-content .bookmark-menu__row[data-menu-option-id='clear-all']",