Hiding dashboard cards: add context menus#20384
Conversation
| /// Only one of two types of action should be associated with the card. | ||
| /// Either ellipsis button tap, or view/header tap | ||
| private func assertOnTapRecognitionCorrectUsage() { | ||
| let bothTypesUsed = (onViewTap != nil || onHeaderTap != nil) && onEllipsisButtonTap != nil |
There was a problem hiding this comment.
These code removals from BlogDashboardCardFrameView are required for this change to work. Previously, setting both the onHeaderTap and onEllipsisButtonTap was unsupported. It is now.
The chevronImage and the iconImageView were removed during the recent dashboard card redesign
|
@kean Hey there. Just a nice to have idea here. Could we change the ellipsis icon to one from our new icon set? I've been holding off on asking, as we actually need to do this globally. But it will look so much better in this instance, and its a new introduction, that it would be nice to use the new ellipsis. It can be found here under more-horizontal-mobile https://www.npmjs.com/package/@wordpress/icons Or I'll attach an SVG below I've been using it with secondary label color like the below mock. If this is more than like 30-60mins work, then don't add it to the scope, I can get it done as part of another upcoming project |
|
Sure, it's a small change. I have a list of minor tweaks I need to make. I'll create a separate PR with these changes. |
staskus
left a comment
There was a problem hiding this comment.
Thanks for the work, @kean! I tested it, and the functionality works as described 👍
My biggest question is about the whole approach. Whether we take the same steps for every personalizable card or is it worth describing them once at a deeper level? Interested in your thoughts.
| } | ||
|
|
||
| private func addContextMenu(card: DashboardCard, blog: Blog) { | ||
| frameView.onEllipsisButtonTap = { |
There was a problem hiding this comment.
I'm curious about your thoughts.
Now every card from the new "Personalize Home Tab" screen has a "Hide this" button in the context menu.
I'm looking at each of the cells which repeat the same pattern of adding ellipsis button handling, hiding action, and tracking code.
Although duplication is not necessarily evil, I'm wondering if in this situation it makes and is possible to have something reused. To describe the card as "personalizable" and then it will share common these functionality and layout traits.
What do you think about that?
A couple more cards require special attention and will be made "personalizable" later.
Is this a counter-argument to my question and it's difficult to reuse the same layout and functionality code between personalizable cards?
There was a problem hiding this comment.
Thanks for bringing this up. I did add some reuse but didn't want to go as far as refactoring the existing cards:
- Creating a
UIActionto hide a card for new cards is fully reused - Tracking the hide action is also reused
But there is clearly some duplication in how the context menus get added:
if FeatureFlag.personalizeHomeTab.enabled {
frameView.onEllipsisButtonTap = {
BlogDashboardAnalytics.trackContextualMenuAccessed(for: .todaysStats)
}
frameView.ellipsisButton.showsMenuAsPrimaryAction = true
frameView.ellipsisButton.menu = UIMenu(title: "", options: .displayInline, children: [
BlogDashboardHelpers.makeHideCardAction(for: .todaysStats, siteID: blog.dotComID?.intValue ?? 0)
])
}I could make it reusable fairly easily:
extension DashboardStatsCardCell {
private func configureCard(for blog: Blog, in viewController: UIViewController) {
if FeatureFlag.personalizeHomeTab.enabled {
let menu = UIMenu(title: "", options: .displayInline, children: [
BlogDashboardHelpers.makeHideCardAction(for: .todaysStats, siteID: blog.dotComID?.intValue ?? 0)
])
frameView.setContextMenu(menu, card: .todaysStats)
}
// ...
}
}
extension BlogDashboardCardFrameView {
func setContextMenu(_ menu: UIMenu, card: DashboardCard) {
onEllipsisButtonTap = {
BlogDashboardAnalytics.trackContextualMenuAccessed(for: card)
}
ellipsisButton.showsMenuAsPrimaryAction = true
ellipsisButton.menu = menu
}
}This way, we'll remove the most obvious instances of duplication, and cards will retain complete control over how their menus are configured.
Should I make this change in this PR? I have some other ideas for refactoring this and also Dashboard.personalizableCards. I was going to open a new PR after getting the features merged first.
Ultimately, I'll want this "Hide this" action to appear automatically based on which cards are personalizable, but that sounds a bit overcomplicated. I do want to look into it a bit more.
There was a problem hiding this comment.
I also already used the same approach for adding the ellipsis in #20393, which is consistent with other cards. I think it'll make sense to update them all at once to make it easy to review/test.
There was a problem hiding this comment.
Thanks for the insightful answer and your examples! Those extensions look like good wins to take.
Should I make this change in this PR? I have some other ideas for refactoring this and also Dashboard.personalizableCards. I was going to open a new PR after getting the features merged first.
I think we could do that in other PRs as well. There are already a fair amount of changes, it will be easier to digest additional ones in a separate PR.
| static let bottomPadding: CGFloat = 8 | ||
| static let headerPaddingWithEllipsisButtonHidden = UIEdgeInsets(top: 12, left: 16, bottom: 8, right: 16) | ||
| static let headerPaddingWithEllipsisButtonShown = UIEdgeInsets(top: 12, left: 16, bottom: 8, right: 8) | ||
| static let headerPaddingWithEllipsisButtonShown = UIEdgeInsets(top: 4, left: 16, bottom: 0, right: 8) |
There was a problem hiding this comment.
I tested the changes on the latest trunk as I was interested in how these changes affect the latest development.
The top of 4 for a multiline label looks visually too close. It looks like a title label centers vertically together with the button. When we have a single-line label, the top of 4 looks fine, and 8 is too far.
There was a problem hiding this comment.
Thanks, good catch. I tested only with the existing cards, which are single-line. titleLabel.numberOfLines = 0 was just added to trunk this week.
I reverted this change for now. It's a production behavior, and I don't want this change to hold the main PRs. I'll think of a different way to implement it. I could do it using hitTest, then there won't be any layout changes.
There was a problem hiding this comment.
Thanks, retested it, looks okay now, although yes, now the button appears a bit too low, so this part as you mentioned could be improved. 👍
…all)" This reverts commit 60b88d8.
| * [***] [internal] Refactor uploading photos (from the device photo, the Free Photo library, and other sources) to the WordPress Media Library. Affected areas are where you can choose a photo and upload, including the "Media" screen, adding images to a post, updating site icon, etc. [#20322] | ||
| * [**] [WordPress-only] Warns user about sites with only individual plugins not supporting core app features and offers the option to switch to the Jetpack app. [#20408] | ||
| * [**] Add a "Personalize Home Tab" button to the bottom of the Home tab that allows changing cards visibility. [#20369] | ||
| * [**] Add context menus to "Drafts", "Scheduled Posts", and "Today's Stats" cards with an option to hide these cards. [#20384] |
There was a problem hiding this comment.
The cut-off for 22.1 is on Monday and the feature is still under the feature flag and development.
I think it's safer to move these notes to 22.2 and aim to enable those changes then.
Does that sound good?
CC: @guarani
staskus
left a comment
There was a problem hiding this comment.
✅ Looks good now!
As we discussed, let's leave potential refactoring and improved reusability for another PR so we could discuss it separately.
Head branch was pushed to by a user without write access
|
@staskus. There was another merge conflict. I fixed it, and it canceled the auto-merge. I'd appreciate it if you could re-run it. |


Related issue: #20296
Previous PRs (dependencies):
Changes
BlogDashboardAnalytics)Screenshots
Testing
Prerequisites
Test Case 1 (Draft Post)
Test Case 2 (Schedule Post)
Test Case 3 (Both)
Test Case 4 (Stats)
Test Case 5 (Stored Per-Site)
Test Case 6 (Regression)
Other Testing Notes:
BlogDashboardService.parseRegression Notes
Potential unintended areas of impact
This change affects primarily "Drafts," "Schedules Posts", and "Today's Stats" cards, but other dashboard cards were also affected. It must be verified that the context menu layout wasn't broken for other cards, such as Blaze.
What I did to test those areas of impact (or what existing automated tests I relied on)
Manual testing
What automated tests I added (or what prevented me from doing so)
n/a
PR submission checklist:
RELEASE-NOTES.txtif necessary.