We need to refactor our comments JavaScript

  • Wrap it in a Drupal behavior
  • Use data attributes as selectors where possible

https://git.drupalcode.org/project/drupal/-/blob/9.2.x/core/themes/olive...

Comments

mherchel created an issue. See original summary.

mherchel’s picture

Status: Active » Needs review
StatusFileSize
new7.09 KB

Note that I wasn't able to modify a template to insert a data attribute for the .indented selector. This markup is generated within the comment module at https://git.drupalcode.org/project/drupal/-/blob/9.2.x/core/modules/comm...

This should be good to go!

gauravvvv’s picture

StatusFileSize
new5.54 KB
new11.27 KB

I have provided the patch please review.

Status: Needs review » Needs work

The last submitted patch, 3: 3208372-3.patch, failed testing. View results

gauravvvv’s picture

Status: Needs work » Needs review
mherchel’s picture

StatusFileSize
new7.05 KB
new1.31 KB

The interdiff in #4 didn't match the patch. Either way, we don't want to introduce new node dependencies.

The reason #2 failed is because babel (on the D.O servers) didn't understand the optional chaining syntax. I'm removing that in this patch.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mherchel’s picture

StatusFileSize
new7.22 KB

Attaching a new patch that uses the [data-drupal-selector] pattern.

Tugboat preview: https://3208372-refactor-comments-js-py9veecd6lb02zgxukvwkzknubwmvwtv.tu...

andy-blum’s picture

--- a/core/themes/olivero/templates/field/field--comment.html.twig
+++ b/core/themes/olivero/templates/field/field--comment.html.twig
@@ -29,7 +29,7 @@

-<section{{ attributes.addClass('comments') }}>
+<section{{ attributes.setAttribute('data-drupal-selector', 'comments').addClass('comments') }}>

I don't think we're using the class name 'comments' anywhere. Do we still want/need to attach that class since it's not doing anything?

Besides that, I think we're good

mherchel’s picture

Yeah, I say we should still include it. Eventually the starterkit theme generator will be able to copy this theme, and in that case the class might be useful for people to style against.

thejimbirch’s picture

If that is the case, then RTBC.

thejimbirch’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 8: 3208372-8.patch, failed testing. View results

mherchel’s picture

Status: Needs work » Reviewed & tested by the community

Unrelated failure.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 8: 3208372-8.patch, failed testing. View results

gauravvvv’s picture

Status: Needs work » Reviewed & tested by the community

Unrelated failure.

lauriii’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/themes/olivero/js/comments.es6.js
@@ -1,39 +1,49 @@
+  function init(comments) {
...
+  Drupal.behaviors.comments = {

These should be documented according to the coding standards https://www.drupal.org/docs/develop/standards/javascript/javascript-api-...

paulocs’s picture

Working on it.

paulocs’s picture

Status: Needs work » Needs review
StatusFileSize
new1.73 KB
new7.84 KB

Attaching patch and interdiff.

paulocs’s picture

StatusFileSize
new7.87 KB

Sorry for the patches. I'm starting now contributing to front-end. I'm having problems with prettier.

paulocs’s picture

StatusFileSize
new1.18 KB
new7.53 KB

I think now it is right...

marcusvsouza’s picture

Status: Needs review » Reviewed & tested by the community

RTBC!

mherchel’s picture

+1 RTBC

  • lauriii committed 630cd36 on 9.3.x
    Issue #3208372 by paulocs, mherchel, Gauravmahlawat: Olivero: Refactor...

  • lauriii committed 60d7c69 on 9.2.x
    Issue #3208372 by paulocs, mherchel, Gauravmahlawat: Olivero: Refactor...
lauriii’s picture

Version: 9.3.x-dev » 9.2.x-dev
Status: Reviewed & tested by the community » Fixed

Noticed the use of indented class but since it's in a piece of markup that is hard to override, I decided to open issue in the comment module issue queue instead: #3221204: Move markup to templates from CommentViewBuilder.

Committed 630cd36 and pushed to 9.3.x. Also cherry-picked to 9.2.x since Olivero is experimental. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.