#25408 closed task (blessed) (fixed)
Ability to specify that a list table column is "primary"
Reported by: | helen | Owned by: | stephdau |
---|---|---|---|
Milestone: | 4.3 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Administration | Keywords: | |
Focuses: | Cc: |
Description
List tables have a "primary" column of sorts; that is, the one with the row actions. We should be able to specify which column is the primary one via API, apply an appropriate class, and display the row actions in cells in that column. Currently, developers customizing the list table columns often need to re-create row actions if they do not use the post name column, or just live with the row actions appearing in a less sensible spot.
This thought stems from three things in particular:
- The above customization example.
- Old experiments (nearly exactly 2 years ago) in making list tables responsive: http://cl.ly/3F1L0N3z1M0F0Z3t0X3W in #18198.
- The assortment of selectors in [25595] that are not particularly robust and not easily reused by developers. We should be able to target something like
.has-row-actions
instead.
Attachments (27)
Change History (122)
#3
@
11 years ago
EDIT:
Ok, I see I've misread the requirements. In any case, I've rectified that situation and attached a patch. Feedback is appreciated.
I made some mistakes in the first attachment, so please ignore it and use the second one .
In essence:
I've added two new methods to class WP_List_Table, both intended to be over-ridden, but not abstract:
- get_primary_column(): Takes no arguments, returns the name of the desired primary column. Hardcoded much the same way as get_columns, but just one string.
- handle_actions( $item, $column_name, $primary ): Takes three arguments: the item - whether post, user, comment, etc. - the current column_name, and the name of the primary column. If the column name matches the primary, then the function returns the actions to be displayed.
I've also modified the various list tables that display row actions to use this new functionality. Some have single_row over-ridden, some don't. Some override the row_actions function, others just directly created and displayed their row actions in the default primary. The latter ones are where I extracted that code to override handle_actions.
The only one I didn't touch was class-wp-links-list-table.php because I don't have the links manager plugin to test it with yet, so I left that one alone.
Here's a list of the files I modified, which will now have the class "has-row-actions" in the primary cells.
class-wp-comments-list-table.php
class-wp-list-table.php
class-wp-media-list-table.php
class-wp-ms-sites-list-table.php
class-wp-ms-themes-list-table.php
class-wp-ms-users-list-table.php
class-wp-plugins-list-table.php
class-wp-posts-list-table.php
class-wp-terms-list-table.php
class-wp-users-list-table.php
#7
@
11 years ago
- Keywords needs-refresh added; has-patch needs-testing removed
By looking at the patch and the current file I can say that the line numbers have changed a lot since the patch was uploaded. The code in the original files have changed too.
#10
@
10 years ago
- Type changed from task (blessed) to enhancement
A lot going on in the patch, late for 4.0 (as much as obviously I want this). Patch seems to be heading in a good direction. One thing I'm noticing is setting HTML classes - should append to the set if primary column, rather than if/else, so it's easier to follow. Places where it's echoed inline should probably be set to a variable first for clarity as well.
This ticket was mentioned in IRC in #wordpress-dev by helen. View the logs.
10 years ago
This ticket was mentioned in Slack in #design by helen. View the logs.
10 years ago
#17
@
10 years ago
@helen: Kept running with 25408.3.diff, as discussed on Slack, but it never got to dealing how a primary column is actually selected/changed. The user-level setting of primary column sounds like it should be a screen option paired with the current "Show on screen" one (lists shown/hidden columns when dealing with a list table).
This is where things get a bit complex.
- "Show on screen" is in
wp-admin/includes/screen.php
- That's JS-enabled so that what the user selects is rendered live
- Assuming the selection of the primary column would be a drop-down (preferred because of interactions below) or series of radio (meh, considering we list columns as checkboxes above) underneath that list of displayed columns
- We have to select the default in initial page load
- Then, if a user hides a column, it should be taken away from the primary columns list, live, and said list revert to its default (some special columns can't be hidden).
- Should be added back, live, if unhidden.
- In an ideal world, user shouldn't have to "apply" primary column change, it should be live too
What's your (and others') perspective on this?
#18
@
10 years ago
Result of chat session with Helen regarding previous comment:
- no UI, just programmatic column selection (ie: via filter)
- 1 generic filter, with context passed via arguments
- at least for "round 1"
That makes my day. Going with that.
#19
@
10 years ago
Here we go: 25408.4.diff:
- was rebuilt from scratch based on the previous patches, brings the code in line with trunk (4.3-alpha, r32551)
- builds upon the previous work: refactoring and based on ticket feedback
- adds a
list_table_primary_column
filter inWP_List_Table::get_primary_column_name()
, so developers can change the default column via the related API, with$default
(returnable) and$context
(screen id) as arguments (as requested).
#20
@
10 years ago
Noticing my IDE removed some of the whitespace around parenthesis and such (when I cut and pasted)... Will fix in a future patch. Code works the same, for testing.
#21
@
10 years ago
- sets the plugin column as being the default again (my mistake in prev patch)
- cleans up some whitespace issues in the previous patch (IDE auto-reformat on paste)
#22
follow-up:
↓ 23
@
10 years ago
Tested a bit the patch, thanks very much @stephdau :) Noticed a few things worth considering:
- small typo: for Posts/Pages the default primary column is set to "author"
- wouldn't be better to use
$this->screen->id
as dynamic portion of the hook name? - doing the above, would we really need to pass
$this->screen->id
as additional variable? - in /network/users.php the "Sites" column needs some special treatment, it needs the "has-row-actions" CSS class (links not revealed on focus see #31003 for reference)
- is it worth it to apply all this new stuff to Link Manager too?
- consider to update the selector in common.js
#23
in reply to:
↑ 22
;
follow-up:
↓ 24
@
10 years ago
Replying to afercia:
Tested a bit the patch, thanks very much @stephdau :)
Thank YOU, for the testing. :)
Added new patch: 25408.6.diff. See further info below below.
Noticed a few things worth considering:
- small typo: for Posts/Pages the default primary column is set to "author"
Fixed in new patch, thanks. Guess that was set to my last test. :)
- wouldn't be better to use
$this->screen->id
as dynamic portion of the hook name?- doing the above, would we really need to pass
$this->screen->id
as additional variable?
Personally, as a dev, I'd like both a generic with context as arg (as per prev patch), or one as you describe (context via dynamic hook name). I see value in both. Passing it as an arg is what @helen and I had decided for this round, but I'm not attached to either. See WP_List_Table::get_primary_column_name()
in new patch for an example of both, from which we can decide.
- in /network/users.php the "Sites" column needs some special treatment, it needs the "has-row-actions" CSS class (links not revealed on focus see #31003 for reference)
I can do that, but I don't understand what you mean. See https://cloudup.com/c5p3yXllT7K
- 1st screenshot is with
username
as primary, edit/view show on kb focus of blog url) - 2nd screenshot is with
blogs
as primary, edit/view also show next to url, then edit link (only action for user) shows underneath the blogs list.
- is it worth it to apply all this new stuff to Link Manager too?
Can do, so long as we're cool with the logic. I'd assume yes. Original patches I started from didn't address it, not sure why.
- consider to update the selector in common.js
I'm not sure what that really means per se. :) Could you apply the patch, make your change, add it to the patch, and submit it, so I can see?
Thanks.
#24
in reply to:
↑ 23
@
10 years ago
Replying to stephdau:
Personally, as a dev, I'd like both a generic with context as arg (as per prev patch), or one as you describe (context via dynamic hook name). I see value in both. Passing it as an arg is what @helen and I had decided for this round, but I'm not attached to either.
I'm not attached to either too :) just a bit concerned about consistency with other similar hooks noticing that they all have a dynamic hook name.
- in /network/users.php the "Sites" column needs some special treatment, it needs the "has-row-actions" CSS class (links not revealed on focus see #31003 for reference)
I can do that, but I don't understand what you mean.
One of the side goals of this ticket would be replacing in common.js that "terrible selectors pile" as @helen named it :) with just one CSS selector. See:
https://core.trac.wordpress.org/browser/tags/4.2/src/wp-admin/js/common.js#L481
should use as selector just ".has-row-actions". Once you do that, the edit/view links in the "Sites" column won't show on keyboard focus because that column is not the primary one and doesn't have a ".has-row-actions" class.
- consider to update the selector in common.js
I'm not sure what that really means per se.
See above :)
#25
@
10 years ago
In 25408.7.diff, I've replaced if ( $primary === $column_name ) {
by if ( $primary === $column_name || 'blogs' === $column_name ) {
(see L170-173 in src/wp-admin/includes/class-wp-ms-users-list-table.php
in patch), which will always apply has-row-actions
to the blogs/sites column.
The same update also bring the patch in line with the latest trunk.
#26
@
10 years ago
@helen: can you give us your opinion on the filter (context as argument, or context in dynamic hook name?)? See WP_List_Table::get_primary_column_name()
in patch.
Links list table: one of the comments above states "The only one I didn't touch was class-wp-links-list-table.php because I don't have the links manager plugin to test it with yet, so I left that one alone.", so now I know why it wasn't previously handled. Will add to future patch.
#27
@
10 years ago
25408.8.diff adds the same logic to src/wp-admin/includes/class-wp-links-list-table.php
.
Left:
- decide how we want the filter(s) to exist in
WP_List_Table::get_primary_column_name()
. - dealing with
wp-admin/js/common.js
if we want to do that here (I wouldn't,since it has its own ticket).
#28
@
10 years ago
25408.10.diff implements most of what @helen and I discussed on Slack:
- also adds
column-primary
when applyinghas-row-actions
, except for theblogs
column inWP_MS_Users_List_Table
, which needs the latter at all times, but not the former. - only implements a statically-named filter in
WP_List_Table::get_primary_column_name()
, with context as argument. Dynamically-named filters are needlessly difficult to document/use, and we don't really implement new ones.
One thing I did not do is renaming *::handle_row_actions()
to *::row_actions()
because they are both implemented in the parent class, are different enough (args, etc), and both are valuable as is. Opened to renaming it, just not to that.
Also switched WP_Comments_List_Table::handle_row_actions()
to return and not echo, for consistency.
#29
@
10 years ago
25408.11.diff updates the previously faulty logic for the column-primary
assignment in WP_MS_Users_List_Table
.
This ticket was mentioned in Slack in #design by stephdau. View the logs.
10 years ago
#36
in reply to:
↑ 34
@
10 years ago
Replying to helen:
woohoo!
I couldn't have said it better myself :) thanks very much stephdau, DaveAl, jesin, helen.
#37
@
10 years ago
afercia noted that this drops some special classes for the media image/icon column, but I'd like to get rid of that as a separate column anyway, see #29993 and #32254. Leaving a note here so that if we don't drop that column (which would make #32395 more difficult, so it's unlikely we won't do it), we add those classes back.
#38
follow-up:
↓ 39
@
10 years ago
Looks like we missed WP_Post_Comments_List_Table
- maybe because of the way it overrides get_column_info()
. See 25408.17.diff.
#39
in reply to:
↑ 38
@
10 years ago
Replying to boonebgorges:
Looks like we missed
WP_Post_Comments_List_Table
I totally did.
maybe because of the way it overrides
get_column_info()
. See 25408.17.diff.
Nope, because I wasn't expecting a 2nd class being defined in the same file, and I never even saw it... Totally my bad. Most excellent catch!
cc @helen for quick commit (.17).
#41
@
10 years ago
Just noticed the Network Themes table cell with row-actions misses the has-row-actions column-primary
CSS classes. Maybe would need same treatment given to the Plugins table, see
$extra_class = ' has-row-actions column-primary';
etc.
#42
@
10 years ago
If you click/focus one of the actions links in the Plugins table all other actions links will be hidden, see https://cloudup.com/cFt-2oOJHrt.
#43
@
10 years ago
Themes/plugins list tables, both single and multisite, could probably lose the has-row-actions
part (there's JS that's likely what's causing @ocean90's issue), and I don't know if the primary column for those should really be allowed to be redefined. Thoughts?
#55
@
10 years ago
WP_List_Table::get_primary_column_name()
is the method with the filter.
Extending classes usually implement ::get_default_primary_column_name()
, which the above uses, so their value is filtered.
For extending classes where we do not want the column to be alterable, they should simply implement ::get_primary_column_name()
instead.
25408.18.diff implements the above proposed solution for:
- plugin list table (used for both single and multisite)
- multisite themes list (single doesn't implement listtables per se).
This ticket was mentioned in Slack in #core by helen. View the logs.
10 years ago
#59
in reply to:
↑ 58
@
10 years ago
Replying to obenland:
Custom row attributes like here are no longer working, after [32644].
[32644] also seems to create notices with plugins like Jetpack, that build on top of WP_List_Table
:
Notice: Undefined offset: 3 in /wp-admin/includes/class-wp-list-table.php on line 1120
I'll keep an eye on this ticket to see if we have to make any changes on our end.
#60
@
9 years ago
Just realized the latest comments in the Dashboard screen have row-actions but they're not revealed on focus. Previously, they were targeted with .dashboard-comment-wrap
now removed in r32645. They would need the has-row-actions
class (removing "td" in the jQuery selector) or to be targeted with a specific selector.
#61
in reply to:
↑ 58
@
9 years ago
Replying to obenland:
Custom row attributes like here are no longer working, after [32644].
I think that is the only one that was missed. See 25408-users-list-table.diff
The only other one I recall is in the posts list, where the title column-title
column also needs page-title
assigned.
#62
follow-up:
↓ 63
@
9 years ago
Re @jeherve's remark above, yeah --
The changed line in WP_List_Table::single_row_columns
from
list( $columns, $hidden ) = $this->get_column_info();
to
list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
is causing a notice (not an error) if get_column_info()
doesn't return four indexes in the array.
I suspect it's the initial failout clause in get_column_info()
that is causing it --
if ( isset( $this->_column_headers ) ) return $this->_column_headers;
I'd suggest that for backcompat, if $this->_column_headers
doesn't contain four array items, we add on a fourth with a value of $this->get_primary_column_name()
Unless there's objections, I'll try to get a patch inbound.
#63
in reply to:
↑ 62
@
9 years ago
Replying to georgestephanis and jeherve:
Yes, that. See 25408-list-table-headers-test.diff and https://github.com/Automattic/jetpack/pull/2232
@
9 years ago
An alternative to 25408-list-table-headers-test.diff, if we wanted to future-proof things a bit.
#64
@
9 years ago
I've not tested but it should do what I was thinking.
25408-list-table-headers-test.diff
has problems, as it will fail out and ignore the custom ones, so any plugins that don't update to expect the new stuff will suddenly have their columns borked.
#65
@
9 years ago
George's solution is friendlier to devs who don't keep up with things than mine, go with that.
#67
follow-up:
↓ 68
@
9 years ago
I think r32717 will break column headers for all plugins that explicitly set $_column_headers
, because up until r32644 only three items were expected from get_column_info()
, but now we check for at least four and skip the explicitly set headers entirely if that's not the case.
25408.20.diff makes sure the function passes an array of at least four items, with null as primary. Too many arrays? You bet.
#68
in reply to:
↑ 67
;
follow-up:
↓ 69
@
9 years ago
Replying to kovshenin:
25408.20.diff makes sure the function passes an array of at least four items, with null as primary. Too many arrays? You bet.
array_replace()
is PHP 5.3+ and can't be used.
#73
@
9 years ago
It's failing because of count( $this->_column_headers ) >= 4
.
There are only three header items in this particular list table:
$columns = $this->get_columns(); $hidden = array(); $sortable = $this->get_sortable_columns(); $this->_column_headers = array( $columns, $hidden, $sortable );
If $this->_column_headers = array( $columns, $hidden, $sortable );
is changed to $this->_column_headers = array( $columns, $hidden, $sortable, array() );
, the table shows properly.
Seems the primary column isn't properly getting set.
#74
@
9 years ago
Further note: it still fails even when not manually setting $this->_column_headers
This ticket was mentioned in Slack in #core by afercia. View the logs.
9 years ago
#77
@
9 years ago
Just noticed a very minor, few pixel, difference in the post table rows height compared to 4.2. The "title" cell used to have a post-title
CSS class, was:
$attributes = 'class="post-title page-title column-title"' . $style;
now post-title
is gone and in /wp-admin/css/edit.css
the following selector doesn't apply anymore:
td.post-title strong, td.plugin-title strong { display: block; margin-bottom: .2em; font-size: 14px; }
I'd say either re-apply the rule with an updated selector or remove td.post-title strong
from the CSS.
This ticket was mentioned in Slack in #core by obenland. View the logs.
9 years ago
#79
@
9 years ago
- Type changed from enhancement to task (blessed)
Still tweaking based on fall-out, including stuff discovered in work on #32395, so marking this as a task.
#80
@
9 years ago
For plugins that have extended the list table class and have defined _column_headers
manually, a default primary column has to be "discovered" if none is specified, otherwise the mobile view is empty (for at least most tables)
In 25408-22.diff I've set it so the first non-checkbox column gets set as the primary if none is explicitly set.
#81
@
9 years ago
25408.22.diff is just an alternative, putting it into get_default_primary_column_name()
instead. Too tired to fully engage in testing and committing this right now, would appreciate more eyes.
This ticket was mentioned in Slack in #design by helen. View the logs.
9 years ago
#83
@
9 years ago
I think 25408.22.diff is great as is:
- I think having it in the default (parent's)
get_default_primary_column_name()
is definitely the proper place to. - Going with a
foreach
,continue
, andbreak
pattern is a smart move there.
I fail to see a case where that would fail, at the very least as ungracefully as it does without the change.
#85
follow-up:
↓ 88
@
9 years ago
Sorry @helen, forgot to come back to this. Happy to follow up with more tweaks if any issues are discovered.
#88
in reply to:
↑ 85
@
9 years ago
Replying to mordauk:
Sorry @helen, forgot to come back to this. Happy to follow up with more tweaks if any issues are discovered.
All good, I think we're set. You'll probably want to check on some responsive CSS for your custom list tables, but otherwise, thanks for your help!
#89
@
9 years ago
- Keywords has-patch needs-testing removed
Trying to go through all the comments above - the one outstanding issue I saw was about custom attributes for a table cell, which I think we could split into another ticket and not necessarily have to fix for 4.3. Anything else before calling this fixed?
#93
@
9 years ago
Where is the documentation on how to use this? I installed 4.3 a couple of days ago and now am having trouble big time with a custom post type that does not make use of the post title. How do I mark a column as primary? To make things simple, I'd like to be able to pass this information in the manage_edit-{cpt}_columns filter, but currently there does not seem to be a way to do it like that. Also, all other columns still are displayed, but the data from the columns gets pulled into the first column. It plainly looks weird & I have no reference how to correct it. WITTFM (Where is the f*#king manual)? Take a look at this screenshot:
Which looks perfectly fine on the big screen:
Found the documentation. Please include that link in the description of this patch!
#94
@
9 years ago
I installed WordPress 4.3 couple of days ago too and found that this feature ruined all of my tables. Because the data I display cannot be deduced to single field.
Please, before you introduce any magic feature, consider having a feature flag. Enable it for your own stuff and let others to slowly adapt.
The worst of all that there is no sane way to disable this and now there is some magic CSS that breaks ::before for table rows. It's not like somebody bothered to introduce a class for wp-list-table to turn that on/off.
Putting in 3.7 especially to address point 3 - if not done extremely soon, we should punt it again.