mirror of
https://github.com/discourse/discourse.git
synced 2025-05-26 12:05:25 +08:00
UX: multiple drafts menu improvements (#31195)
This change includes the following updates: - Rename view all to view all drafts - Remove view all link from drop-down when all drafts are displayed in the menu - Different icon for draft topics and PMs (adds envelope for PMs) - Disable drop-down when New Topic button is disabled (private categories etc) - Improve drafts drop-down loading (no longer disables the trigger btn on click)
This commit is contained in:
@ -18,6 +18,6 @@
|
|||||||
</DButtonTooltip>
|
</DButtonTooltip>
|
||||||
|
|
||||||
{{#if @showDrafts}}
|
{{#if @showDrafts}}
|
||||||
<TopicDraftsDropdown />
|
<TopicDraftsDropdown @disabled={{this.disabled}} />
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/if}}
|
{{/if}}
|
@ -7,6 +7,10 @@ import { or } from "truth-helpers";
|
|||||||
import DButton from "discourse/components/d-button";
|
import DButton from "discourse/components/d-button";
|
||||||
import DropdownMenu from "discourse/components/dropdown-menu";
|
import DropdownMenu from "discourse/components/dropdown-menu";
|
||||||
import DiscourseURL from "discourse/lib/url";
|
import DiscourseURL from "discourse/lib/url";
|
||||||
|
import {
|
||||||
|
NEW_PRIVATE_MESSAGE_KEY,
|
||||||
|
NEW_TOPIC_KEY,
|
||||||
|
} from "discourse/models/composer";
|
||||||
import { i18n } from "discourse-i18n";
|
import { i18n } from "discourse-i18n";
|
||||||
import DMenu from "float-kit/components/d-menu";
|
import DMenu from "float-kit/components/d-menu";
|
||||||
|
|
||||||
@ -35,6 +39,20 @@ export default class TopicDraftsDropdown extends Component {
|
|||||||
: "";
|
: "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
draftIcon(item) {
|
||||||
|
if (item.draft_key.startsWith(NEW_TOPIC_KEY)) {
|
||||||
|
return "layer-group";
|
||||||
|
} else if (item.draft_key.startsWith(NEW_PRIVATE_MESSAGE_KEY)) {
|
||||||
|
return "envelope";
|
||||||
|
} else {
|
||||||
|
return "reply";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get showViewAll() {
|
||||||
|
return this.draftCount > DRAFTS_LIMIT;
|
||||||
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
onRegisterApi(api) {
|
onRegisterApi(api) {
|
||||||
this.dMenu = api;
|
this.dMenu = api;
|
||||||
@ -42,6 +60,10 @@ export default class TopicDraftsDropdown extends Component {
|
|||||||
|
|
||||||
@action
|
@action
|
||||||
async onShowMenu() {
|
async onShowMenu() {
|
||||||
|
if (this.loading) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -82,7 +104,7 @@ export default class TopicDraftsDropdown extends Component {
|
|||||||
@onShow={{this.onShowMenu}}
|
@onShow={{this.onShowMenu}}
|
||||||
@onRegisterApi={{this.onRegisterApi}}
|
@onRegisterApi={{this.onRegisterApi}}
|
||||||
@modalForMobile={{true}}
|
@modalForMobile={{true}}
|
||||||
@disabled={{this.loading}}
|
@disabled={{@disabled}}
|
||||||
class="btn-small btn-default"
|
class="btn-small btn-default"
|
||||||
>
|
>
|
||||||
<:content>
|
<:content>
|
||||||
@ -91,7 +113,7 @@ export default class TopicDraftsDropdown extends Component {
|
|||||||
<dropdown.item class="topic-drafts-item">
|
<dropdown.item class="topic-drafts-item">
|
||||||
<DButton
|
<DButton
|
||||||
@action={{fn this.resumeDraft draft}}
|
@action={{fn this.resumeDraft draft}}
|
||||||
@icon={{if draft.topic_id "reply" "layer-group"}}
|
@icon={{this.draftIcon draft}}
|
||||||
@translatedLabel={{or
|
@translatedLabel={{or
|
||||||
draft.title
|
draft.title
|
||||||
(i18n "drafts.dropdown.untitled")
|
(i18n "drafts.dropdown.untitled")
|
||||||
@ -101,20 +123,22 @@ export default class TopicDraftsDropdown extends Component {
|
|||||||
</dropdown.item>
|
</dropdown.item>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
||||||
<dropdown.divider />
|
{{#if this.showViewAll}}
|
||||||
|
<dropdown.divider />
|
||||||
|
|
||||||
<dropdown.item>
|
<dropdown.item>
|
||||||
<DButton
|
<DButton
|
||||||
@href="/my/activity/drafts"
|
@href="/my/activity/drafts"
|
||||||
@model={{this.currentUser}}
|
@model={{this.currentUser}}
|
||||||
class="btn-link view-all-drafts"
|
class="btn-link view-all-drafts"
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
data-other-drafts={{this.otherDraftsCount}}
|
data-other-drafts={{this.otherDraftsCount}}
|
||||||
>{{this.otherDraftsText}}</span>
|
>{{this.otherDraftsText}}</span>
|
||||||
<span>{{i18n "drafts.dropdown.view_all"}}</span>
|
<span>{{i18n "drafts.dropdown.view_all"}}</span>
|
||||||
</DButton>
|
</DButton>
|
||||||
</dropdown.item>
|
</dropdown.item>
|
||||||
|
{{/if}}
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
</:content>
|
</:content>
|
||||||
</DMenu>
|
</DMenu>
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
.topic-drafts-menu-content .dropdown-menu {
|
.topic-drafts-menu-content .dropdown-menu {
|
||||||
max-width: 300px;
|
max-width: 350px;
|
||||||
|
min-width: 275px;
|
||||||
}
|
}
|
||||||
|
@ -500,7 +500,7 @@ en:
|
|||||||
dropdown:
|
dropdown:
|
||||||
title: "Open the latest drafts menu"
|
title: "Open the latest drafts menu"
|
||||||
untitled: "Untitled draft"
|
untitled: "Untitled draft"
|
||||||
view_all: "view all"
|
view_all: "view all drafts"
|
||||||
other_drafts:
|
other_drafts:
|
||||||
one: "+%{count} other draft"
|
one: "+%{count} other draft"
|
||||||
other: "+%{count} other drafts"
|
other: "+%{count} other drafts"
|
||||||
|
@ -64,5 +64,57 @@ describe "Drafts dropdown", type: :system do
|
|||||||
expect(drafts_dropdown.draft_item_count).to eq(4)
|
expect(drafts_dropdown.draft_item_count).to eq(4)
|
||||||
expect(drafts_dropdown.other_drafts_count).to eq(1)
|
expect(drafts_dropdown.other_drafts_count).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "shows the view all drafts when there are other drafts to display" do
|
||||||
|
page.visit "/"
|
||||||
|
drafts_dropdown.open
|
||||||
|
|
||||||
|
expect(drafts_dropdown).to be_open
|
||||||
|
expect(drafts_dropdown).to have_view_all_link
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not show the view all drafts link when all drafts are displayed" do
|
||||||
|
Draft.where(user_id: user.id).order("created_at DESC").limit(2).destroy_all
|
||||||
|
|
||||||
|
page.visit "/"
|
||||||
|
drafts_dropdown.open
|
||||||
|
|
||||||
|
expect(drafts_dropdown).to be_open
|
||||||
|
expect(drafts_dropdown).to have_no_view_all_link
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "with private category" do
|
||||||
|
fab!(:group)
|
||||||
|
fab!(:group_user) { Fabricate(:group_user, user: user, group: group) }
|
||||||
|
fab!(:category) { Fabricate(:private_category, group: group, permission_type: 3) }
|
||||||
|
fab!(:subcategory) do
|
||||||
|
Fabricate(
|
||||||
|
:private_category,
|
||||||
|
parent_category_id: category.id,
|
||||||
|
group: group,
|
||||||
|
permission_type: 1,
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:category_page) { PageObjects::Pages::Category.new }
|
||||||
|
|
||||||
|
before do
|
||||||
|
SiteSetting.default_subcategory_on_read_only_category = false
|
||||||
|
|
||||||
|
Draft.set(
|
||||||
|
user,
|
||||||
|
Draft::NEW_TOPIC,
|
||||||
|
0,
|
||||||
|
{ title: "This is a test topic", reply: "Lorem ipsum dolor sit amet" }.to_json,
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "disables the drafts dropdown menu when new topic button is disabled" do
|
||||||
|
category_page.visit(category)
|
||||||
|
|
||||||
|
expect(category_page).to have_button("New Topic", disabled: true)
|
||||||
|
expect(drafts_dropdown).to be_disabled
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -13,6 +13,10 @@ module PageObjects
|
|||||||
has_no_css?(MENU_SELECTOR + "-trigger")
|
has_no_css?(MENU_SELECTOR + "-trigger")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def disabled?
|
||||||
|
find(MENU_SELECTOR + "-trigger")["disabled"]
|
||||||
|
end
|
||||||
|
|
||||||
def open?
|
def open?
|
||||||
has_css?(MENU_SELECTOR + "-content")
|
has_css?(MENU_SELECTOR + "-content")
|
||||||
end
|
end
|
||||||
@ -21,6 +25,14 @@ module PageObjects
|
|||||||
has_no_css?(MENU_SELECTOR + "-content")
|
has_no_css?(MENU_SELECTOR + "-content")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_view_all_link?
|
||||||
|
has_css?(MENU_SELECTOR + "-content .view-all-drafts")
|
||||||
|
end
|
||||||
|
|
||||||
|
def has_no_view_all_link?
|
||||||
|
has_no_css?(MENU_SELECTOR + "-content .view-all-drafts")
|
||||||
|
end
|
||||||
|
|
||||||
def open
|
def open
|
||||||
find(MENU_SELECTOR + "-trigger").click
|
find(MENU_SELECTOR + "-trigger").click
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user