Convert Olivero's pager to use single directory components

Created on 7 June 2023, over 1 year ago

Olivero's pager component should be using SDC. Let's migrate it. The current code lives in core/themes/olivero/templates/navigation/pager.html.twig

📌 Task
Status

Active

Version

11.0 🔥

Component
Olivero 

Last updated 12 days ago

Created by

🇺🇸United States mherchel Gainesville, FL, US

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @mherchel
  • Assigned to xenophyle
  • 🇺🇸United States sharkbaitdc

    Initial pass at converting the pager for sdc

  • Issue was unassigned.
  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States mherchel Gainesville, FL, US

    Thanks for all of the work on this! Initial review below:

    1. +++ b/core/themes/olivero/components/pager/pager.components.yml
      @@ -0,0 +1,21 @@
      +$schema: https://git.drupalcode.org/project/sdc/-/raw/1.x/src/metadata.schema.json
      

      Lets get rid of the schema, status, and group keys here.

    2. +++ b/core/themes/olivero/components/pager/pager.components.yml
      @@ -0,0 +1,21 @@
      +slots:
      

      There's no pager block, so this is not needed

    3. +++ b/core/themes/olivero/components/pager/pager.twig
      @@ -0,0 +1,129 @@
      +#}
      

      Lets keep these comments within the pager.html.twig

    4. +++ b/core/themes/olivero/components/pager/pager.twig
      @@ -0,0 +1,129 @@
      +	{% if items %}
      ...
      +								{{ current == key ? 'Current page'|t : 'Page'|t }}
      

      Need to use spaces not tabs.

    5. +++ b/core/themes/olivero/components/pager/pager.twig
      @@ -0,0 +1,129 @@
      +                {% include "@olivero/../images/pager-previous.svg" %}
      

      Lets 1) convert this to a twig function, and 2) bring all of the pager's images into the component and reference them using componentMetadata.

    6. +++ b/core/themes/olivero/components/pager/pager.twig
      @@ -0,0 +1,129 @@
      +							</span>
      

      Need to use spaces not tabs.

    7. +++ b/core/themes/olivero/templates/navigation/pager.html.twig
      @@ -30,90 +30,12 @@
      +{% embed "olivero:pager" with {
      

      Since we're not using any blocks here, let's use an include function.

  • Status changed to Needs review over 1 year ago
  • last update over 1 year ago
    Custom Commands Failed
  • 🇮🇳India gauravvvv Delhi, India

    Addressed feedbacks from #6, attached interdiff for same. please review

  • Status changed to Needs work over 1 year ago
  • The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • 🇮🇳India _utsavsharma

    Tried to fix failures in #8.

  • last update over 1 year ago
    Build Successful
  • First commit to issue fork.
  • Merge request !8768Issue #3365391: Add Pager SDC. → (Open) created by Unnamed author
  • Pipeline finished with Failed
    7 months ago
    Total: 583s
    #224559
  • Status changed to Needs review 7 months ago
  • Status changed to RTBC 7 months ago
  • 🇮🇳India Vishal Choudhary Dharmshala

    In this scenario, I have created two nodes and a view to show a node using a pager.
    After saving the view go to the page URL and show the Output like that
    Screenshot Attached:

    To See this Output May be Moved to RTBC
    Thanks.

  • Status changed to Needs work 7 months ago
  • 🇬🇧United Kingdom catch

    One question on the MR.

  • Pipeline finished with Failed
    7 months ago
    Total: 540s
    #227451
  • 🇬🇧United Kingdom catch

    Looks like the library definition still needs updating too.

  • Pipeline finished with Failed
    7 months ago
    Total: 664s
    #228513
  • Status changed to Needs review 7 months ago
  • Status changed to Needs work 7 months ago
  • 🇺🇸United States smustgrave

    Appears to have multiple test failures.

  • Pipeline finished with Failed
    7 months ago
    Total: 456s
    #231960
  • 🇪🇸Spain IgnacioFarre

    First-time contributor - Refactoring the pager component
    Hi, this is my first time contributing to Drupal. 😊

    This patch includes updates to the pager.component.yml and pager.twig files
    If there’s anything I’ve done incorrectly or any feedback you have, please let me know. Thank you!

  • Pipeline finished with Failed
    29 days ago
    Total: 532s
    #406417
  • Merge request !110113502353: feed icon component created → (Closed) created by Unnamed author
  • 🇪🇸Spain IgnacioFarre

    ignaciofarre changed the visibility of the branch drupal-3502353-3502353-2 to hidden.

  • 🇪🇸Spain IgnacioFarre

    ignaciofarre changed the visibility of the branch 3502353-2 to hidden.

  • Pipeline finished with Failed
    28 days ago
    Total: 517s
    #406542
  • Pipeline finished with Failed
    28 days ago
    Total: 105s
    #407119
  • Pipeline finished with Failed
    28 days ago
    Total: 420s
    #407124
  • Pipeline finished with Failed
    28 days ago
    Total: 446s
    #407138
  • 🇺🇸United States smustgrave

    Hello and thanks for the first time contribution.

    So with all issues they should use the standard issue template, the template that's there when you create a new ticket. Even if sections aren't relevant like API change leave it and put a NA under it.

    Will probably need SDC maintainer eyes, will ping them.

  • 🇫🇷France pdureau Paris

    A few feedbacks from a first quick look:

    Undefined objects

    This is not enough to be understood by developers using your component and leveraged by display builders ( UI Patterns 2 , the upcoming Experience Builder...):

            previous:
              type: object
              title: Previous page
              description: Represents the previous page relative to the current page, typically with a link to the preceding page in the pager.
    

    You need to tell what is inside the object, which properties.

    Buy the way, don't feel obligated to mimic the current Twig logic and model of core/themes/olivero/templates/navigation/pager.html.twig , this is also the occasion of proposing a cleaner model and do the mapping when you include the component.

    Alien classes

    Are you sure layout--content-medium belongs to the component template ?

    attributes.addClass(['pager', 'layout--content-medium'])
    

    it looks foreign for me.

    Maybe you can inject it from the presenter template instead:

    {% include 'olivero:pager' with {
      attributes.addClass('layout--content-medium'),
    

    Use include function instead of include tag

    According to Twig documentation, it is recommended to use the include function instead as it provides the same features with a bit more flexibility: https://twig.symfony.com/doc/3.x/tags/include.html

    Proper use of icons

    It is a bit weird to use componentMetadata as a workaround to get icon path but I understand why you did that:

     {{ include (componentMetadata.path ~ '/images/pager-previous.svg') }}
    

    However, there is a new Icon API in Drupal Core since Drupal 11.1: Add an icon management API Active

    So, you can add an icon pack in olivero.icons.yml (naive, non tested, example):

    olivero:
      label: "Olivero icons"
      extractor: svg
      config:
        sources:
          - path/to/your/icons/
      settings: {}
      template: >-
        <svg {{ attributes }}>{{ content }}</svg>
    

    Adn then call your icon from your template:

     {{ icon ('olivero', 'pager-previous') }}
    

    It is a new API. I would be happy to help if necessary.

  • First commit to issue fork.
  • 🇬🇧United Kingdom oily Greater London

    Edited MR. Attempt to make code more comprehensible.

  • Pipeline finished with Failed
    27 days ago
    Total: 365s
    #407678
  • Pipeline finished with Failed
    23 days ago
    Total: 122s
    #411359
  • Pipeline finished with Failed
    23 days ago
    Total: 122s
    #411372
  • 🇪🇸Spain IgnacioFarre

    Hi Pierre,
    Thank you for your review and comments—I really appreciate the feedback.
    I’ve made some updates based on the suggestions:
    1. I added a new component (`pager_item`) and structured the render arrays in the preprocess function. This seemed necessary because of the complexity, but I’m not entirely sure if this was the best approach. Please let me know if there’s room for improvement.
    2. I also added the view mini pager template since it was previously unstyled.

    Unfortunately, I wasn’t able to make the icons work. Any guidance or feedback on this would be greatly appreciated.

    Lastly, thank you, Andrew, for reviewing the text as well. English isn’t my first language, and I’d really appreciate another review of the text if possible.

    Please let me know if I can improve or update the code further—I am eager to learn, so don’t hesitate to share any suggestions.
    Thanks again!

  • 🇫🇷France pdureau Paris

    Hi Ignacio,

    Undefined objects

    I added a new component (`pager_item`) and structured the render arrays in the preprocess function. This seemed necessary because of the complexity, but I’m not entirely sure if this was the best approach. Please let me know if there’s room for improvement.

    Creating a pager_item component is not a bad idea. There is plenty of situations when we want a "sub component" repeated in a parent component' slot:

    • slides in a slider component
    • items in an accordion component
    • tab in a tabs component

    However, in this case, I don't believe it is the best choice:

    there is not slot in pager_item so the repeated data structure can be expressed with JSON schema
    this data structure already exists in Drupal: pager links. it just need to be defined properly instead of a simple type: object

    Also, if you decide to keep pager_item, the BEM HTML class name must not be an element of pager:

    {% set classes = [
      'pager__item',
      'pager__item--' ~ itemType
    ] %}
    

    but its own block:

    {% set classes = [
      'pager-item',
      'pager-item--' ~ itemType
    ] %}
    

    See: https://getbem.com/naming/

    Proper use of icons

    Unfortunately, I wasn’t able to make the icons work. Any guidance or feedback on this would be greatly appreciated.

    This new API (available since Drupal 11.1) is easy to use once the icon pack is defined.

    First, you need to have a clearer organisation of your icons. You actually have:

    I have no opinion about where to keep those 2 icons, but it seems there is some duplications to fix, so I am proposing to move components/paginator/pager_item/images/*.svg to images/icons/*.svg , replacing the existing files.

    Then you can create a olivero.icons.yml file at the root of the theme with:

    olivero:
      label: "Olivero"
      extractor: svg
      config:
        sources:
          - images/icons/*.svg
      settings: {}
      template: >-
        <svg {{ attributes }}>{{ content }}</svg>
    

    And try to print {{ icon ('olivero', 'pager-previous') }} in a template. Is it working?

    If yes, it is a good start :) If no, let's check this together.

    Linting & and checking

    There is no official Twig linter for Drupal Core yet, but you can run the Twig files of the components added by you (and only those ones) with 📌 Adopt friendsoftwig/twigcs for Twig coding standards Needs review

    Also, https://www.drupal.org/project/sdc_devel can be useful to check your component (definition & template) :

    • there is a report page: /admin/reports/ui-components
    • and a drush command: drush sdv olivero
Production build 0.71.5 2024