Add a Notes section in the Dashboard Activity widget - #13076
Conversation
…p into ticket/65890
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
WP_Comment exposes its columns as strings, so passing comment_post_ID straight to _draft_or_post_title() and get_edit_post_link() fails static analysis. It also repeated an error pattern the PHPStan baseline records once for the comments widget, pushing that entry out of date.
…p into ticket/65890
Tallying the open notes of the displayed posts loaded every one of those notes just to count rows, an unbounded query on a busy post. Query each post's count instead, which returns a single value and skips priming the comment and meta caches.
Covers the edit link, the post title and its placeholder, escaping, the open note count and its singular and plural forms, and the relative date each row ends with, including its use of the timezone of the site. The dashboard had no test coverage of its own before this.
…old. A note is created on hold and is approved when it is resolved, so the row tests now create their notes the way the editor does. Adds coverage of the listing itself: the open note count, which posts are listed and in what order, and the exclusion of resolved threads, replies and regular comments.
The section queried the notes that start a thread and dated each post by one of those, so a thread opened weeks ago and replied to this morning was dated weeks ago, and sorted below a thread nobody had touched since it was opened. Query replies too, and date each post by the most recent note or reply in a thread that is still open. Resolving a thread approves the note that starts it while its replies stay on hold, so the thread a reply belongs to is checked before the reply counts as activity. The threads are primed in one query per page rather than fetched one at a time. Also pass 'orderby' => 'none' to the open note counts, which do not need the ordering, matching get_comment_count().
|
Working on this a few points emerged:
|
Notes are only listed for posts the current user can edit, so a user who can edit none of them paged through every open note on the site, one query per page. Stop paging once a hundred notes per row have been examined, and prime the posts the capability checks load while skipping the note meta they never read.
The row put the post title in the narrow first column the sibling sections use for the date, so a title of any length wrapped while the open note count stretched across the free space. Render the date first, the title in the column that grows, and the count last, and drop a duplicated block of rules left over from an earlier iteration. Skip a row whose post no longer has an edit link along the way, as esc_url() is passed null for a post deleted since the notes were queried.
|
I had Claude review the branch, and pushed what it turned up: Two commits, both on top of the existing work here. d4d4678 bounds the paging loop. Notes are only listed for posts the current user can edit, so a user who can edit none of them - a Subscriber, or an Author on a multi-author site - never satisfied the c8c9b7f is the row layout. The markup was Tests came along with each: the paging bound, the edit link guard, and the two row helpers that read the date out of the markup. One review note that turned out to be a non-issue, for the record: @mcrisp1972 does the date-first row order look right to you? Happy to put it back if you had a reason for leading with the title. |
@adamsilverstein , Jen
@adamsilverstein , this is looking good. Regarding the ordering of row date and title, Jen and @aosmichenko built out the rows, so we might want their input on that, but I think the date first makes sense, especially if that is the sorted field. |
|
I was initially thinking of making "time ago" format, so if you would rather do that instead. I have no hard preferences on the format and column order, was trying to find the most useful to read. |
I like the human readable time ago format, we use that for most user facing dates. |
Review on the PR favored the relative "time ago" format over the Today/Tomorrow/date wording, matching how most user facing dates are shown elsewhere in the admin, such as the Media list table and the revisions screen. Compute the difference from the GMT date of the note so it is correct in any site timezone, which also removes the dead branch guarding a non-integer timestamp: get_comment_date( 'U' ) always returned one. The separate clock time is dropped because the difference already carries it, taking the '%1$s, %2$s' join and the date format strings out of the translation catalog. The row markup keeps its shape, so the column layout and dashboard.css are unchanged.
We are adding notes posted to blocks in the editor to the Recent Activity widget in the admin dashboard.
Trac ticket: https://core.trac.wordpress.org/ticket/65890
Testing
Tool to create many notes: https://github.com/t-hamano/notes-data-generator
https://playground.wordpress.net/wordpress.html?pr=13076
Screenshot
More screenshots
Claude seeded a site with notes and captured the widget in each state:
The test site has six posts carrying note threads: several threads have replies, some threads are resolved, one post has every thread resolved, and one post belongs to another author.
The Activity widget with five posts that have open notes. Each row links to the post, counts the open threads on it, and is dated by the newest note or reply on that post, in the same date, title, count order the sections above it use.
Where those counts come from. The same post in the editor: four open threads, two of them with replies, and the resolved threads below the divider. The dashboard reads "4 open notes" for it.
Eight more states
A post with one open thread uses the singular string.
Every thread resolved on every post, so the Notes section is not rendered at all and the rest of the widget is unchanged.
A thread replied to minutes ago on a six-day-old note sorts to the top, dated by the reply rather than by the note that opened the thread.
Dates across the year: today, earlier this year, and last year, which picks up the year.
Long titles, a post with 24 open notes, and an untitled draft in the same list.
Signed in as an author who can only edit their own post: the posts they cannot edit drop out of the list, notes and all.
At 420px wide, the date and the count hold their columns and the title wraps into what is left.
The whole dashboard for context.