Problem/Motivation
In reviewing #3037668-17: Improve visual coherence of the media library, @lauriii had this to say:
We shouldn't use js- prefixed classes for styling. Since this is just adding RTL styles for a pre-existing selector, we should probably just open a follow-up for this.
This is that follow-up. We should remove any styling from CSS classes that are prefixed with js-.
Proposed resolution
Remove styling rules from any Media Library CSS classes that are prefixed with js-.
Remaining tasks
Patch, review, commit.
User interface changes
There'd better be none, or we've done our job wrong.
API changes
None. These are styling changes in an experimental module.
Data model changes
None.
Release notes snippet
None needed.
Comments
Comment #2
bnjmnmAdded classes, updated css and created an
UpdatePathTestBasetest since there is a config change.Originally tried implementing the config change in hook_update_X, but this caused other update tests to fail -- not entirely sure why admittedly. Instead it's a post_update.
Comment #3
wim leers👍 These retain BC.
👍 These set the right example for contrib & custom code to follow.
👍 This test coverage looks solid!
Comment #4
phenaproximaJust a l'il ol' reroll, so leaving RTBC in place.
Comment #5
lauriiiThe CSS class not prefixed with
js-should use BEM. Maybe something likemedia-library-item__click-to-select-checkbox?Comment #6
bnjmnmChanged to BEM and reduced CSS specificity where possible.
Comment #7
wim leers🤓 Silly PHPStorm reformatted this… But that can be fixed on commit.
Comment #8
lauriiiWas there a particular reason why we could remove
.media-library-item--gridfrom the first selector but not from the second?Sorry that I didn't mention this earlier but we should probably also convert this to use BEM.
Comment #9
bnjmnm#8.1
That was done to achieve greater specificity than the margin set by
.media-library-item--grid .form-item, I moved that rule to appear earlier in the file (adjacent to other.media-library-item--gridstyles), and that was able to remove the extra selector.#8.2 BEM-ified click-to-select-trigger, pretty much just spaced on that one 🙂
Comment #10
wim leersComment #11
lauriiiThis change prevents tests to fully cover all cases. This can be confirmed by removing widget_table from the display items list. Tests pass even after that.
This is all very hypothetical but given that it's upgrade paths, it's better to be safe. This post update could have been run in someone's environment already, and if the
media_library_post_update_checkbox_classesdoesn't have full test coverage, it could be theoretically broken without us noticing it. 😢Comment #12
bnjmnmGood catch on #11! Fortunately, that change is completely unnecessary so it's been removed.
Comment #13
phenaproximaComment #15
bnjmnmEven changing getEditable() to get() in the test did not address the conflicts with media_library_post_update_table_display(), which adds a display that is altered by the new post_update added here. To get around this the pre-update fixture was updated so the view has all media post_updates applied other than the one added in this issue, and post_update.existing_updates made to reflect that.
Also renamed the fixture file to include the issue ID.
Comment #16
phenaproximaI think this looks pretty good and thorough. Nice test coverage! I'd like to see a few small changes, but overall I am +1 for the approach.
Why was this changed? Perhaps this warrants a comment.
This is a post-update function, so we can use the full Drupal APIs (e.g., View::load() and friends).
On second thought, I see that we're doing this to improve the abstraction. So okay, we can keep it this way if we want to.
display_type is a misleading name for this key. It's really the display_id, so let's change it to that.
This is misleading too. 'class_key' doesn't really mean anything to me; this is actually a configuration option for a particular field in a particular display of the view. So maybe something like 'option' instead?
Similarly, I think 'form' is misleading. It's the name of the field in the view, so perhaps something like 'field' would be better.
Although I find it extremely unlikely, this will collide with existing classes like
foo--media-library-item__click-to-select-checkbox. I don't think we necessarily need to change anything here, but a safer thing to do (if we want to be extra paranoid) is to split the classes into an array and use in_array(). But that's extra complexity for, probably, little gain.We should change the misleading keys here too.
This is a bit awkward to read; I think we can use assertContains() and assertNotContains() instead.
Same here.
Comment #17
bnjmnmAddressed all the items in #16 other than #2, which also mentioned it's fine as-is.
For #16.1, that weird change was due to changes in #3062375: Media library item loses focus when hovering over item's title being committed recently. The changes have been moved to where the classes now live.
Comment #18
phenaproximaOnly minor stuff, but otherwise this looks good code-wise.
This needs to be preg_split(), I think, to account for the possibility of multiple spaces between class names. Something like:
$classes_array = preg_split('/\s+/', $classes);.We should pass TRUE as the third argument to in_array().
Might wanna use preg_split() here too.
Comment #19
bnjmnm#18 👌On paying attention to detail even as stable looms near. Changes made.
Comment #20
phenaproximaYeah, I'm cool with it. 😎 RTBC once green on all backends.
Comment #21
bnjmnmSetting back to Needs Review to see if the tests can be improved.
Comment #22
bnjmnmThe concerns mentioned in #11 exposed an execution order that is addressed in this patch.
Comment #23
phenaproximaSupernit: there are two spaces before "executed".
We should bail out if the view has been deleted for some reason:
Nit: This can be
$view->save().Whoops, looks like there's some extra white space right above the foreach.
Should "NAH" be in there?
Comment #24
bnjmnmAddresses feedback from #23
Comment #25
phenaproximaComment #26
alexpottThis is looking good. I think we can be a bit more careful with the update.
This update needs to be a bit more robust and expect that the media library might have changed. So we should expect that the display might exist. And maybe the field has been removed.
Comment #27
phenaproximaAnother thing that might be worth looking into: over in #3081587-58: Multilingual content is shown double in the media library view, @seanB encountered a similar "hey, we can't control the order of updates" thing. His solution was to add the required changes to both updates that are affected by it, effectively removing any need for them to happen in a particular order. Is that a tactic we might be able to take advantage of here, too?
Comment #28
bnjmnmAdded the checks per #26
Re #27, I'd much rather keep concerns separated in their own functions now that I've confirmed it's possible to control the order of post_update calls within the same file.
From docs in module.api.php:
Plus I confirmed it via Xdebug since the docs for earlier versions of 8.x stated that the order was determined by their placement in the file.
Comment #29
phenaproximaSmall nit here -- we don't need to do the two isset checks, since there's implicit checking, AFAIK. So we can do something like:
if (!$display || !isset($display['display_options']['fields'][$field][$option])).Comment #30
bnjmnm#29 is correct! Apparently it looked redundant because it was redundant. Here's the change.
Comment #31
phenaproximaSorry to move the goal post again -- I know how frustrating that is.
I noticed a thing here, though -- we probably shouldn't check if the option is set, since for all we know, a NULL/unset option could be totally legitimate. Views plugins work in mysterious ways. So I would remove [$option] from the isset() check.
Otherwise, this is fine. Please restore RTBC when a new patch is up.
Comment #32
phenaproximaNope! On second thought, it's good as-is. The reason being, as @bnjmnm explained in Slack, that the alternative is this:
Ugh.
So no: it's fine the way it is. Let's go for it.
Comment #33
alexpottCommitted 0ec69d3 and pushed to 8.8.x. Thanks!